]> Dogcows Code - chaz/tar/blobdiff - src/create.c
Fix bugs in handling the --remove-files option.
[chaz/tar] / src / create.c
index e33122a4ce07ee34a199255a55a4d5a26e74bcb7..d4b9ae7e4738bb0909d7c7905f24a6f4325c1443 100644 (file)
@@ -402,8 +402,7 @@ mode_to_chars (mode_t v, char *p, size_t s)
       && S_IROTH == TOREAD && S_IWOTH == TOWRITE && S_IXOTH == TOEXEC
       && archive_format != POSIX_FORMAT
       && archive_format != USTAR_FORMAT
-      && archive_format != GNU_FORMAT
-      && archive_format != OLDGNU_FORMAT)
+      && archive_format != GNU_FORMAT)
     {
       negative = v < 0;
       u = v;
@@ -1081,7 +1080,7 @@ dump_regular_file (int fd, struct tar_stat_info *st)
                    quotearg_colon (st->orig_file_name),
                    STRINGIFY_BIGINT (size_left, buf)));
          if (! ignore_failed_read_option) 
-           exit_status = TAREXIT_DIFFERS;
+           set_exit_status (TAREXIT_DIFFERS);
          pad_archive (size_left - (bufsize - count));
          return dump_status_short;
        }
@@ -1334,7 +1333,7 @@ create_archive (void)
 
   write_eot ();
   close_archive ();
-
+  finish_deferred_unlinks ();
   if (listed_incremental_option)
     write_directory_file ();
 }
@@ -1365,7 +1364,7 @@ unknown_file_error (char const *p)
           (0, 0, _("%s: Unknown file type; file ignored"),
            quotearg_colon (p)));
   if (!ignore_failed_read_option)
-    exit_status = TAREXIT_FAILURE;
+    set_exit_status (TAREXIT_FAILURE);
 }
 
 \f
@@ -1414,8 +1413,8 @@ dump_hard_link (struct tar_stat_info *st)
          blk->header.typeflag = LNKTYPE;
          finish_header (st, blk, block_ordinal);
 
-         if (remove_files_option && unlink (st->orig_file_name) != 0)
-           unlink_error (st->orig_file_name);
+         if (remove_files_option)
+           queue_deferred_unlink (st->orig_file_name, false);
 
          return true;
        }
@@ -1667,8 +1666,7 @@ dump_file0 (struct tar_stat_info *st, const char *p,
              WARNOPT (WARN_FILE_CHANGED,
                       (0, 0, _("%s: file changed as we read it"),
                        quotearg_colon (p)));
-             if (exit_status == TAREXIT_SUCCESS)
-               exit_status = TAREXIT_DIFFERS;
+             set_exit_status (TAREXIT_DIFFERS);
            }
          else if (atime_preserve_option == replace_atime_preserve
                   && set_file_atime (fd, p, restore_times) != 0)
@@ -1682,18 +1680,7 @@ dump_file0 (struct tar_stat_info *st, const char *p,
        }
 
       if (ok && remove_files_option)
-       {
-         if (is_dir)
-           {
-             if (rmdir (p) != 0 && errno != ENOTEMPTY)
-               rmdir_error (p);
-           }
-         else
-           {
-             if (unlink (p) != 0)
-               unlink_error (p);
-           }
-       }
+       queue_deferred_unlink (p, is_dir);
 
       return;
     }
@@ -1729,10 +1716,8 @@ dump_file0 (struct tar_stat_info *st, const char *p,
       /* nothing more to do to it */
 
       if (remove_files_option)
-       {
-         if (unlink (p) == -1)
-           unlink_error (p);
-       }
+       queue_deferred_unlink (p, false);
+
       file_count_links (st);
       return;
     }
@@ -1784,10 +1769,7 @@ dump_file0 (struct tar_stat_info *st, const char *p,
 
   finish_header (st, header, block_ordinal);
   if (remove_files_option)
-    {
-      if (unlink (p) == -1)
-       unlink_error (p);
-    }
+    queue_deferred_unlink (p, false);
 }
 
 void
This page took 0.02353 seconds and 4 git commands to generate.