Hi!

It's sometimes useful to ignore errors tar returns if a requested member
is not found in archive, while receiving other possible errors (corrupt or
absent archives, no space left on device, etc).

For example:

$ touch file
$ tar -c file | tar -t file
tar: dir: Not found in archive
tar: Exiting with failure status due to previous errors
$ echo $?
2
$

The attached patch implements a new option --ignore-missing/--no-ignore-missing
which allows the behavior wanted:

$ touch file
$ tar -c file | tar --ignore-missing -t file
$ echo $?
0
$

1. Any chances it will (can) get to future official releases?
2. Are there modifications needed for the patch to be done to be accepted to 
upstream?

-- 
Vladimir A. Pavlov
diff -Napur tar-1.27.orig/src/common.h tar-1.27/src/common.h
--- tar-1.27.orig/src/common.h	2013-10-01 22:19:42.000000000 +0400
+++ tar-1.27/src/common.h	2014-06-23 00:22:42.020075978 +0400
@@ -308,6 +308,8 @@ GLOBAL const char *volno_file_option;
 
 /* Specified value or pattern.  */
 GLOBAL const char *volume_label_option;
+
+GLOBAL bool ignore_missing_option;
 
 /* Other global variables.  */
 
diff -Napur tar-1.27.orig/src/names.c tar-1.27/src/names.c
--- tar-1.27.orig/src/names.c	2013-10-06 00:09:53.000000000 +0400
+++ tar-1.27/src/names.c	2014-06-23 00:45:43.200079940 +0400
@@ -826,12 +826,26 @@ regex_usage_warning (const char *name)
   return warned_once;
 }
 
+static inline void
+null_namelist (void)
+{
+  /* Don't bother freeing the name list; we're about to exit.  */
+  namelist = NULL;
+  nametail = NULL;
+}
+
 /* Print the names of things in the namelist that were not matched.  */
 void
 names_notfound (void)
 {
   struct name const *cursor;
 
+  if (ignore_missing_option)
+    {
+      null_namelist();
+      return;
+    }
+
   for (cursor = namelist; cursor; cursor = cursor->next)
     if (!WASFOUND (cursor) && cursor->name[0])
       {
@@ -843,9 +857,7 @@ names_notfound (void)
 		quotearg_colon (cursor->name)));
       }
 
-  /* Don't bother freeing the name list; we're about to exit.  */
-  namelist = NULL;
-  nametail = NULL;
+  null_namelist();
 
   if (same_order_option)
     {
diff -Napur tar-1.27.orig/src/tar.c tar-1.27/src/tar.c
--- tar-1.27.orig/src/tar.c	2013-10-03 23:28:03.000000000 +0400
+++ tar-1.27/src/tar.c	2014-06-23 00:37:27.950078519 +0400
@@ -285,6 +285,7 @@ enum
   IGNORE_CASE_OPTION,
   IGNORE_COMMAND_ERROR_OPTION,
   IGNORE_FAILED_READ_OPTION,
+  IGNORE_MISSING_OPTION,
   INDEX_FILE_OPTION,
   KEEP_DIRECTORY_SYMLINK_OPTION,
   KEEP_NEWER_FILES_OPTION,
@@ -302,6 +303,7 @@ enum
   NO_DELAY_DIRECTORY_RESTORE_OPTION,
   NO_IGNORE_CASE_OPTION,
   NO_IGNORE_COMMAND_ERROR_OPTION,
+  NO_IGNORE_MISSING_OPTION,
   NO_NULL_OPTION,
   NO_OVERWRITE_DIR_OPTION,
   NO_QUOTE_CHARS_OPTION,
@@ -457,6 +459,12 @@ static struct argp_option options[] = {
   {"check-device", CHECK_DEVICE_OPTION, NULL, 0,
    N_("check device numbers when creating incremental archives (default)"),
    GRID+1 },
+  {"ignore-missing", IGNORE_MISSING_OPTION, 0, 0,
+   N_("ignore requested members missing in archive"),
+   GRID+1 },
+  {"no-ignore-missing", NO_IGNORE_MISSING_OPTION, 0, 0,
+   N_("warn about requested members missing in archive (default)"),
+   GRID+1 },
 #undef GRID
 
 #define GRID 30
@@ -2087,6 +2095,14 @@ parse_opt (int key, char *arg, struct ar
       set_warning_option (arg);
       break;
 
+    case IGNORE_MISSING_OPTION:
+      ignore_missing_option = true;
+      break;
+
+    case NO_IGNORE_MISSING_OPTION:
+      ignore_missing_option = false;
+      break;
+
     case '0':
     case '1':
     case '2':

Reply via email to