X-Git-Url: https://git.dogcows.com/gitweb?a=blobdiff_plain;f=src%2Flist.c;h=3166e686c1ca43970807805f75da15a87204a004;hb=320298c663ac4849226a2db820bee1bdb75d21ef;hp=f5684c443aa30b3ca97b282469c4914b3740c4f2;hpb=683390b02dedca56036b9b1b2aeae46fbfde4e49;p=chaz%2Ftar diff --git a/src/list.c b/src/list.c index f5684c4..3166e68 100644 --- a/src/list.c +++ b/src/list.c @@ -1,7 +1,7 @@ /* List a tar archive, with support routines for reading a tar archive. Copyright (C) 1988, 1992, 1993, 1994, 1996, 1997, 1998, 1999, 2000, - 2001, 2003 Free Software Foundation, Inc. + 2001, 2003, 2004 Free Software Foundation, Inc. Written by John Gilmore, on 1985-08-26. @@ -20,7 +20,7 @@ 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ /* Define to non-zero for forcing old ctime format instead of ISO format. */ -#undef USE_OLD_CTIME +#undef USE_OLD_CTIME #include "system.h" #include @@ -78,7 +78,7 @@ read_and (void (*do_something) (void)) prev_status = status; tar_stat_destroy (¤t_stat_info); xheader_destroy (&extended_header); - + status = read_header (false); switch (status) { @@ -92,12 +92,17 @@ read_and (void (*do_something) (void)) Ensure incoming names are null terminated. */ if (! name_match (current_stat_info.file_name) - || (newer_mtime_option != TYPE_MINIMUM (time_t) + || (NEWER_OPTION_INITIALIZED (newer_mtime_option) /* FIXME: We get mtime now, and again later; this causes duplicate diagnostics if header.mtime is bogus. */ && ((current_stat_info.stat.st_mtime - = TIME_FROM_HEADER (current_header->header.mtime)) - < newer_mtime_option)) + = TIME_FROM_HEADER (current_header->header.mtime)), +#ifdef ST_MTIM_NSEC + /* FIXME: Grab fractional time stamps from + extended header. */ + current_stat_info.stat.st_mtim.ST_MTIM_NSEC = 0, +#endif + OLDER_STAT_TIME (current_stat_info.stat, m))) || excluded_name (current_stat_info.file_name)) { switch (current_header->header.typeflag) @@ -166,6 +171,15 @@ read_and (void (*do_something) (void)) case HEADER_ZERO_BLOCK: case HEADER_SUCCESS: + if (block_number_option) + { + char buf[UINTMAX_STRSIZE_BOUND]; + off_t block_ordinal = current_block_ordinal (); + block_ordinal -= recent_long_name_blocks; + block_ordinal -= recent_long_link_blocks; + fprintf (stdlis, _("block %s: "), + STRINGIFY_BIGINT (block_ordinal, buf)); + } ERROR ((0, 0, _("Skipping to next header"))); break; @@ -356,7 +370,7 @@ read_header (bool raw_extended_headers) xalloc_die (); header_copy = xmalloc (size + 1); - + if (header->header.typeflag == GNUTYPE_LONGNAME) { if (next_long_name) @@ -371,7 +385,7 @@ read_header (bool raw_extended_headers) next_long_link = header_copy; next_long_link_blocks = size / BLOCKSIZE; } - + set_next_block_after (header); *header_copy = *header; bp = header_copy->buffer + BLOCKSIZE; @@ -387,7 +401,7 @@ read_header (bool raw_extended_headers) written = available_space_after (data_block); if (written > size) written = size; - + memcpy (bp, data_block->buffer, written); bp += written; set_next_block_after ((union block *) @@ -403,7 +417,7 @@ read_header (bool raw_extended_headers) xheader_read (header, OFF_FROM_HEADER (header->header.size)); xheader_decode_global (); } - + /* Loop! */ } @@ -520,7 +534,7 @@ decode_header (union block *header, struct tar_stat_info *stat_info, assign_string (&stat_info->gname, header->header.gname); stat_info->devmajor = MAJOR_FROM_HEADER (header->header.devmajor); stat_info->devminor = MINOR_FROM_HEADER (header->header.devminor); - + stat_info->stat.st_atime = start_time; stat_info->stat.st_ctime = start_time; @@ -559,7 +573,7 @@ decode_header (union block *header, struct tar_stat_info *stat_info, || !gname_to_gid (header->header.gname, &stat_info->stat.st_gid)) stat_info->stat.st_gid = GID_FROM_HEADER (header->header.gid); } - + switch (header->header.typeflag) { case BLKTYPE: @@ -573,8 +587,14 @@ decode_header (union block *header, struct tar_stat_info *stat_info, } } + stat_info->archive_file_size = stat_info->stat.st_size; xheader_decode (stat_info); - current_stat_info.archive_file_size = current_stat_info.stat.st_size; + + if (sparse_member_p (stat_info)) + { + sparse_fixup_header (stat_info); + stat_info->is_sparse = true; + } } /* Convert buffer at WHERE0 of size DIGS from external format to @@ -955,7 +975,7 @@ print_header (struct tar_stat_info *st, off_t block_ordinal) char modes[11]; char const *time_stamp; char *temp_name = st->orig_file_name ? st->orig_file_name : st->file_name; - + /* These hold formatted ints. */ char uform[UINTMAX_STRSIZE_BOUND], gform[UINTMAX_STRSIZE_BOUND]; char *user, *group; @@ -1102,16 +1122,10 @@ print_header (struct tar_stat_info *st, off_t block_ordinal) strcat (size, STRINGIFY_BIGINT (minor (st->stat.st_rdev), uintbuf)); break; - case GNUTYPE_SPARSE: - strcpy (size, - STRINGIFY_BIGINT - (UINTMAX_FROM_HEADER (current_header - ->oldgnu_header.realsize), - uintbuf)); - break; + default: /* st->stat.st_size keeps stored file size */ - strcpy (size, STRINGIFY_BIGINT (st->archive_file_size, uintbuf)); + strcpy (size, STRINGIFY_BIGINT (st->stat.st_size, uintbuf)); break; } @@ -1188,7 +1202,7 @@ print_header (struct tar_stat_info *st, off_t block_ordinal) /* Print a similar line when we make a directory automatically. */ void -print_for_mkdir (char *pathname, int length, mode_t mode) +print_for_mkdir (char *dirname, int length, mode_t mode) { char modes[11]; @@ -1207,7 +1221,7 @@ print_for_mkdir (char *pathname, int length, mode_t mode) } fprintf (stdlis, "%s %*s %.*s\n", modes, ugswidth + DATEWIDTH, - _("Creating directory:"), length, quotearg (pathname)); + _("Creating directory:"), length, quotearg (dirname)); } } @@ -1223,6 +1237,19 @@ skip_file (off_t size) save_sizeleft = size; } + if (seekable_archive) + { + off_t nblk = seek_archive (size); + if (nblk >= 0) + { + size -= nblk * BLOCKSIZE; + if (multi_volume_option) /* Argh.. */ + save_sizeleft -= nblk * BLOCKSIZE; + } + else + seekable_archive = false; + } + while (size > 0) { x = find_next_block (); @@ -1243,20 +1270,10 @@ skip_member (void) char save_typeflag = current_header->header.typeflag; set_next_block_after (current_header); - if (current_format == OLDGNU_FORMAT - && current_header->oldgnu_header.isextended) - { - union block *exhdr; - do - { - exhdr = find_next_block (); - if (!exhdr) - FATAL_ERROR ((0, 0, _("Unexpected EOF in archive"))); - set_next_block_after (exhdr); - } - while (exhdr->sparse_header.isextended); - } + assign_string (&save_name, current_stat_info.file_name); - if (save_typeflag != DIRTYPE) + if (sparse_member_p (¤t_stat_info)) + sparse_skip_file (¤t_stat_info); + else if (save_typeflag != DIRTYPE) skip_file (current_stat_info.stat.st_size); }