X-Git-Url: https://git.brokenzipper.com/gitweb?a=blobdiff_plain;f=src%2Fcreate.c;h=b712f93b716aa220eea16ed6b52bb4115ef424b7;hb=0008f6123738f466bc95b8b6bd3e82a7bc91876d;hp=6f9f7e8ca291b7149251b68ef446857279cfe8e9;hpb=cb3ec64970434eeb345a11032cb2babc505a5689;p=chaz%2Ftar diff --git a/src/create.c b/src/create.c index 6f9f7e8..b712f93 100644 --- a/src/create.c +++ b/src/create.c @@ -21,11 +21,6 @@ #include "system.h" -#if !MSDOS -# include -# include -#endif - #if HAVE_UTIME_H # include #else @@ -41,11 +36,6 @@ struct utimbuf #include "common.h" #include -#ifndef MSDOS -extern dev_t ar_dev; -extern ino_t ar_ino; -#endif - struct link { dev_t dev; @@ -402,6 +392,16 @@ write_long (const char *p, char type) set_next_block_after (header + (size - 1) / BLOCKSIZE); } +/* Write a long link name, depending on the current archive format */ +static void +write_long_link (struct tar_stat_info *st) +{ + if (archive_format == POSIX_FORMAT) + xheader_store ("linkpath", st); + else + write_long (st->link_name, GNUTYPE_LONGNAME); +} + /* NOTE: Cross recursion between start_header and write_extended */ static union block * @@ -410,7 +410,6 @@ write_extended (union block *old_header, char type) union block *header, hp; struct tar_stat_info foo; size_t size; - size_t bufsize; char *p; if (extended_header.buffer || extended_header.stk == NULL) @@ -469,10 +468,16 @@ start_header (const char *name, struct tar_stat_info *st) union block *header; name = safer_name_suffix (name, 0); - + assign_string (&st->file_name, name); + if (sizeof header->header.name <= strlen (name)) - write_long (name, GNUTYPE_LONGNAME); - + { + if (archive_format == POSIX_FORMAT) + xheader_store ("path", st); + else + write_long (name, GNUTYPE_LONGNAME); + } + header = find_next_block (); memset (header->buffer, 0, sizeof (union block)); @@ -629,6 +634,22 @@ finish_header (union block *header, off_t block_ordinal) int sum; char *p; + /* Note: It is important to do this before the call to write_extended(), + so that the actual ustar header is printed */ + if (verbose_option + && header->header.typeflag != GNUTYPE_LONGLINK + && header->header.typeflag != GNUTYPE_LONGNAME + && header->header.typeflag != XHDTYPE + && header->header.typeflag != XGLTYPE) + { + /* These globals are parameters to print_header, sigh. */ + + current_header = header; + /* current_stat_info is already set up. */ + current_format = archive_format; + print_header (block_ordinal); + } + header = write_extended (header, XHDTYPE); memcpy (header->header.chksum, CHKBLANKS, sizeof header->header.chksum); @@ -651,18 +672,6 @@ finish_header (union block *header, off_t block_ordinal) uintmax_to_chars ((uintmax_t) sum, header->header.chksum, 7); - if (verbose_option - && header->header.typeflag != GNUTYPE_LONGLINK - && header->header.typeflag != GNUTYPE_LONGNAME) - { - /* These globals are parameters to print_header, sigh. */ - - current_header = header; - /* current_stat_info is already set up. */ - current_format = archive_format; - print_header (block_ordinal); - } - set_next_block_after (header); } @@ -1039,16 +1048,13 @@ dump_file (char *p, int top_level, dev_t parent_device) return; } -#if !MSDOS /* See if we are trying to dump the archive. */ - - if (ar_dev && current_stat_info.stat.st_dev == ar_dev && current_stat_info.stat.st_ino == ar_ino) + if (sys_file_is_archive (¤t_stat_info)) { WARN ((0, 0, _("%s: file is the archive; not dumped"), quotearg_colon (p))); return; } -#endif if (S_ISDIR (current_stat_info.stat.st_mode)) { @@ -1236,9 +1242,9 @@ dump_file (char *p, int top_level, dev_t parent_device) dup->nlink--; block_ordinal = current_block_ordinal (); - if (NAME_FIELD_SIZE <= strlen (link_name)) - write_long (link_name, GNUTYPE_LONGLINK); assign_string (¤t_stat_info.link_name, link_name); + if (NAME_FIELD_SIZE <= strlen (link_name)) + write_long_link (¤t_stat_info); current_stat_info.stat.st_size = 0; header = start_header (p, ¤t_stat_info); @@ -1478,7 +1484,9 @@ dump_file (char *p, int top_level, dev_t parent_device) char buf[UINTMAX_STRSIZE_BOUND]; memset (start->buffer + count, 0, bufsize - count); WARN ((0, 0, - _("%s: File shrank by %s bytes; padding with zeros"), + ngettext ("%s: File shrank by %s byte; padding with zeros", + "%s: File shrank by %s bytes; padding with zeros", + sizeleft), quotearg_colon (p), STRINGIFY_BIGINT (sizeleft, buf))); if (! ignore_failed_read_option) @@ -1563,9 +1571,9 @@ dump_file (char *p, int top_level, dev_t parent_device) return; } buffer[size] = '\0'; - if (size >= NAME_FIELD_SIZE) - write_long (buffer, GNUTYPE_LONGLINK); assign_string (¤t_stat_info.link_name, buffer); + if (size >= NAME_FIELD_SIZE) + write_long_link (¤t_stat_info); block_ordinal = current_block_ordinal (); current_stat_info.stat.st_size = 0; /* force 0 size on symlink */