diff --git a/src/common.h b/src/common.h
index 4f7c19f5..9ac22b81 100644
--- a/src/common.h
+++ b/src/common.h
@@ -96,11 +96,6 @@ enum subcommand
GLOBAL enum subcommand subcommand_option;
-#define READ_LIKE_SUBCOMMAND \
- (subcommand_option == EXTRACT_SUBCOMMAND \
- || subcommand_option == DIFF_SUBCOMMAND \
- || subcommand_option == LIST_SUBCOMMAND)
-
/* Selected format for output archive. */
GLOBAL enum archive_format archive_format;
diff --git a/src/tar.c b/src/tar.c
index c29b4fab..b602a5c2 100644
--- a/src/tar.c
+++ b/src/tar.c
@@ -2346,7 +2346,29 @@ static const char *tar_authors[] = {
"Jay Fenlason",
NULL
};
+
+/* Subcommand classes */
+#define SUBCL_READ 0x01 /* subcommand reads from the archive */
+#define SUBCL_WRITE 0x02 /* subcommand writes to the archive */
+#define SUBCL_UPDATE 0x04 /* subcommand updates existing archive */
+#define SUBCL_TEST 0x08 /* subcommand tests archive header or meta-info */
+static int subcommand_class[] = {
+ /* UNKNOWN_SUBCOMMAND */ 0,
+ /* APPEND_SUBCOMMAND */ SUBCL_WRITE|SUBCL_UPDATE,
+ /* CAT_SUBCOMMAND */ SUBCL_WRITE,
+ /* CREATE_SUBCOMMAND */ SUBCL_WRITE,
+ /* DELETE_SUBCOMMAND */ SUBCL_WRITE|SUBCL_UPDATE,
+ /* DIFF_SUBCOMMAND */ SUBCL_READ,
+ /* EXTRACT_SUBCOMMAND */ SUBCL_READ,
+ /* LIST_SUBCOMMAND */ SUBCL_READ,
+ /* UPDATE_SUBCOMMAND */ SUBCL_WRITE|SUBCL_UPDATE,
+ /* TEST_LABEL_SUBCOMMAND */ SUBCL_TEST
+};
+
+/* Return t if the subcommand_option is in class(es) f */
+#define IS_SUBCOMMAND_CLASS(f) (subcommand_class[subcommand_option] & (f))
+
static void
decode_options (int argc, char **argv)
{
@@ -2510,12 +2532,10 @@ decode_options (int argc, char **argv)
if (!args.input_files)
USAGE_ERROR ((0, 0,
_("--occurrence is meaningless without a file list")));
- if (subcommand_option != DELETE_SUBCOMMAND
- && subcommand_option != DIFF_SUBCOMMAND
- && subcommand_option != EXTRACT_SUBCOMMAND
- && subcommand_option != LIST_SUBCOMMAND)
- USAGE_ERROR ((0, 0,
- _("--occurrence cannot be used in the requested operation mode")));
+ if (!IS_SUBCOMMAND_CLASS (SUBCL_READ))
+ USAGE_ERROR ((0, 0,
+ _("--occurrence cannot be used with %s"),
+ subcommand_string (subcommand_option)));
}
if (archive_names == 0)
@@ -2574,15 +2594,16 @@ decode_options (int argc, char **argv)
USAGE_ERROR ((0, 0, _("Cannot verify multi-volume archives")));
if (use_compress_program_option)
USAGE_ERROR ((0, 0, _("Cannot verify compressed archives")));
+ if (!IS_SUBCOMMAND_CLASS (SUBCL_WRITE))
+ USAGE_ERROR ((0, 0, _("--verify cannot be used with %s"),
+ subcommand_string (subcommand_option)));
}
if (use_compress_program_option)
{
if (multi_volume_option)
USAGE_ERROR ((0, 0, _("Cannot use multi-volume compressed archives")));
- if (subcommand_option == UPDATE_SUBCOMMAND
- || subcommand_option == APPEND_SUBCOMMAND
- || subcommand_option == DELETE_SUBCOMMAND)
+ if (IS_SUBCOMMAND_CLASS (SUBCL_UPDATE))
USAGE_ERROR ((0, 0, _("Cannot update compressed archives")));
if (subcommand_option == CAT_SUBCOMMAND)
USAGE_ERROR ((0, 0, _("Cannot concatenate compressed archives")));
@@ -2594,24 +2615,24 @@ decode_options (int argc, char **argv)
--gray */
if (args.pax_option
&& archive_format != POSIX_FORMAT
- && !READ_LIKE_SUBCOMMAND)
+ && !IS_SUBCOMMAND_CLASS (SUBCL_READ))
USAGE_ERROR ((0, 0, _("--pax-option can be used only on POSIX archives")));
/* star creates non-POSIX typed archives with xattr support, so allow the
- extra headers whenn reading */
+ extra headers when reading */
if ((acls_option > 0)
&& archive_format != POSIX_FORMAT
- && !READ_LIKE_SUBCOMMAND)
+ && !IS_SUBCOMMAND_CLASS (SUBCL_READ))
USAGE_ERROR ((0, 0, _("--acls can be used only on POSIX archives")));
if ((selinux_context_option > 0)
&& archive_format != POSIX_FORMAT
- && !READ_LIKE_SUBCOMMAND)
+ && !IS_SUBCOMMAND_CLASS (SUBCL_READ))
USAGE_ERROR ((0, 0, _("--selinux can be used only on POSIX archives")));
if ((xattrs_option > 0)
&& archive_format != POSIX_FORMAT
- && !READ_LIKE_SUBCOMMAND)
+ && !IS_SUBCOMMAND_CLASS (SUBCL_READ))
USAGE_ERROR ((0, 0, _("--xattrs can be used only on POSIX archives")));
/* If ready to unlink hierarchies, so we are for simpler files. */
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 500de899..8b7acb16 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -134,6 +134,12 @@ TESTSUITE_AT = \
multiv07.at\
multiv08.at\
old.at\
+ opcomp01.at\
+ opcomp02.at\
+ opcomp03.at\
+ opcomp04.at\
+ opcomp05.at\
+ opcomp06.at\
options.at\
options02.at\
owner.at\
diff --git a/tests/opcomp01.at b/tests/opcomp01.at
new file mode 100644
index 00000000..f696be82
--- /dev/null
+++ b/tests/opcomp01.at
@@ -0,0 +1,34 @@
+# Process this file with autom4te to create testsuite. -*- Autotest -*-
+
+# Test suite for GNU tar.
+# Copyright 2013 Free Software Foundation, Inc.
+
+# This file is part of GNU tar.
+
+# GNU tar is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
+
+# GNU tar is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see .
+
+AT_SETUP([occurrence compatibility])
+AT_KEYWORDS([opcomp opcomp01])
+
+AT_CHECK([
+tar --occurrence=1 -cf test.tar .
+],
+[2],
+[],
+[tar: --occurrence cannot be used with -c
+Try 'tar --help' or 'tar --usage' for more information.
+])
+
+AT_CLEANUP
+
diff --git a/tests/opcomp02.at b/tests/opcomp02.at
new file mode 100644
index 00000000..85538c8b
--- /dev/null
+++ b/tests/opcomp02.at
@@ -0,0 +1,34 @@
+# Process this file with autom4te to create testsuite. -*- Autotest -*-
+
+# Test suite for GNU tar.
+# Copyright 2013 Free Software Foundation, Inc.
+
+# This file is part of GNU tar.
+
+# GNU tar is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
+
+# GNU tar is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see .
+
+AT_SETUP([occurrence compatibility])
+AT_KEYWORDS([opcomp opcomp02])
+
+AT_CHECK([
+tar --occurrence=1 -tf test.tar
+],
+[2],
+[],
+[tar: --occurrence is meaningless without a file list
+Try 'tar --help' or 'tar --usage' for more information.
+])
+
+AT_CLEANUP
+
diff --git a/tests/opcomp03.at b/tests/opcomp03.at
new file mode 100644
index 00000000..aa540535
--- /dev/null
+++ b/tests/opcomp03.at
@@ -0,0 +1,34 @@
+# Process this file with autom4te to create testsuite. -*- Autotest -*-
+
+# Test suite for GNU tar.
+# Copyright 2013 Free Software Foundation, Inc.
+
+# This file is part of GNU tar.
+
+# GNU tar is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
+
+# GNU tar is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see .
+
+AT_SETUP([--verify compatibility])
+AT_KEYWORDS([opcomp opcomp03])
+
+AT_CHECK([
+tar -tWf test.tar .
+],
+[2],
+[],
+[tar: --verify cannot be used with -t
+Try 'tar --help' or 'tar --usage' for more information.
+])
+
+AT_CLEANUP
+
diff --git a/tests/opcomp04.at b/tests/opcomp04.at
new file mode 100644
index 00000000..67f94b5a
--- /dev/null
+++ b/tests/opcomp04.at
@@ -0,0 +1,38 @@
+# Process this file with autom4te to create testsuite. -*- Autotest -*-
+
+# Test suite for GNU tar.
+# Copyright 2013 Free Software Foundation, Inc.
+
+# This file is part of GNU tar.
+
+# GNU tar is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
+
+# GNU tar is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see .
+
+AT_SETUP([compress option compatibility])
+AT_KEYWORDS([opcomp opcomp04])
+
+AT_CHECK([
+AT_GZIP_PREREQ
+genfile --file file
+tar czf test.tar file
+genfile --file newfile
+tar rzf test.tar newfile
+],
+[2],
+[],
+[tar: Cannot update compressed archives
+Try 'tar --help' or 'tar --usage' for more information.
+])
+
+AT_CLEANUP
+
diff --git a/tests/opcomp05.at b/tests/opcomp05.at
new file mode 100644
index 00000000..f470d4ca
--- /dev/null
+++ b/tests/opcomp05.at
@@ -0,0 +1,34 @@
+# Process this file with autom4te to create testsuite. -*- Autotest -*-
+
+# Test suite for GNU tar.
+# Copyright 2013 Free Software Foundation, Inc.
+
+# This file is part of GNU tar.
+
+# GNU tar is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
+
+# GNU tar is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see .
+
+AT_SETUP([--pax-option compatibility])
+AT_KEYWORDS([opcomp opcomp05])
+
+AT_CHECK([
+tar -Hgnu -cf test.tar --pax-option user:=root .
+],
+[2],
+[],
+[tar: --pax-option can be used only on POSIX archives
+Try 'tar --help' or 'tar --usage' for more information.
+])
+
+AT_CLEANUP
+
diff --git a/tests/opcomp06.at b/tests/opcomp06.at
new file mode 100644
index 00000000..12de5b22
--- /dev/null
+++ b/tests/opcomp06.at
@@ -0,0 +1,36 @@
+# Process this file with autom4te to create testsuite. -*- Autotest -*-
+
+# Test suite for GNU tar.
+# Copyright 2013 Free Software Foundation, Inc.
+
+# This file is part of GNU tar.
+
+# GNU tar is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
+
+# GNU tar is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see .
+
+AT_SETUP([--pax-option compatibility])
+AT_KEYWORDS([opcomp opcomp06])
+
+AT_CHECK([
+AT_ACLS_PREREQ
+genfile --file file
+tar -cf test.tar --acls -Hgnu file
+],
+[2],
+[],
+[tar: --acls can be used only on POSIX archives
+Try 'tar --help' or 'tar --usage' for more information.
+])
+
+AT_CLEANUP
+
diff --git a/tests/testsuite.at b/tests/testsuite.at
index 1de7d305..d3fabe5f 100644
--- a/tests/testsuite.at
+++ b/tests/testsuite.at
@@ -188,20 +188,40 @@ m4_include([pipe.at])
m4_include([options.at])
m4_include([options02.at])
+AT_BANNER([Option compatibility])
+m4_include([opcomp01.at])
+m4_include([opcomp02.at])
+m4_include([opcomp03.at])
+m4_include([opcomp04.at])
+m4_include([opcomp05.at])
+m4_include([opcomp06.at])
+
+AT_BANNER([The -T option])
m4_include([T-empty.at])
m4_include([T-null.at])
+AT_BANNER([Various options])
m4_include([indexfile.at])
m4_include([verbose.at])
+m4_include([gzip.at])
+m4_include([recurse.at])
+m4_include([shortrec.at])
+AT_BANNER([The --same-order option])
+m4_include([same-order01.at])
+m4_include([same-order02.at])
+
+AT_BANNER([Append])
m4_include([append.at])
m4_include([append01.at])
m4_include([append02.at])
m4_include([append03.at])
+AT_BANNER([Transforms])
m4_include([xform-h.at])
m4_include([xform01.at])
+AT_BANNER([Exclude])
m4_include([exclude.at])
m4_include([exclude01.at])
m4_include([exclude02.at])
@@ -220,12 +240,14 @@ m4_include([exclude14.at])
m4_include([exclude15.at])
m4_include([exclude16.at])
+AT_BANNER([Deletions])
m4_include([delete01.at])
m4_include([delete02.at])
m4_include([delete03.at])
m4_include([delete04.at])
m4_include([delete05.at])
+AT_BANNER([Extracting])
m4_include([extrac01.at])
m4_include([extrac02.at])
m4_include([extrac03.at])
@@ -245,17 +267,16 @@ m4_include([extrac16.at])
m4_include([extrac17.at])
m4_include([extrac18.at])
m4_include([extrac19.at])
+m4_include([backup01.at])
+AT_BANNER([Volume label operations])
m4_include([label01.at])
m4_include([label02.at])
m4_include([label03.at])
m4_include([label04.at])
m4_include([label05.at])
-m4_include([backup01.at])
-
-m4_include([gzip.at])
-
+AT_BANNER([Incremental archives])
m4_include([incremental.at])
m4_include([incr01.at])
m4_include([incr02.at])
@@ -269,9 +290,11 @@ m4_include([incr04.at])
m4_include([incr05.at])
m4_include([incr06.at])
+AT_BANNER([Files removed while archiving])
m4_include([filerem01.at])
m4_include([filerem02.at])
+AT_BANNER([Renames])
m4_include([rename01.at])
m4_include([rename02.at])
m4_include([rename03.at])
@@ -279,21 +302,26 @@ m4_include([rename04.at])
m4_include([rename05.at])
m4_include([chtype.at])
+AT_BANNER([Ignore failing reads])
m4_include([ignfail.at])
+AT_BANNER([Link handling])
m4_include([link01.at])
m4_include([link02.at])
m4_include([link03.at])
m4_include([link04.at])
+AT_BANNER([Specific archive formats])
m4_include([longv7.at])
m4_include([long01.at])
m4_include([lustar01.at])
m4_include([lustar02.at])
m4_include([lustar03.at])
+m4_include([old.at])
m4_include([time01.at])
+AT_BANNER([Multivolume archives])
m4_include([multiv01.at])
m4_include([multiv02.at])
m4_include([multiv03.at])
@@ -303,16 +331,10 @@ m4_include([multiv06.at])
m4_include([multiv07.at])
m4_include([multiv08.at])
-m4_include([old.at])
+AT_BANNER([Owner and Groups])
m4_include([owner.at])
-m4_include([recurse.at])
-
-m4_include([same-order01.at])
-m4_include([same-order02.at])
-
-m4_include([shortrec.at])
-
+AT_BANNER([Sparse files])
m4_include([sparse01.at])
m4_include([sparse02.at])
m4_include([sparse03.at])
@@ -322,28 +344,33 @@ m4_include([spmvp00.at])
m4_include([spmvp01.at])
m4_include([spmvp10.at])
+AT_BANNER([Updates])
m4_include([update.at])
m4_include([update01.at])
m4_include([update02.at])
+AT_BANNER([Verifying the archive])
m4_include([verify.at])
+AT_BANNER([Volume operations])
m4_include([volume.at])
m4_include([volsize.at])
+AT_BANNER()
m4_include([comprec.at])
m4_include([shortfile.at])
m4_include([shortupd.at])
m4_include([truncate.at])
m4_include([grow.at])
+m4_include([sigpipe.at])
+AT_BANNER([Removing files after archiving])
m4_include([remfiles01.at])
m4_include([remfiles02.at])
m4_include([remfiles03.at])
-m4_include([sigpipe.at])
-
+AT_BANNER([Extended attributes])
m4_include([xattr01.at])
m4_include([xattr02.at])
m4_include([xattr03.at])
@@ -358,6 +385,7 @@ m4_include([selacl01.at])
m4_include([capabs_raw01.at])
+AT_BANNER([Star tests])
m4_include([star/gtarfail.at])
m4_include([star/gtarfail2.at])