* src/common.h (READ_LIKE_SUBCOMMAND): Remove define.
* src/tar.c (IS_SUBCOMMAND_CLASS): New macro.
(decode_options): Use IS_SUBCOMMAND_CLASS in checking
option compatibility.
Accept the --verify option only with subcommands that
write to the archive.
* tests/opcomp01.at: New test case.
* tests/opcomp02.at: New test case.
* tests/opcomp03.at: New test case.
* tests/opcomp04.at: New test case.
* tests/opcomp05.at: New test case.
* tests/opcomp06.at: New test case.
* tests/Makefile.am: Add new testcases.
* tests/testsuite.at: Likewise.
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;
"Jay Fenlason",
NULL
};
+\f
+/* 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)
{
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)
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")));
--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. */
multiv07.at\
multiv08.at\
old.at\
+ opcomp01.at\
+ opcomp02.at\
+ opcomp03.at\
+ opcomp04.at\
+ opcomp05.at\
+ opcomp06.at\
options.at\
options02.at\
owner.at\
--- /dev/null
+# 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 <http://www.gnu.org/licenses/>.
+
+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
+
--- /dev/null
+# 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 <http://www.gnu.org/licenses/>.
+
+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
+
--- /dev/null
+# 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 <http://www.gnu.org/licenses/>.
+
+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
+
--- /dev/null
+# 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 <http://www.gnu.org/licenses/>.
+
+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
+
--- /dev/null
+# 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 <http://www.gnu.org/licenses/>.
+
+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
+
--- /dev/null
+# 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 <http://www.gnu.org/licenses/>.
+
+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
+
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])
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])
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])
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])
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])
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])
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])
m4_include([capabs_raw01.at])
+AT_BANNER([Star tests])
m4_include([star/gtarfail.at])
m4_include([star/gtarfail2.at])