1 /* Warnings for GNU tar.
2
3 Copyright 2009-2021 Free Software Foundation, Inc.
4
5 This file is part of GNU tar.
6
7 GNU tar is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3 of the License, or
10 (at your option) any later version.
11
12 GNU tar is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with this program. If not, see <http://www.gnu.org/licenses/>. */
19
20 #include <system.h>
21 #include <argmatch.h>
22
23 #include "common.h"
24
25 static char const *const warning_args[] = {
26 "all",
27 "alone-zero-block",
28 "bad-dumpdir",
29 "cachedir",
30 "contiguous-cast",
31 "file-changed",
32 "file-ignored",
33 "file-removed",
34 "file-shrank",
35 "file-unchanged",
36 "filename-with-nuls",
37 "ignore-archive",
38 "ignore-newer",
39 "new-directory",
40 "rename-directory",
41 "symlink-cast",
42 "timestamp",
43 "unknown-cast",
44 "unknown-keyword",
45 "xdev",
46 "decompress-program",
47 "existing-file",
48 "xattr-write",
49 "record-size",
50 "failed-read",
51 NULL
52 };
53
54 static int warning_types[] = {
55 WARN_ALL,
56 WARN_ALONE_ZERO_BLOCK,
57 WARN_BAD_DUMPDIR,
58 WARN_CACHEDIR,
59 WARN_CONTIGUOUS_CAST,
60 WARN_FILE_CHANGED,
61 WARN_FILE_IGNORED,
62 WARN_FILE_REMOVED,
63 WARN_FILE_SHRANK,
64 WARN_FILE_UNCHANGED,
65 WARN_FILENAME_WITH_NULS,
66 WARN_IGNORE_ARCHIVE,
67 WARN_IGNORE_NEWER,
68 WARN_NEW_DIRECTORY,
69 WARN_RENAME_DIRECTORY,
70 WARN_SYMLINK_CAST,
71 WARN_TIMESTAMP,
72 WARN_UNKNOWN_CAST,
73 WARN_UNKNOWN_KEYWORD,
74 WARN_XDEV,
75 WARN_DECOMPRESS_PROGRAM,
76 WARN_EXISTING_FILE,
77 WARN_XATTR_WRITE,
78 WARN_RECORD_SIZE,
79 WARN_FAILED_READ
80 };
81
82 ARGMATCH_VERIFY (warning_args, warning_types);
83
84 int warning_option = WARN_ALL;
85
86 void
set_warning_option(const char * arg)87 set_warning_option (const char *arg)
88 {
89 int negate = 0;
90 int option;
91
92 if (strcmp (arg, "none") == 0)
93 {
94 warning_option = 0;
95 return;
96 }
97 if (strlen (arg) > 2 && memcmp (arg, "no-", 3) == 0)
98 {
99 negate = 1;
100 arg += 3;
101 }
102
103 option = XARGMATCH ("--warning", arg,
104 warning_args, warning_types);
105 if (negate)
106 warning_option &= ~option;
107 else
108 warning_option |= option;
109 }
110