]> arthur.barton.de Git - bup.git/commitdiff
Add atime tests and fix atime capture in metadata.from_path().
authorRob Browning <rlb@defaultvalue.org>
Wed, 26 Jan 2011 03:04:39 +0000 (21:04 -0600)
committerRob Browning <rlb@defaultvalue.org>
Wed, 26 Jan 2011 03:04:39 +0000 (21:04 -0600)
Adjust metadata.from_path() to accept an optional statinfo argument.
This allows us to pass in the value returned by recursive_dirlist()
during a save_tree().  Otherwise the second lstat(), in from_path(),
will receive an incorrect atime, one which has been adjusted by the
recursive_dirlist() stat().  Of course, this also allows us to drop an
unnecessary lstat() call.

Signed-off-by: Rob Browning <rlb@defaultvalue.org>
lib/bup/metadata.py
t/test-meta.sh

index 24f1c476b609e04fcd3c28e9617b8012904eb38a..bb16892b6fa499fb46f41c906b79ee13e44adb88 100644 (file)
@@ -544,10 +544,10 @@ class Metadata:
             add_error(e)
 
 
-def from_path(path, archive_path=None, save_symlinks=True):
+def from_path(path, statinfo=None, archive_path=None, save_symlinks=True):
     result = Metadata()
     result.path = archive_path
-    st = lstat(path)
+    st = statinfo if statinfo else lstat(path)
     result._add_common(path, st)
     if(save_symlinks):
         result._add_symlink_target(path, st)
@@ -575,7 +575,7 @@ def save_tree(output_file, paths,
             dirlist_dir = os.getcwd()
             os.chdir(start_dir)
             safe_path = _clean_up_path_for_archive(p)
-            m = from_path(p, archive_path=safe_path,
+            m = from_path(p, statinfo=st, archive_path=safe_path,
                           save_symlinks=save_symlinks)
             if verbose:
                 print >> sys.stderr, m.path
index 600dc12eb5b024b16262cc1f973cfee154306808..4fdd1f9b16db384d38e3ae615c02f296a34ee41a 100755 (executable)
@@ -116,6 +116,36 @@ then
     cp -a src testfs/src
     (cd testfs && test-src-create-extract)
 
+    WVSTART 'meta - atime'
+    force-delete testfs/src
+    mkdir testfs/src
+    (
+      mkdir testfs/src/foo
+      touch testfs/src/bar
+      PYTHONPATH="${TOP}/lib" \
+        python -c "from bup.xstat import lutime, FSTime; \
+                   x = FSTime.from_secs(42);\
+                   lutime('testfs/src/foo', (x, x));\
+                   lutime('testfs/src/bar', (x, x));"
+      cd testfs
+      WVPASS bup meta -v --create --recurse --file src.meta src
+      bup meta -tvf src.meta
+      # Test extract.
+      force-delete src-restore
+      mkdir src-restore
+      cd src-restore
+      WVPASS bup meta --extract --file ../src.meta
+      WVPASSEQ "$(bup xstat --include-fields=atime src/foo)" "atime: 42"
+      WVPASSEQ "$(bup xstat --include-fields=atime src/bar)" "atime: 42"
+      # Test start/finish extract.
+      force-delete src
+      WVPASS bup meta --start-extract --file ../src.meta
+      WVPASS test -d src
+      WVPASS bup meta --finish-extract --file ../src.meta
+      WVPASSEQ "$(bup xstat --include-fields=atime src/foo)" "atime: 42"
+      WVPASSEQ "$(bup xstat --include-fields=atime src/bar)" "atime: 42"
+    )
+
     WVSTART 'meta - Linux attr (as root)'
     force-delete testfs/src
     mkdir testfs/src