浏览代码

New option --warning=failed-read

* NEWS: Document the --warning=failed-read option.
* doc/tar.texi: Likewise.
* doc/tar.1: Likewise.
* src/common.h (WARN_FAILED_READ): New constant.
(WARNING_ENABLED): New macro.
* src/misc.c (close_diag, open_diag)
(read_diag_details, readlink_diag)
(savedir_diag, seek_diag_details)
(stat_diag): Suppress warnings if WARN_FAILED_READ is set.
* src/warning.c (failed-read): New keyword.
Sergey Poznyakoff 7 年之前
父节点
当前提交
32e51de2af
共有 6 个文件被更改,包括 66 次插入11 次删除
  1. 12 0
      NEWS
  2. 7 1
      doc/tar.1
  3. 12 1
      doc/tar.texi
  4. 4 1
      src/common.h
  5. 28 7
      src/misc.c
  6. 3 1
      src/warning.c

+ 12 - 0
NEWS

@@ -37,6 +37,18 @@ This helps the output of 'tar' to be more deterministic.
 In some cases tar would restore the directory permissions too early,
 In some cases tar would restore the directory permissions too early,
 causing subsequent link extractions in that directory to fail.
 causing subsequent link extractions in that directory to fail.
 
 
+* The --warnings=failed-read option
+
+This new warning control option suppresses warning messages about
+unreadable files and directories. It has effect only if used together
+with the --ignore-failed-read option.  
+
+* The --warnings=none option now suppresses all warnings
+
+This includes warnings about unreadable files produced when
+--ignore-failed-read is in effect. To output these, use
+--warnings=none --warnings=no-failed-read.
+
 
 
 version 1.29 - Sergey Poznyakoff, 2016-05-16
 version 1.29 - Sergey Poznyakoff, 2016-05-16
 
 

+ 7 - 1
doc/tar.1

@@ -13,7 +13,7 @@
 .\"
 .\"
 .\" You should have received a copy of the GNU General Public License
 .\" You should have received a copy of the GNU General Public License
 .\" along with this program.  If not, see <http://www.gnu.org/licenses/>.
 .\" along with this program.  If not, see <http://www.gnu.org/licenses/>.
-.TH TAR 1 "March 23, 2016" "TAR" "GNU TAR Manual"
+.TH TAR 1 "November 16, 2017" "TAR" "GNU TAR Manual"
 .SH NAME
 .SH NAME
 tar \- an archiving utility
 tar \- an archiving utility
 .SH SYNOPSIS
 .SH SYNOPSIS
@@ -1163,6 +1163,12 @@ Keywords applicable for \fBtar --create\fR:
 .TP
 .TP
 .B file-changed
 .B file-changed
 "%s: file changed as we read it"
 "%s: file changed as we read it"
+.TP
+.B failed-read
+Suppresses warnings about unreadable files or directories. This
+keyword applies only if used together with the
+.B \-\-ignore\-failed\-read
+option.
 .HP
 .HP
 Keywords applicable for \fBtar --extract\fR:
 Keywords applicable for \fBtar --extract\fR:
 .TP
 .TP

+ 12 - 1
doc/tar.texi

@@ -4610,6 +4610,10 @@ Disable all warning messages.
 @cindex @samp{file changed as we read it}, warning message
 @cindex @samp{file changed as we read it}, warning message
 @item file-changed
 @item file-changed
 @samp{%s: file changed as we read it}
 @samp{%s: file changed as we read it}
+@item failed-read
+Suppresses warnings about unreadable files or directories. This
+keyword applies only if used together with the @option{--ignore-failed-read}
+option. @xref{Ignore Failed Read}.
 @end table
 @end table
 
 
 @subheading Keywords applicable for @command{tar --extract}
 @subheading Keywords applicable for @command{tar --extract}
@@ -5726,7 +5730,7 @@ Disable SELinux context support.
 @end table
 @end table
 
 
 @node Ignore Failed Read
 @node Ignore Failed Read
-@subsection Ignore Fail Read
+@subsection Ignore Failed Read
 
 
 @table @option
 @table @option
 @item --ignore-failed-read
 @item --ignore-failed-read
@@ -5734,6 +5738,13 @@ Disable SELinux context support.
 Do not exit with nonzero on unreadable files or directories.
 Do not exit with nonzero on unreadable files or directories.
 @end table
 @end table
 
 
+This option has effect only during creation.  It instructs tar to
+treat as mild conditions any missing or unreadable files (directories).
+Such failures don't affect the program exit code, and the
+corresponding diagnostic messages are marked as warnings, not errors.
+These warnings can be suppressed using the
+@option{--warning=failed-read} option (@pxref{warnings}).
+
 @node extract options
 @node extract options
 @section Options Used by @option{--extract}
 @section Options Used by @option{--extract}
 @cindex options for use with @option{--extract}
 @cindex options for use with @option{--extract}

+ 4 - 1
src/common.h

@@ -927,6 +927,7 @@ void checkpoint_flush_actions (void);
 #define WARN_EXISTING_FILE       0x00100000
 #define WARN_EXISTING_FILE       0x00100000
 #define WARN_XATTR_WRITE         0x00200000
 #define WARN_XATTR_WRITE         0x00200000
 #define WARN_RECORD_SIZE         0x00400000
 #define WARN_RECORD_SIZE         0x00400000
+#define WARN_FAILED_READ         0x00800000
 
 
 /* These warnings are enabled by default in verbose mode: */
 /* These warnings are enabled by default in verbose mode: */
 #define WARN_VERBOSE_WARNINGS    (WARN_RENAME_DIRECTORY|WARN_NEW_DIRECTORY|\
 #define WARN_VERBOSE_WARNINGS    (WARN_RENAME_DIRECTORY|WARN_NEW_DIRECTORY|\
@@ -938,10 +939,12 @@ void set_warning_option (const char *arg);
 
 
 extern int warning_option;
 extern int warning_option;
 
 
+#define WARNING_ENABLED(opt) (warning_option & (opt))
+
 #define WARNOPT(opt,args)			\
 #define WARNOPT(opt,args)			\
   do						\
   do						\
     {						\
     {						\
-      if (warning_option & opt) WARN (args);	\
+      if (WARNING_ENABLED(opt)) WARN (args);	\
     }						\
     }						\
   while (0)
   while (0)
 
 

+ 28 - 7
src/misc.c

@@ -1044,7 +1044,10 @@ void
 close_diag (char const *name)
 close_diag (char const *name)
 {
 {
   if (ignore_failed_read_option)
   if (ignore_failed_read_option)
-    close_warn (name);
+    {
+      if (WARNING_ENABLED(WARN_FAILED_READ))
+	close_warn (name);
+    }
   else
   else
     close_error (name);
     close_error (name);
 }
 }
@@ -1053,7 +1056,10 @@ void
 open_diag (char const *name)
 open_diag (char const *name)
 {
 {
   if (ignore_failed_read_option)
   if (ignore_failed_read_option)
-    open_warn (name);
+    {
+      if (WARNING_ENABLED(WARN_FAILED_READ))
+	open_warn (name);
+    }
   else
   else
     open_error (name);
     open_error (name);
 }
 }
@@ -1062,7 +1068,10 @@ void
 read_diag_details (char const *name, off_t offset, size_t size)
 read_diag_details (char const *name, off_t offset, size_t size)
 {
 {
   if (ignore_failed_read_option)
   if (ignore_failed_read_option)
-    read_warn_details (name, offset, size);
+    {
+      if (WARNING_ENABLED(WARN_FAILED_READ))
+	read_warn_details (name, offset, size);
+    }
   else
   else
     read_error_details (name, offset, size);
     read_error_details (name, offset, size);
 }
 }
@@ -1071,7 +1080,10 @@ void
 readlink_diag (char const *name)
 readlink_diag (char const *name)
 {
 {
   if (ignore_failed_read_option)
   if (ignore_failed_read_option)
-    readlink_warn (name);
+    {
+      if (WARNING_ENABLED(WARN_FAILED_READ))
+	readlink_warn (name);
+    }
   else
   else
     readlink_error (name);
     readlink_error (name);
 }
 }
@@ -1080,7 +1092,10 @@ void
 savedir_diag (char const *name)
 savedir_diag (char const *name)
 {
 {
   if (ignore_failed_read_option)
   if (ignore_failed_read_option)
-    savedir_warn (name);
+    {
+      if (WARNING_ENABLED(WARN_FAILED_READ))
+	savedir_warn (name);
+    }
   else
   else
     savedir_error (name);
     savedir_error (name);
 }
 }
@@ -1089,7 +1104,10 @@ void
 seek_diag_details (char const *name, off_t offset)
 seek_diag_details (char const *name, off_t offset)
 {
 {
   if (ignore_failed_read_option)
   if (ignore_failed_read_option)
-    seek_warn_details (name, offset);
+    {
+      if (WARNING_ENABLED(WARN_FAILED_READ))
+	seek_warn_details (name, offset);
+    }
   else
   else
     seek_error_details (name, offset);
     seek_error_details (name, offset);
 }
 }
@@ -1098,7 +1116,10 @@ void
 stat_diag (char const *name)
 stat_diag (char const *name)
 {
 {
   if (ignore_failed_read_option)
   if (ignore_failed_read_option)
-    stat_warn (name);
+    {
+      if (WARNING_ENABLED(WARN_FAILED_READ))
+	stat_warn (name);
+    }
   else
   else
     stat_error (name);
     stat_error (name);
 }
 }

+ 3 - 1
src/warning.c

@@ -47,6 +47,7 @@ static char const *const warning_args[] = {
   "existing-file",
   "existing-file",
   "xattr-write",
   "xattr-write",
   "record-size",
   "record-size",
+  "failed-read",
   NULL
   NULL
 };
 };
 
 
@@ -74,7 +75,8 @@ static int warning_types[] = {
   WARN_DECOMPRESS_PROGRAM,
   WARN_DECOMPRESS_PROGRAM,
   WARN_EXISTING_FILE,
   WARN_EXISTING_FILE,
   WARN_XATTR_WRITE,
   WARN_XATTR_WRITE,
-  WARN_RECORD_SIZE
+  WARN_RECORD_SIZE,
+  WARN_FAILED_READ
 };
 };
 
 
 ARGMATCH_VERIFY (warning_args, warning_types);
 ARGMATCH_VERIFY (warning_args, warning_types);