bug-tar
[Top][All Lists]
Advanced

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

[PATCH][Bug-Tar]Improvement(add --select for --diff) in TODO]


From: Xu Yibo
Subject: [PATCH][Bug-Tar]Improvement(add --select for --diff) in TODO]
Date: Wed, 12 Dec 2007 09:36:44 +0800
User-agent: Thunderbird 2.0.0.5 (Windows/20070716)

Hello everybody,

  We have carried out an improvement in TODO of tar.
We added an option (--select) to remove files that compare
successfully("compare successfully" means that there is
no differences between files in archive and files in file
system). It would be useful to use '--select' with
'--diff', '-d' or '--compare', to remove all files that
compare successfully, when verifying a backup.

Signed-off-by: Fu Kuang<address@hidden>
Signed-off-by: Xu Yibo <address@hidden>

The patch is following:

 TODO          |    8 --------
 doc/tar.texi  |   11 +++++++++++
 src/common.h  |    4 ++++
 src/compare.c |   22 ++++++++++++++++++++++
 src/tar.c     |    9 ++++++++-
 5 files changed, 45 insertions(+), 9 deletions(-)

diff -Nurp tar-1.19.orig/TODO tar-1.19/TODO
--- tar-1.19.orig/TODO  2007-06-27 08:30:32.000000000 -0400
+++ tar-1.19/TODO       2007-11-05 10:11:29.000000000 -0500
@@ -17,14 +17,6 @@ Suggestions for improving GNU tar.
 
 * Interoperate better with Joerg Schilling's star implementation.
 
-* Add an option to remove files that compare successfully.
-
-  From: Roesinger Eric <address@hidden>
-  Date: Sat, 28 Jul 2001 18:43:43 -0500
-
-  It would be useful to be able to use '--remove-files' with '--diff',
-  to remove all files that compare successfully, when verifying a backup.
-
 * Add tests for the new functonality.
 
 * Consider this:
diff -Nurp tar-1.19.orig/doc/tar.texi tar-1.19/doc/tar.texi
--- tar-1.19.orig/doc/tar.texi  2007-09-26 16:39:52.000000000 -0400
+++ tar-1.19/doc/tar.texi       2007-11-05 10:02:36.000000000 -0500
@@ -3057,6 +3057,17 @@ locations.  Usually @command{tar} determ
 the archive can be seeked or not.  This option is intended for use
 in cases when such recognition fails.
 
address@hidden
address@hidden --select
+
+Use this option with '--diff', '-d' or '--compare' to remove all
+files that compare successfully(no differences between files in
+archive and files in file system), when verifying a backup.
+
address@hidden
+$ tar --diff --select -f archive.tar.gz directory
address@hidden smallexample
+
 @opsummary{show-defaults}
 @item --show-defaults
 
diff -Nurp tar-1.19.orig/src/common.h tar-1.19/src/common.h
--- tar-1.19.orig/src/common.h  2007-09-26 16:42:26.000000000 -0400
+++ tar-1.19/src/common.h       2007-11-05 11:04:06.000000000 -0500
@@ -203,6 +203,10 @@ GLOBAL mode_t initial_umask;
 
 GLOBAL bool multi_volume_option;
 
+/* For --select option  */
+GLOBAL bool select_option;
+GLOBAL bool changed_for_select;
+
 /* Specified threshold date and time.  Files having an older time stamp
    do not get archived (also see after_date_option above).  */
 GLOBAL struct timespec newer_mtime_option;
diff -Nurp tar-1.19.orig/src/compare.c tar-1.19/src/compare.c
--- tar-1.19.orig/src/compare.c 2007-08-26 03:56:56.000000000 -0400
+++ tar-1.19/src/compare.c      2007-11-05 11:02:38.000000000 -0500
@@ -55,6 +55,9 @@ diff_init (void)
 void
 report_difference (struct tar_stat_info *st, const char *fmt, ...)
 {
+  if (select_option)
+    changed_for_select = true;
+
   if (fmt)
     {
       va_list ap;
@@ -463,6 +466,7 @@ diff_archive (void)
       print_header (&current_stat_info, -1);
     }
 
+  changed_for_select = false;
   switch (current_header->header.typeflag)
     {
     default:
@@ -513,6 +517,24 @@ diff_archive (void)
     case GNUTYPE_MULTIVOL:
       diff_multivol ();
     }
+
+  /* For tar -d --select option  */
+  if (!changed_for_select && select_option)
+    {
+      struct stat temp;
+      if (lstat (current_stat_info.file_name, &temp) < 0)
+       {
+         ERROR ((0, errno, _("lstat error: %s"),
+                 current_stat_info.file_name));
+         return;
+       }
+      if (!S_ISDIR (temp.st_mode) && remove (current_stat_info.file_name) < 0)
+       {
+         ERROR ((0, errno, _("remove %s error"),
+                 current_stat_info.file_name));
+         return;
+       }
+    }
 }
 
 void
diff -Nurp tar-1.19.orig/src/tar.c tar-1.19/src/tar.c
--- tar-1.19.orig/src/tar.c     2007-09-26 16:36:58.000000000 -0400
+++ tar-1.19/src/tar.c  2007-11-05 10:02:36.000000000 -0500
@@ -321,7 +321,8 @@ enum
   VERSION_OPTION,
   VOLNO_FILE_OPTION,
   WILDCARDS_MATCH_SLASH_OPTION,
-  WILDCARDS_OPTION
+  WILDCARDS_OPTION,
+  SELECT_OPTION
 };
 
 const char *argp_program_version = "tar (" PACKAGE_NAME ") " VERSION;
@@ -390,6 +391,8 @@ static struct argp_option options[] = {
   {NULL, 0, NULL, 0,
    N_("Operation modifiers:"), GRID },
 
+  {"select", SELECT_OPTION, 0, 0,
+   N_("flag for removing the same entries from directory"), GRID+2 },
   {"sparse", 'S', 0, 0,
    N_("handle sparse files efficiently"), GRID+1 },
   {"sparse-version", SPARSE_VERSION_OPTION, N_("MAJOR[.MINOR]"), 0,
@@ -1945,6 +1948,9 @@ parse_opt (int key, char *arg, struct ar
        sleep (1);
       break;
 
+    case SELECT_OPTION:
+      select_option = true;
+      break;
     default:
       return ARGP_ERR_UNKNOWN;
     }
@@ -2011,6 +2017,7 @@ decode_options (int argc, char **argv)
   newer_mtime_option.tv_nsec = -1;
   recursion_option = FNM_LEADING_DIR;
   unquote_option = true;
+  select_option = false;
   tar_sparse_major = 1;
   tar_sparse_minor = 0;





reply via email to

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