bug-tar
[Top][All Lists]
Advanced

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

[Bug-tar] Improvement to --compare for directories in incremental archiv


From: Martin Simmons
Subject: [Bug-tar] Improvement to --compare for directories in incremental archives in 1.13.92
Date: Fri, 2 Jan 2004 22:53:48 +0000 (GMT)

Here is a patch to improve process_dumpdir by explicitly comparing each file
name and type, ignoring whether it is in the archive.  This allows incremental
archives to be compared without seeing spurious differences (I use this for
backups).


Test case (final tar should produce no output):

rm -rf /tmp/tartest
mkdir -p /tmp/tartest/data
touch /tmp/tartest/data/file1
touch /tmp/tartest/data/file2
sleep 1
tar -c -f /tmp/tartest/data.tar --listed-incremental=/tmp/tartest/data.incr 
/tmp/tartest/data
touch /tmp/tartest/data/file2
touch /tmp/tartest/data/file3
sleep 1
tar -c -f /tmp/tartest/data2.tar --listed-incremental=/tmp/tartest/data.incr 
/tmp/tartest/data
tar --diff -f /tmp/tartest/data2.tar --directory=/


Patch:

--- orig/tar-1.13.92/src/compare.c      2003-11-17 10:59:58.000000000 +0000
+++ tar-1.13.92/src/compare.c   2003-12-27 22:26:23.000000000 +0000
@@ -124,18 +124,52 @@
 /* Directory contents, only for GNUTYPE_DUMPDIR.  */
 
 static char *dumpdir_cursor;
+static int dumpdir_is_file_start;
 
 static int
 process_dumpdir (size_t bytes, char *buffer)
 {
-  if (memcmp (buffer, dumpdir_cursor, bytes))
+  while (bytes--)
     {
-      report_difference (&current_stat_info, _("Contents differ"));
-      return 0;
+      char bch = *buffer++;
+      char dch = *dumpdir_cursor++;
+
+      if (dumpdir_is_file_start)
+       {
+         switch (dch)
+           {
+           case 'D':
+             if (bch == 'D' || bch == 'N') break;
+             goto differ;
+
+           case '\0':
+             if (bch == '\0') break;
+             goto differ;
+
+           case 'Y':
+           case 'N':
+             if (bch == 'Y' || bch == 'N') break;
+             goto differ;
+
+           default:
+             goto differ;
+           }
+         dumpdir_is_file_start = 0;
+       }
+      else
+       {
+         if (bch != dch)
+           goto differ;
+         if (bch == '\0')
+           dumpdir_is_file_start = 1;
+       }
     }
 
-  dumpdir_cursor += bytes;
   return 1;
+
+ differ:
+  report_difference (&current_stat_info, _("Contents differ"));
+  return 0;
 }
 
 /* Some other routine wants SIZE bytes in the archive.  For each chunk
@@ -395,6 +429,7 @@
        if (dumpdir_buffer)
          {
            dumpdir_cursor = dumpdir_buffer;
+           dumpdir_is_file_start = 1;
            read_and_process (current_stat_info.stat.st_size, process_dumpdir);
            free (dumpdir_buffer);
          }

__Martin




reply via email to

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