X-Git-Url: https://git.dogcows.com/gitweb?a=blobdiff_plain;f=src%2Fcreate.c;h=a964bc2824a416a118e69fa0c31fa334904a76c6;hb=7cb84c25ee51f443c69443e217efe194d12678ea;hp=e33122a4ce07ee34a199255a55a4d5a26e74bcb7;hpb=51aee274e892923a3f8fdb774e4f6b90bce47437;p=chaz%2Ftar diff --git a/src/create.c b/src/create.c index e33122a..a964bc2 100644 --- a/src/create.c +++ b/src/create.c @@ -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; @@ -516,9 +515,8 @@ write_eot (void) /* Write a "private" header */ union block * -start_private_header (const char *name, size_t size) +start_private_header (const char *name, size_t size, time_t t) { - time_t t; union block *header = find_next_block (); memset (header->buffer, 0, sizeof (union block)); @@ -526,7 +524,6 @@ start_private_header (const char *name, size_t size) tar_name_copy_str (header->header.name, name, NAME_FIELD_SIZE); OFF_TO_CHARS (size, header->header.size); - time (&t); TIME_TO_CHARS (t, header->header.mtime); MODE_TO_CHARS (S_IFREG|S_IRUSR|S_IWUSR|S_IRGRP|S_IROTH, header->header.mode); UID_TO_CHARS (getuid (), header->header.uid); @@ -564,13 +561,13 @@ write_gnu_long_link (struct tar_stat_info *st, const char *p, char type) union block *header; char *tmpname; - header = start_private_header ("././@LongLink", size); - FILL(header->header.mtime, '0'); - FILL(header->header.mode, '0'); - FILL(header->header.uid, '0'); - FILL(header->header.gid, '0'); - FILL(header->header.devmajor, 0); - FILL(header->header.devminor, 0); + header = start_private_header ("././@LongLink", size, time (NULL)); + FILL (header->header.mtime, '0'); + FILL (header->header.mode, '0'); + FILL (header->header.uid, '0'); + FILL (header->header.gid, '0'); + FILL (header->header.devmajor, 0); + FILL (header->header.devminor, 0); uid_to_uname (0, &tmpname); UNAME_TO_CHARS (tmpname, header->header.uname); free (tmpname); @@ -713,7 +710,8 @@ write_extended (bool global, struct tar_stat_info *st, union block *old_header) union block *header, hp; char *p; int type; - + time_t t; + if (st->xhdr.buffer || st->xhdr.stk == NULL) return old_header; @@ -723,13 +721,15 @@ write_extended (bool global, struct tar_stat_info *st, union block *old_header) { type = XGLTYPE; p = xheader_ghdr_name (); + time (&t); } else { type = XHDTYPE; p = xheader_xhdr_name (st); + t = st->stat.st_mtime; } - xheader_write (type, p, &st->xhdr); + xheader_write (type, p, t, &st->xhdr); free (p); header = find_next_block (); memcpy (header, &hp.buffer, sizeof (hp.buffer)); @@ -1081,7 +1081,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 +1334,7 @@ create_archive (void) write_eot (); close_archive (); - + finish_deferred_unlinks (); if (listed_incremental_option) write_directory_file (); } @@ -1365,7 +1365,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); } @@ -1414,8 +1414,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 +1667,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 +1681,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 +1717,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 +1770,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