X-Git-Url: https://git.brokenzipper.com/gitweb?a=blobdiff_plain;f=src%2Fcreate.c;h=4edf4882155cab8894530eacf4d2bbc580985154;hb=e5e43aa7a4f43365d1a9d6d09de5b4cbe19d4e89;hp=4cd5980856b580620f0d039d84f6deadb94ee596;hpb=06742ec624c4be64ea1033f5470b668162c022cb;p=chaz%2Ftar diff --git a/src/create.c b/src/create.c index 4cd5980..4edf488 100644 --- a/src/create.c +++ b/src/create.c @@ -1,7 +1,7 @@ /* Create a tar archive. Copyright (C) 1985, 1992, 1993, 1994, 1996, 1997, 1999, 2000, 2001, - 2003, 2004 Free Software Foundation, Inc. + 2003, 2004, 2005 Free Software Foundation, Inc. Written by John Gilmore, on 1985-08-25. @@ -17,7 +17,7 @@ You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., - 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include @@ -370,6 +370,16 @@ tar_copy_str (char *dst, const char *src, size_t len) strncpy (dst, src, len); } +/* Same as tar_copy_str, but always terminate with NUL if using + is OLDGNU format */ +static void +tar_name_copy_str (char *dst, const char *src, size_t len) +{ + tar_copy_str (dst, src, len); + if (archive_format == OLDGNU_FORMAT) + dst[len-1] = 0; +} + /* Write a "private" header */ union block * start_private_header (const char *name, size_t size) @@ -379,7 +389,7 @@ start_private_header (const char *name, size_t size) memset (header->buffer, 0, sizeof (union block)); - tar_copy_str (header->header.name, name, NAME_FIELD_SIZE); + tar_name_copy_str (header->header.name, name, NAME_FIELD_SIZE); OFF_TO_CHARS (size, header->header.size); time (&t); @@ -402,7 +412,7 @@ write_short_name (struct tar_stat_info *st) { union block *header = find_next_block (); memset (header->buffer, 0, sizeof (union block)); - tar_copy_str (header->header.name, st->file_name, NAME_FIELD_SIZE); + tar_name_copy_str (header->header.name, st->file_name, NAME_FIELD_SIZE); return header; } @@ -410,7 +420,7 @@ write_short_name (struct tar_stat_info *st) memset(field, byte, sizeof(field)-1); \ (field)[sizeof(field)-1] = 0; \ } while (0) - + /* Write a GNUTYPE_LONGLINK or GNUTYPE_LONGNAME block. */ static void write_gnu_long_link (struct tar_stat_info *st, const char *p, char type) @@ -419,7 +429,7 @@ write_gnu_long_link (struct tar_stat_info *st, const char *p, char type) size_t bufsize; union block *header; char *tmpname; - + header = start_private_header ("././@LongLink", size); FILL(header->header.mtime, '0'); FILL(header->header.mode, '0'); @@ -433,7 +443,7 @@ write_gnu_long_link (struct tar_stat_info *st, const char *p, char type) gid_to_gname (0, &tmpname); GNAME_TO_CHARS (tmpname, header->header.gname); free (tmpname); - + strcpy (header->header.magic, OLDGNU_MAGIC); header->header.typeflag = type; finish_header (st, header, -1); @@ -590,7 +600,9 @@ write_header_name (struct tar_stat_info *st) xheader_store ("path", st, NULL); return write_short_name (st); } - else if (NAME_FIELD_SIZE < strlen (st->file_name)) + else if ((archive_format == OLDGNU_FORMAT + && OLDGNU_NAME_FIELD_SIZE < strlen (st->file_name)) + || NAME_FIELD_SIZE < strlen (st->file_name)) return write_long_name (st); else return write_short_name (st); @@ -618,8 +630,9 @@ start_header (struct tar_stat_info *st) if (group_option != (gid_t) -1) st->stat.st_gid = group_option; if (mode_option) - st->stat.st_mode = ((st->stat.st_mode & ~MODE_ALL) - | mode_adjust (st->stat.st_mode, mode_option)); + st->stat.st_mode = + ((st->stat.st_mode & ~MODE_ALL) + | mode_adjust (st->stat.st_mode, mode_option, initial_umask)); /* Paul Eggert tried the trivial test ($WRITER cf a b; $READER tvf a) for a few tars and came up with the following interoperability @@ -847,7 +860,7 @@ dump_regular_file (int fd, struct tar_stat_info *st) if (multi_volume_option) { - assign_string (&save_name, st->file_name); + assign_string (&save_name, st->orig_file_name); save_sizeleft = size_left; save_totsize = st->stat.st_size; } @@ -873,9 +886,9 @@ dump_regular_file (int fd, struct tar_stat_info *st) return dump_status_short; } size_left -= count; - - set_next_block_after (blk + (bufsize - 1) / BLOCKSIZE); - + if (count) + set_next_block_after (blk + (bufsize - 1) / BLOCKSIZE); + if (count != bufsize) { char buf[UINTMAX_STRSIZE_BOUND]; @@ -888,7 +901,7 @@ dump_regular_file (int fd, struct tar_stat_info *st) STRINGIFY_BIGINT (size_left, buf))); if (! ignore_failed_read_option) exit_status = TAREXIT_FAILURE; - pad_archive (size_left); + pad_archive (size_left - (bufsize-count)); return dump_status_short; } } @@ -949,7 +962,7 @@ check_cache_directory (char *dirname) if (fd >= 0) { static char tagbuf[CACHEDIR_SIGNATURE_SIZE]; - + if (read (fd, tagbuf, CACHEDIR_SIGNATURE_SIZE) == CACHEDIR_SIGNATURE_SIZE && memcmp (tagbuf, CACHEDIR_SIGNATURE, CACHEDIR_SIGNATURE_SIZE) == 0) @@ -1066,7 +1079,7 @@ dump_dir0 (char *directory, { char const *entry; size_t entry_len; - char *name_buf = strdup (st->orig_file_name); + char *name_buf = xstrdup (st->orig_file_name); size_t name_size = strlen (name_buf); size_t name_len = name_size; @@ -1198,8 +1211,8 @@ create_archive (void) /* Calculate the hash of a link. */ -static unsigned -hash_link (void const *entry, unsigned n_buckets) +static size_t +hash_link (void const *entry, size_t n_buckets) { struct link const *l = entry; uintmax_t num = l->dev ^ l->ino; @@ -1250,13 +1263,16 @@ dump_hard_link (struct tar_stat_info *st) if ((duplicate = hash_lookup (link_table, &lp))) { /* We found a link. */ - char const *link_name = safer_name_suffix (duplicate->name, true); + char const *link_name = safer_name_suffix (duplicate->name, true, + absolute_names_option); duplicate->nlink--; block_ordinal = current_block_ordinal (); assign_string (&st->link_name, link_name); - if (NAME_FIELD_SIZE < strlen (link_name)) + if ((archive_format == OLDGNU_FORMAT + && OLDGNU_NAME_FIELD_SIZE < strlen (link_name)) + || NAME_FIELD_SIZE < strlen (link_name)) write_long_link (st); st->stat.st_size = 0; @@ -1317,7 +1333,7 @@ check_links (void) { if (lp->nlink) { - WARN ((0, 0, _("Missing links to '%s'.\n"), lp->name)); + WARN ((0, 0, _("Missing links to %s.\n"), quote (lp->name))); } } } @@ -1346,7 +1362,8 @@ dump_file0 (struct tar_stat_info *st, char *p, return; assign_string (&st->orig_file_name, p); - assign_string (&st->file_name, safer_name_suffix (p, false)); + assign_string (&st->file_name, + safer_name_suffix (p, false, absolute_names_option)); if (deref_stat (dereference_option, p, &st->stat) != 0) { @@ -1383,7 +1400,7 @@ dump_file0 (struct tar_stat_info *st, char *p, && OLDER_STAT_TIME (st->stat, m) && (!after_date_option || OLDER_STAT_TIME (st->stat, c))) { - if (!incremental_option) + if (!incremental_option && verbose_option) WARN ((0, 0, _("%s: file is unchanged; not dumped"), quotearg_colon (p))); return; @@ -1490,7 +1507,8 @@ dump_file0 (struct tar_stat_info *st, char *p, } buffer[size] = '\0'; assign_string (&st->link_name, buffer); - if (size > NAME_FIELD_SIZE) + if ((archive_format == OLDGNU_FORMAT && size > OLDGNU_NAME_FIELD_SIZE) + || size > NAME_FIELD_SIZE) write_long_link (st); block_ordinal = current_block_ordinal ();