bug-tar
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Bug-tar] tar with -k option no longer warns when not overwriting fi


From: Sergey Poznyakoff
Subject: Re: [Bug-tar] tar with -k option no longer warns when not overwriting files
Date: Thu, 17 Nov 2011 11:24:21 +0200

Hi Doug,

> I would propose that if a file is not put down due to it already
> existing and the -k / --keep-old-files flag being given, that a
> warning should be thrown.

Perhaps it makes sense, but I'm not sure it should be enabled by
default.  The attached patch implements a new --warning category
"existing-file", which enables this warning.  With this patch applied,
you get the following behavior:

# One -v option: no changes
$ tar -kxvf foo.tar 
foo
# Two -v options enable verbose warnings:
$ tar -kxvvf foo.tar
-rw-r--r-- dougmc/local      0 2011-11-16 22:43 foo
tar: foo: skipping existing file
# Explicit --warning does its job too:
$ tar --warning=existing-file -kxf foo.tar
tar: foo: skipping existing file
# Explicit --warning with -v:
$ tar --warning=existing-file -kxvf foo.tar
foo
tar: foo: skipping existing file

It's only a proposal, I did not apply that patch to the master yet.

Regards,
Sergey

diff --git a/src/common.h b/src/common.h
index c29ffc0..f03d647 100644
--- a/src/common.h
+++ b/src/common.h
@@ -810,12 +810,15 @@ void checkpoint_run (bool do_write);
 #define WARN_UNKNOWN_KEYWORD     0x00020000
 #define WARN_XDEV                0x00040000
 #define WARN_DECOMPRESS_PROGRAM  0x00080000
+#define WARN_EXISTING_FILE       0x00100000

 /* The warnings composing WARN_VERBOSE_WARNINGS are enabled by default
    in verbose mode */
 #define WARN_VERBOSE_WARNINGS    (WARN_RENAME_DIRECTORY|WARN_NEW_DIRECTORY|\
                                  WARN_DECOMPRESS_PROGRAM)
-#define WARN_ALL                 (~WARN_VERBOSE_WARNINGS)
+/* The WARN_VERBOSE2_WARNINGS bits are enabled when verbose > 1 */
+#define WARN_VERBOSE2_WARNINGS   (WARN_EXISTING_FILE)
+#define WARN_ALL                 
(~(WARN_VERBOSE_WARNINGS|WARN_VERBOSE2_WARNINGS))

 void set_warning_option (const char *arg);

diff --git a/src/extract.c b/src/extract.c
index d24f98f..60ec747 100644
--- a/src/extract.c
+++ b/src/extract.c
@@ -643,6 +643,8 @@ maybe_recoverable (char *file_name, bool regular, bool 
*interdir_made)
       switch (old_files_option)
        {
        case KEEP_OLD_FILES:
+         WARNOPT (WARN_EXISTING_FILE,
+                  (0, 0, _("%s: skipping existing file"), file_name));
          return RECOVER_SKIP;

        case KEEP_NEWER_FILES:
diff --git a/src/tar.c b/src/tar.c
index f0d8f5b..057726b 100644
--- a/src/tar.c
+++ b/src/tar.c
@@ -1722,6 +1722,8 @@ parse_opt (int key, char *arg, struct argp_state *state)
     case 'v':
       verbose_option++;
       warning_option |= WARN_VERBOSE_WARNINGS;
+      if (verbose_option > 1)
+       warning_option |= WARN_VERBOSE2_WARNINGS;
       break;

     case 'V':
diff --git a/src/warning.c b/src/warning.c
index 5d1bcab..102364d 100644
--- a/src/warning.c
+++ b/src/warning.c
@@ -42,6 +42,7 @@ static char const *const warning_args[] = {
   "unknown-keyword",
   "xdev",
   "decompress-program",
+  "existing-file",
   NULL
 };

@@ -66,7 +67,8 @@ static int warning_types[] = {
   WARN_UNKNOWN_CAST,
   WARN_UNKNOWN_KEYWORD,
   WARN_XDEV,
-  WARN_DECOMPRESS_PROGRAM
+  WARN_DECOMPRESS_PROGRAM,
+  WARN_EXISTING_FILE
 };

 ARGMATCH_VERIFY (warning_args, warning_types);

reply via email to

[Prev in Thread] Current Thread [Next in Thread]