ear;ecere/EARArchive: Fix for reporting errors when adding to archive; Fix for re...
authorJerome St-Louis <jerome@ecere.com>
Tue, 13 Mar 2012 07:36:03 +0000 (03:36 -0400)
committerJerome St-Louis <jerome@ecere.com>
Tue, 13 Mar 2012 07:39:04 +0000 (03:39 -0400)
ear/cmd/ear.ec
ear/cmd/locale/ear.pot
ecere/src/sys/Archive.ec
ecere/src/sys/EARArchive.ec

index 05ce239..802e996 100644 (file)
@@ -639,7 +639,7 @@ class EARApp : GuiApplication
             }
             case ARCHIVE_ACTION_ADD:
             {
-               Archive archive = ArchiveOpen(argv[2], { true });
+               Archive archive = ArchiveOpen(argv[2], { true, waitLock = true });
                if(archive)
                {
                   if(selfExtract)
@@ -675,14 +675,29 @@ class EARApp : GuiApplication
                            if(dir)
                            {
                               if(!AddToArchive(archive, dir, file, argv[c], addMode, compression))
+                              {
+                                 exitCode = 2;
+                                 Logf($"Failed to add %s to archive!\n", argv[c]);
+                                 delete dir;
                                  break;
+                              }
                               delete dir;
                            }
+                           else
+                           {
+                              exitCode = 3;
+                              Logf($"Failed to open the internal directory of archive %s!\n", argv[2]);
+                           }
                         }
                      }
                   }
                   delete archive;
                }
+               else
+               {
+                  Logf($"Failed to open archive %s for writing!\n", argv[2]);
+                  exitCode = 4;
+               }
                break;
             }
             case ARCHIVE_ACTION_CLEAR:
index 9db040a..21d55c3 100644 (file)
@@ -90,7 +90,7 @@ msgstr "A folder with the same name already exists (%s).\n"
 msgid "Adding %s..."
 msgstr "Adding %s..."
 
-#: .\ear.ec:696
+#: .\ear.ec:711
 msgid "Archive cleared: %s.\n"
 msgstr "Archive cleared: %s.\n"
 
@@ -106,11 +106,11 @@ msgstr "Archive file not found: %s\n"
 msgid "Can't move directory %s inside itself.\n"
 msgstr "Can't move directory %s inside itself.\n"
 
-#: .\ear.ec:723
+#: .\ear.ec:738
 msgid "Deleting file %s in directory %s.\n"
 msgstr "Deleting file %s in directory %s.\n"
 
-#: .\ear.ec:812
+#: .\ear.ec:827
 msgid "Drive letters and %s only valid at root.\n"
 msgstr "Drive letters and %s only valid at root.\n"
 
@@ -122,6 +122,18 @@ msgstr "Extracting %s...\n"
 msgid "Extraction Commands:\n"
 msgstr "Extraction Commands:\n"
 
+#: .\ear.ec:680
+msgid "Failed to add %s to archive!\n"
+msgstr "Failed to add %s to archive!\n"
+
+#: .\ear.ec:698
+msgid "Failed to open archive %s for writing!\n"
+msgstr "Failed to open archive %s for writing!\n"
+
+#: .\ear.ec:689
+msgid "Failed to open the internal directory of archive %s!\n"
+msgstr "Failed to open the internal directory of archive %s!\n"
+
 #: .\ear.ec:585
 msgid "File Not Found: %s\n"
 msgstr "File Not Found: %s\n"
@@ -154,7 +166,7 @@ msgstr "Moving file %s in directory %s to %s.\n"
 msgid "Moving files in root to %s.\n"
 msgstr "Moving files in root to %s.\n"
 
-#: .\ear.ec:815
+#: .\ear.ec:830
 msgid "New name contains directory structure.\n"
 msgstr "New name contains directory structure.\n"
 
@@ -166,7 +178,7 @@ msgstr "Options:\n"
 msgid "Out of disk space.\nError: Ran out of disk space while archiving%s%s.\n"
 msgstr "Out of disk space.\nError: Ran out of disk space while archiving%s%s.\n"
 
-#: .\ear.ec:779
+#: .\ear.ec:794
 msgid "Renaming %s in directory %s to %s.\n"
 msgstr "Renaming %s in directory %s to %s.\n"
 
index 4e9a311..a8afc6e 100644 (file)
@@ -11,6 +11,7 @@ public:
    bool writeAccess:1;
    bool buffered:1;
    bool exclusive:1;
+   bool waitLock:1;
 };
 
 public class Archive
index 4a125dd..5d85c63 100644 (file)
@@ -163,7 +163,11 @@ class EARArchive : Archive
          Defrag(rootDir);
          archiveStart += Update();
       }
-
+      if(f && writeAccess)
+      {
+         f.Flush();
+         f.Unlock(0, 0, true);
+      }
       delete f;
 
       /*if(rootDir && writeAccess)
@@ -1549,61 +1553,68 @@ class EARFileSystem : FileSystem
       EARArchive archive { writeAccess = flags.writeAccess };
       if(archive)
       {
-         // Check for existing Archive
-         if((archive.f = fileName ? (flags.buffered ? FileOpenBuffered : FileOpen)(fileName, flags.writeAccess ? readWrite : read) : TempFile { openMode = readWrite } ))
+         int try = flags.waitLock ? 10 : 0;
+         for(; try >= 0; try--)
          {
-            EARHeader header;
-            bool opened = false;
-            uint archiveSize = 0;
-            archive.f.Seek(-(int)sizeof(uint), end);
-            archive.f.Read(&archiveSize, sizeof(uint), 1);
-            archive.f.Seek(-(int)archiveSize, end);
-
-            archive.archiveStart = archive.f.Tell();
-            if(archive.f.Read(&header, sizeof(EARHeader), 1) == 1 &&
-               !strncmp(header.recognition, earRecognition, sizeof(earRecognition)))
-               opened = true;
-
-            if(!opened)
+            // Check for existing Archive
+            if((archive.f = fileName ? (flags.buffered ? FileOpenBuffered : FileOpen)(fileName, flags.writeAccess ? readWrite : read) : TempFile { openMode = readWrite } ))
             {
-               archive.f.Seek(0, start);
+               EARHeader header;
+               bool opened = false;
+               uint archiveSize = 0;
+               archive.f.Seek(-(int)sizeof(uint), end);
+               archive.f.Read(&archiveSize, sizeof(uint), 1);
+               archive.f.Seek(-(int)archiveSize, end);
+
                archive.archiveStart = archive.f.Tell();
-               archiveSize = archive.f.GetSize();
                if(archive.f.Read(&header, sizeof(EARHeader), 1) == 1 &&
                   !strncmp(header.recognition, earRecognition, sizeof(earRecognition)))
                   opened = true;
-            }
 
-            if(opened)
-            {
-               // At this point we recognized the file as a valid eAR archive
-               archive.rootDir = archive.archiveStart + sizeof(EARHeader);
-               archive.totalSize = header.totalSize;
-
-               archive.f.Seek(archive.rootDir, start);
-               if(flags.buffered)
-               {
-                  archive.freeBlocks.Add(FreeBlock { start = archive.rootDir + 2 * sizeof(uint), end = MAXDWORD });
-                  archive.SubtractUsedBlocks();
-               }
-               else
+               if(!opened)
                {
-                  archive.freeBlocks.Add(FreeBlock { start = archive.archiveStart + (archiveSize - sizeof(uint)), end = MAXDWORD });
+                  archive.f.Seek(0, start);
+                  archive.archiveStart = archive.f.Tell();
+                  archiveSize = archive.f.GetSize();
+                  if(archive.f.Read(&header, sizeof(EARHeader), 1) == 1 &&
+                     !strncmp(header.recognition, earRecognition, sizeof(earRecognition)))
+                     opened = true;
                }
 
-               /*
-               if(!flags.writeAccess)
-               {
-                  delete archive.f;
-                  archive.f = FileOpen(fileName, readWrite);
-               }
-               */
-               if(archive.f)
+               if(opened)
                {
-                  incref archive.f;
-                  result = archive;
+                  // At this point we recognized the file as a valid eAR archive
+                  archive.rootDir = archive.archiveStart + sizeof(EARHeader);
+                  archive.totalSize = header.totalSize;
+
+                  archive.f.Seek(archive.rootDir, start);
+                  if(flags.buffered)
+                  {
+                     archive.freeBlocks.Add(FreeBlock { start = archive.rootDir + 2 * sizeof(uint), end = MAXDWORD });
+                     archive.SubtractUsedBlocks();
+                  }
+                  else
+                  {
+                     archive.freeBlocks.Add(FreeBlock { start = archive.archiveStart + (archiveSize - sizeof(uint)), end = MAXDWORD });
+                  }
+
+                  /*
+                  if(!flags.writeAccess)
+                  {
+                     delete archive.f;
+                     archive.f = FileOpen(fileName, readWrite);
+                  }
+                  */
+                  if(archive.f)
+                  {
+                     incref archive.f;
+                     result = archive;
+                  }
                }
+               break;
             }
+            else if(try > 0)
+               Sleep(0.01);
          }
 
          // This piece of code will create a new archive as a new file or at the footer
@@ -1643,7 +1654,7 @@ class EARFileSystem : FileSystem
                result = archive;
             }
          }
-         if(archive.f && flags.writeAccess && flags.exclusive && !archive.f.Lock(flags.exclusive ? exclusive : shared, 0, 0, false))
+         if(archive.f && flags.writeAccess && flags.exclusive && !archive.f.Lock(flags.exclusive ? exclusive : shared, 0, 0, flags.waitLock))
             result = null;
          if(!result)
          {