]> arthur.barton.de Git - bup.git/commitdiff
Add (private for now) "bup xstat" command and use it in the metadata tests.
authorRob Browning <rlb@defaultvalue.org>
Fri, 26 Nov 2010 23:48:58 +0000 (17:48 -0600)
committerRob Browning <rlb@defaultvalue.org>
Fri, 26 Nov 2010 23:48:58 +0000 (17:48 -0600)
Add a "bup xstat" command that relies on Metadata and prints extended
stat information for the paths provided.  Use "bup xstat" in the
top-level metadata tests so that we don't have to try to accommodate
variations in the local stat command across platforms.

Move the top-level metadata tests from t/test.sh to t/test-meta.sh so
that it's easy to run them independently.

Makefile
cmd/xstat-cmd.py [new file with mode: 0755]
t/test-meta.sh [new file with mode: 0755]
t/test.sh

index 0faf8a684ff7d4967878587bf0de56c18fa53617..a4ca3abad77d389a6fa6f4ce5e4ed3200430c5e6 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -87,6 +87,7 @@ runtests-python:
 
 runtests-cmdline: all
        t/test.sh
+       t/test-meta.sh
 
 stupid:
        PATH=/bin:/usr/bin $(MAKE) test
diff --git a/cmd/xstat-cmd.py b/cmd/xstat-cmd.py
new file mode 100755 (executable)
index 0000000..c9e3310
--- /dev/null
@@ -0,0 +1,115 @@
+#!/usr/bin/env python
+
+# Copyright (C) 2010 Rob Browning
+#
+# This code is covered under the terms of the GNU Library General
+# Public License as described in the bup LICENSE file.
+
+import posix1e
+import stat
+import sys
+from bup import metadata
+from bup import options
+from bup import xstat
+from bup.helpers import handle_ctrl_c, saved_errors
+
+optspec = """
+bup pathinfo [OPTION ...] <PATH ...>
+--
+v,verbose       increase log output (can be used more than once)
+q,quiet         don't show progress meter
+exclude-fields= exclude comma-separated fields
+include-fields= include comma-separated fields (definitive if first)
+"""
+
+target_filename = ''
+all_fields = frozenset(['path',
+                        'mode',
+                        'link-target',
+                        'rdev',
+                        'uid',
+                        'gid',
+                        'owner',
+                        'group',
+                        'atime',
+                        'mtime',
+                        'ctime',
+                        'linux-attr',
+                        'linux-xattr',
+                        'posix1e-acl'])
+active_fields = all_fields
+
+handle_ctrl_c()
+
+o = options.Options('bup pathinfo', optspec)
+(opt, flags, remainder) = o.parse(sys.argv[1:])
+
+treat_include_fields_as_definitive = True
+for flag, value in flags:
+    if flag == '--verbose' or flag == '-v':
+        metadata.verbose += 1
+    elif flag == '--quiet' or flag == '-q':
+        metadata.verbose = 0
+    elif flag == '--exclude-fields':
+        exclude_fields = frozenset(value.split(','))
+        for f in exclude_fields:
+            if not f in all_fields:
+                o.fatal(f + ' is not a valid field name')
+        active_fields = active_fields - exclude_fields
+        treat_include_fields_as_definitive = False
+    elif flag == '--include-fields':
+        include_fields = frozenset(value.split(','))
+        for f in include_fields:
+            if not f in all_fields:
+                o.fatal(f + ' is not a valid field name')
+        if treat_include_fields_as_definitive:
+            active_fields = include_fields
+            treat_include_fields_as_definitive = False
+        else:
+            active_fields = active_fields | include_fields
+
+for path in remainder:
+    m = metadata.from_path(path, archive_path = path)
+    if 'path' in active_fields:
+        print 'path:', m.path
+    if 'mode' in active_fields:
+        print 'mode:', hex(m.mode)
+    if 'link-target' in active_fields and stat.S_ISLNK(m.mode):
+        print 'link-target:', m.symlink_target
+    if 'rdev' in active_fields:
+        print 'rdev:', m.rdev
+    if 'uid' in active_fields:
+        print 'uid:', m.uid
+    if 'gid' in active_fields:
+        print 'gid:', m.gid
+    if 'owner' in active_fields:
+        print 'owner:', m.owner
+    if 'group' in active_fields:
+        print 'group:', m.group
+    if 'atime' in active_fields:
+        print 'atime: ' + '%d.%09d' % m.atime.secs_nsecs()
+    if 'mtime' in active_fields:
+        print 'mtime: ' + '%d.%09d' % m.mtime.secs_nsecs()
+    if 'ctime' in active_fields:
+        print 'ctime: ' + '%d.%09d' % m.ctime.secs_nsecs()
+    if 'linux-attr' in active_fields and m.linux_attr:
+        print 'linux-attr:', hex(m.linux_attr)
+    if 'linux-xattr' in active_fields and m.linux_xattr:
+        for name, value in m.linux_xattr:
+            print 'linux-xattr: %s -> %s' % (name, repr(value))
+    if 'posix1e-acl' in active_fields and m.posix1e_acl:
+        flags = posix1e.TEXT_ABBREVIATE
+        if stat.S_ISDIR(m.mode):
+            acl = m.posix1e_acl[0]
+            default_acl = m.posix1e_acl[2]
+            print acl.to_any_text('posix1e-acl: ', '\n', flags)
+            print acl.to_any_text('posix1e-acl-default: ', '\n', flags)
+        else:
+            acl = m.posix1e_acl[0]
+            print acl.to_any_text('posix1e-acl: ', '\n', flags)
+
+if saved_errors:
+    log('WARNING: %d errors encountered.\n' % len(saved_errors))
+    sys.exit(1)
+else:
+    sys.exit(0)
diff --git a/t/test-meta.sh b/t/test-meta.sh
new file mode 100755 (executable)
index 0000000..ed1bc51
--- /dev/null
@@ -0,0 +1,58 @@
+#!/usr/bin/env bash
+. wvtest.sh
+#set -e
+
+TOP="$(pwd)"
+export BUP_DIR="$TOP/buptest.tmp"
+
+bup()
+{
+    "$TOP/bup" "$@"
+}
+
+# Very simple metadata tests -- "make install" to a temp directory,
+# then check that bup meta can reproduce the metadata correctly
+# (according to coreutils stat) via create, extract, start-extract,
+# and finish-extract.  The current tests are crude, and this does not
+# test devices, varying users/groups, acls, attrs, etc.
+WVSTART "meta"
+
+genstat()
+{
+  (
+    export PATH="${TOP}:${PATH}" # pick up bup
+    find . | sort | xargs bup xstat --exclude-fields ctime
+  )
+}
+
+# Create a test tree and collect its info via stat(1).
+(
+  set -e
+  rm -rf "${TOP}/bupmeta.tmp"
+  mkdir -p "${TOP}/bupmeta.tmp"
+  make DESTDIR="${TOP}/bupmeta.tmp/src" install
+  mkdir "${TOP}/bupmeta.tmp/src/misc"
+  cp -a cmd/bup-* "${TOP}/bupmeta.tmp/src/misc/"
+  cd "${TOP}/bupmeta.tmp/src"
+  WVPASS genstat >../src-stat
+) || WVFAIL
+
+# Use the test tree to check bup meta.
+(
+  WVPASS cd "${TOP}/bupmeta.tmp"
+  WVPASS bup meta --create --recurse --file src.meta src
+  WVPASS mkdir src-restore
+  WVPASS cd src-restore
+  WVPASS bup meta --extract --file ../src.meta
+  WVPASS test -d src
+  (cd src && genstat >../../src-restore-stat) || WVFAIL
+  WVPASS diff -u5 ../src-stat ../src-restore-stat
+  WVPASS rm -rf src
+  WVPASS bup meta --start-extract --file ../src.meta
+  WVPASS test -d src
+  WVPASS bup meta --finish-extract --file ../src.meta
+  (cd src && genstat >../../src-restore-stat) || WVFAIL
+  WVPASS diff -u5 ../src-stat ../src-restore-stat
+)
+
+exit 0
index 4648b9dfd0e4a2a89606201ed70c2fa4d5ddecbd..c833532104eb51c2df71f33a0921e48fe54b6a3c 100755 (executable)
--- a/t/test.sh
+++ b/t/test.sh
@@ -220,52 +220,4 @@ else
     WVFAIL bup fsck --quick -r # still fails because par2 was missing
 fi
 
-# Very simple metadata tests -- "make install" to a temp directory,
-# then check that bup meta can reproduce the metadata correctly
-# (according to coreutils stat) via create, extract, build-tree, and
-# settle-up.  The current use of stat is crude, and this does not test
-# devices, varying users/groups, acls, attrs, etc.
-WVSTART "meta"
-
-genstat()
-{
-    find . |
-      sort |
-      xargs stat |
-      sed -e 's/Inode: [0-9]\+ *//' \
-         -e '/^ \+Size: /d' \
-         -e '/^Change: /d' \
-         -e '/^Access: [0-9]/d'
-}
-
-# Create a test tree and collect its info via stat(1).
-(
-  set -e
-  rm -rf "${TOP}/bupmeta.tmp"
-  mkdir -p "${TOP}/bupmeta.tmp"
-  make DESTDIR="${TOP}/bupmeta.tmp/src" install
-  mkdir "${TOP}/bupmeta.tmp/src/misc"
-  cp -a cmd/bup-* "${TOP}/bupmeta.tmp/src/misc/"
-  cd "${TOP}/bupmeta.tmp/src"
-  WVPASS genstat >../src-stat
-) || WVFAIL
-
-# Use the test tree to check bup meta.
-(
-  WVPASS cd "${TOP}/bupmeta.tmp"
-  WVPASS bup meta --create --recurse --file src.meta src
-  WVPASS mkdir src-restore
-  WVPASS cd src-restore
-  WVPASS bup meta --extract --file ../src.meta
-  WVPASS test -d src
-  (cd src && genstat >../../src-restore-stat) || WVFAIL
-  WVPASS diff -u ../src-stat ../src-restore-stat
-  WVPASS rm -rf src
-  WVPASS bup meta --start-extract --file ../src.meta
-  WVPASS test -d src
-  WVPASS bup meta --finish-extract --file ../src.meta
-  (cd src && genstat >../../src-restore-stat) || WVFAIL
-  WVPASS diff -u ../src-stat ../src-restore-stat
-)
-
 exit 0