diff -pur tar-1.13.25/ChangeLog my-tar-1.13.25/ChangeLog --- tar-1.13.25/ChangeLog Wed Sep 26 13:54:08 2001 +++ my-tar-1.13.25/ChangeLog Mon Jan 14 22:39:30 2002 @@ -1,3 +1,22 @@ +2002-01-14 Jason Spence + + * THANKS: Add Jason Spence. + + * doc/tar.texi: Document the new behavior. + + * src/common.h: Added new return values for read_header and magic + numbers for bzip2 and gzip. + + * src/list.c (read_and): Added logic for new return values from + read_header which will automatically re-open the file if + read_header reports it is a compressed archive. + + * src/list.c (read_header): Added logic to detect bzip2 and gzip + headers. + + * src/tar.c (set_use_compress_program_option): Changed prototype + so it can be called from read_and in module list.c. + 2001-09-26 Paul Eggert * NEWS, configure.ac (AM_INIT_AUTOMAKE): Version 1.13.25. diff -pur tar-1.13.25/THANKS my-tar-1.13.25/THANKS --- tar-1.13.25/THANKS Wed Sep 26 13:29:16 2001 +++ my-tar-1.13.25/THANKS Mon Jan 14 22:11:16 2002 @@ -206,6 +206,7 @@ Jan Carlson address@hidden Jan Djarv address@hidden Janice Burton address@hidden Janne Snabb address@hidden +Jason Spence address@hidden Jason R. Mastaler address@hidden Jay Fenlason address@hidden Jean-Michel Soenen address@hidden diff -pur tar-1.13.25/doc/tar.texi my-tar-1.13.25/doc/tar.texi --- tar-1.13.25/doc/tar.texi Wed Sep 26 11:46:09 2001 +++ my-tar-1.13.25/doc/tar.texi Mon Jan 14 22:20:53 2002 @@ -6421,6 +6421,17 @@ disk space, by using pipes internally: $ @kbd{tar tfz archive.tar.gz} @end example address@hidden tar is smart enough to figure out if you are trying to +decompress an archive compressed using the bzip2 or gzip algorithms, +and will automatically decompress them for you using the appropriate +program if necessary. This is especially useful if you are not sure +which algorithm was used to compress your archive. In that case, it +is not necessary to specify either decompression option: + address@hidden +$ @kbd{tar tf archive.tar.gz} address@hidden example + @cindex corrupted archives About corrupted compressed archives: @command{gzip}'ed files have no redundancy, for maximum compression. The adaptive nature of the diff -pur tar-1.13.25/src/common.h my-tar-1.13.25/src/common.h --- tar-1.13.25/src/common.h Thu Sep 20 17:00:55 2001 +++ my-tar-1.13.25/src/common.h Mon Jan 14 22:23:46 2002 @@ -425,9 +425,17 @@ enum read_header HEADER_SUCCESS_EXTENDED, /* likewise, but we got an extended header */ HEADER_ZERO_BLOCK, /* zero block where header expected */ HEADER_END_OF_FILE, /* true end of file while header expected */ - HEADER_FAILURE /* ill-formed header, or bad checksum */ + HEADER_FAILURE, /* ill-formed header, or bad checksum */ + HEADER_GZIP, /* trying to untar a gzip compressed file */ + HEADER_BZIP2 /* trying to untar a bzip2 compressed file */ }; +/* magic numbers to identify compressed archives */ +#define GZIP_MAGIC_LEN 2 +#define GZIP_MAGIC "\037\213" +#define BZIP2_MAGIC_LEN 2 +#define BZIP2_MAGIC "BZ" + extern union block *current_header; extern struct stat current_stat; extern enum archive_format current_format; @@ -570,6 +578,7 @@ int is_avoided_name PARAMS ((char const int confirm PARAMS ((const char *, const char *)); void request_stdin PARAMS ((const char *)); +void set_use_compress_program_option PARAMS ((const char *string)); /* Module update.c. */ diff -pur tar-1.13.25/src/list.c my-tar-1.13.25/src/list.c --- tar-1.13.25/src/list.c Wed Sep 26 13:05:04 2001 +++ my-tar-1.13.25/src/list.c Mon Jan 14 22:30:52 2002 @@ -83,6 +83,18 @@ read_and (void (*do_something) ()) case HEADER_STILL_UNREAD: abort (); + case HEADER_GZIP: + close_archive(); + set_use_compress_program_option("gzip"); + open_archive (ACCESS_READ); + continue; + + case HEADER_BZIP2: + close_archive(); + set_use_compress_program_option("bzip2"); + open_archive (ACCESS_READ); + continue; + case HEADER_SUCCESS: /* Valid header. We should decode next field (mode) first. @@ -305,6 +317,14 @@ read_header (bool raw_extended_headers) } unsigned_sum += ' ' * sizeof header->header.chksum; signed_sum += ' ' * sizeof header->header.chksum; + if (strncmp(GZIP_MAGIC, header->buffer, GZIP_MAGIC_LEN) == 0) + { + return HEADER_GZIP; + } + if (strncmp(BZIP2_MAGIC, header->buffer, BZIP2_MAGIC_LEN) == 0) + { + return HEADER_BZIP2; + } parsed_sum = from_header (header->header.chksum, sizeof header->header.chksum, 0, diff -pur tar-1.13.25/src/tar.c my-tar-1.13.25/src/tar.c --- tar-1.13.25/src/tar.c Thu Sep 20 17:11:27 2001 +++ my-tar-1.13.25/src/tar.c Mon Jan 14 21:51:18 2002 @@ -480,7 +480,7 @@ set_subcommand_option (enum subcommand s subcommand_option = subcommand; } -static void +void set_use_compress_program_option (const char *string) { if (use_compress_program_option && strcmp (use_compress_program_option, string) != 0)