* configure.ac, NEWS: Version 1.20.90

* doc/tar.texi: Document -J, --no-auto-compress, etc.
* src/buffer.c (ct_tar): New constant.
(magic): Add lzop support.  Proposed by Kevin Day
<thekevinday@gmail.com>.
(check_compressed_archive): Do not use autodetect if the
compression program was specified explicitly.
Fall back to analyzing archive name, if the autodetection fails.
* src/suffix.c: Add .lzo
* src/tar.c: New options --lzop and --no-auto-compress.
New short option -J (alias for --lzma).
This commit is contained in:
Sergey Poznyakoff
2008-06-26 10:19:19 +00:00
parent 985637ab5a
commit c9a7297a8a
7 changed files with 138 additions and 33 deletions
+43 -17
View File
@@ -198,11 +198,13 @@ compute_duration ()
/* Compression detection */
enum compress_type {
ct_none,
ct_tar, /* Plain tar file */
ct_none, /* Unknown compression type */
ct_compress,
ct_gzip,
ct_bzip2,
ct_lzma
ct_lzma,
ct_lzop
};
struct zip_magic
@@ -215,11 +217,13 @@ struct zip_magic
};
static struct zip_magic const magic[] = {
{ ct_tar },
{ ct_none, },
{ ct_compress, 2, "\037\235", "compress", "-Z" },
{ ct_gzip, 2, "\037\213", "gzip", "-z" },
{ ct_bzip2, 3, "BZh", "bzip2", "-j" },
{ ct_lzma, 6, "\xFFLZMA", "lzma", "--lzma" }, /* FIXME: ???? */
{ ct_lzma, 6, "\xFFLZMA", "lzma", "-J" }, /* FIXME: ???? */
{ ct_lzop, 4, "\211LZO", "lzop", "--lzop" },
};
#define NMAGIC (sizeof(magic)/sizeof(magic[0]))
@@ -250,9 +254,9 @@ check_compressed_archive (bool *pshort)
if (tar_checksum (record_start, true) == HEADER_SUCCESS)
/* Probably a valid header */
return ct_none;
return ct_tar;
for (p = magic + 1; p < magic + NMAGIC; p++)
for (p = magic + 2; p < magic + NMAGIC; p++)
if (memcmp (record_start->buffer, p->magic, p->length) == 0)
return p->type;
@@ -272,14 +276,30 @@ open_compressed_archive ()
if (!multi_volume_option)
{
bool shortfile;
enum compress_type type = check_compressed_archive (&shortfile);
if (type == ct_none)
if (!use_compress_program_option)
{
if (shortfile)
ERROR ((0, 0, _("This does not look like a tar archive")));
return archive;
bool shortfile;
enum compress_type type = check_compressed_archive (&shortfile);
switch (type)
{
case ct_tar:
if (shortfile)
ERROR ((0, 0, _("This does not look like a tar archive")));
return archive;
case ct_none:
if (shortfile)
ERROR ((0, 0, _("This does not look like a tar archive")));
set_comression_program_by_suffix (archive_name_array[0], NULL);
if (!use_compress_program_option)
return archive;
break;
default:
use_compress_program_option = compress_program (type);
break;
}
}
/* FD is not needed any more */
@@ -289,7 +309,6 @@ open_compressed_archive ()
check_compressed_archive */
/* Open compressed archive */
use_compress_program_option = compress_program (type);
child_pid = sys_child_open_for_uncompress ();
read_full_records = true;
}
@@ -512,7 +531,7 @@ _open_archive (enum access_mode wanted_access)
archive = STDIN_FILENO;
type = check_compressed_archive (&shortfile);
if (type != ct_none)
if (type != ct_tar && type != ct_none)
FATAL_ERROR ((0, 0,
_("Archive is compressed. Use %s option"),
compress_option (type)));
@@ -561,9 +580,16 @@ _open_archive (enum access_mode wanted_access)
O_RDWR | O_CREAT | O_BINARY,
MODE_RW, rsh_command_option);
if (check_compressed_archive (NULL) != ct_none)
FATAL_ERROR ((0, 0,
_("Cannot update compressed archives")));
switch (check_compressed_archive (NULL))
{
case ct_none:
case ct_tar:
break;
default:
FATAL_ERROR ((0, 0,
_("Cannot update compressed archives")));
}
break;
}
+1
View File
@@ -39,6 +39,7 @@ struct compression_suffix compression_suffixes[] = {
{ S(tz2, bzip2) },
{ S(lzma, lzma) },
{ S(tlz, lzma) },
{ S(lzo, lzop) },
#undef S
};
+14 -7
View File
@@ -271,11 +271,11 @@ enum
IGNORE_FAILED_READ_OPTION,
INDEX_FILE_OPTION,
KEEP_NEWER_FILES_OPTION,
LZMA_OPTION,
MODE_OPTION,
MTIME_OPTION,
NEWER_MTIME_OPTION,
NO_ANCHORED_OPTION,
NO_AUTO_COMPRESS_OPTION,
NO_CHECK_DEVICE_OPTION,
NO_DELAY_DIRECTORY_RESTORE_OPTION,
NO_IGNORE_CASE_OPTION,
@@ -350,7 +350,7 @@ The version control may be set with --backup or VERSION_CONTROL, values are:\n\n
/* NOTE:
Available option letters are DEIJQY and eqy. Consider the following
Available option letters are DEIQY and eqy. Consider the following
assignments:
[For Solaris tar compatibility =/= Is it important at all?]
@@ -592,6 +592,9 @@ static struct argp_option options[] = {
N_("Compression options:"), GRID },
{"auto-compress", 'a', 0, 0,
N_("use archive suffix to determine the compression program"), GRID+1 },
{"no-auto-compress", NO_AUTO_COMPRESS_OPTION, 0, 0,
N_("do not use use archive suffix to determine the compression program"),
GRID+1 },
{"bzip2", 'j', 0, 0,
N_("filter the archive through bzip2"), GRID+1 },
{"gzip", 'z', 0, 0,
@@ -601,7 +604,7 @@ static struct argp_option options[] = {
{"compress", 'Z', 0, 0,
N_("filter the archive through compress"), GRID+1 },
{"uncompress", 0, 0, OPTION_ALIAS, NULL, GRID+1 },
{"lzma", LZMA_OPTION, 0, 0,
{"lzma", 'J', 0, 0,
N_("filter the archive through lzma"), GRID+1 },
{"use-compress-program", USE_COMPRESS_PROGRAM_OPTION, N_("PROG"), 0,
N_("filter through PROG (must accept -d)"), GRID+1 },
@@ -1262,6 +1265,10 @@ parse_opt (int key, char *arg, struct argp_state *state)
case 'a':
args->compress_autodetect = true;
break;
case NO_AUTO_COMPRESS_OPTION:
args->compress_autodetect = false;
break;
case 'b':
{
@@ -1355,6 +1362,10 @@ parse_opt (int key, char *arg, struct argp_state *state)
set_use_compress_program_option ("bzip2");
break;
case 'J':
set_use_compress_program_option ("lzma");
break;
case 'k':
/* Don't replace existing files. */
old_files_option = KEEP_OLD_FILES;
@@ -1386,10 +1397,6 @@ parse_opt (int key, char *arg, struct argp_state *state)
}
break;
case LZMA_OPTION:
set_use_compress_program_option ("lzma");
break;
case 'm':
touch_option = true;
break;