]> arthur.barton.de Git - bup.git/commitdiff
fuse-cmd.py: given --meta, report original metadata
authorRob Browning <rlb@defaultvalue.org>
Fri, 30 May 2014 02:54:49 +0000 (21:54 -0500)
committerRob Browning <rlb@defaultvalue.org>
Thu, 5 Jun 2014 20:34:49 +0000 (15:34 -0500)
Add a new --meta option to "bup fuse", and when specified, report the
original mode, uid, gid, atime, mtime, and ctime for the mounted
paths.

Since negative timestamps cause access errors, and cause "ls -l" to
report question marks for the stat values, set a floor of 0 for all
timestamps reported to python-fuse.

Signed-off-by: Rob Browning <rlb@defaultvalue.org>
Documentation/bup-fuse.md
cmd/fuse-cmd.py
t/test-fuse.sh

index 1a9e7613f48cc69561c7624e140190ae6e848282..cc2423a9c22b5b4f6188611380ce90e3cfbe49da 100644 (file)
@@ -39,6 +39,14 @@ should unmount it with `umount`(8).
 :   permit other users to access the filesystem. Necessary for
     exporting the filesystem via Samba, for example.
 
+\--meta
+:   report some of the original metadata (when available) for the
+    mounted paths (currently the uid, gid, mode, and timestamps).
+    Without this, only generic values will be presented.  This option
+    is not yet enabled by default because it may negatively affect
+    performance, and note that any timestamps before 1970-01-01 UTC
+    (i.e. before the Unix epoch) will be presented as 1970-01-01 UTC.
+
 # EXAMPLES
     rm -rf /tmp/buptest
     mkdir /tmp/buptest
index 1621f1e527cadc95d5dbbb09cfa24fd59d82079a..30776cb36b0013adf0bf49de831b5768baa349f6 100755 (executable)
@@ -1,6 +1,6 @@
 #!/usr/bin/env python
 import sys, os, errno
-from bup import options, git, vfs
+from bup import options, git, vfs, xstat
 from bup.helpers import *
 try:
     import fuse
@@ -52,9 +52,10 @@ def cache_get(top, path):
     
 
 class BupFs(fuse.Fuse):
-    def __init__(self, top):
+    def __init__(self, top, meta=False):
         fuse.Fuse.__init__(self)
         self.top = top
+        self.meta = meta
     
     def getattr(self, path):
         log('--getattr(%r)\n' % path)
@@ -63,10 +64,16 @@ class BupFs(fuse.Fuse):
             st = Stat()
             st.st_mode = node.mode
             st.st_nlink = node.nlinks()
-            st.st_size = node.size()
-            st.st_mtime = node.mtime
-            st.st_ctime = node.ctime
-            st.st_atime = node.atime
+            st.st_size = node.size()  # Until/unless we store the size in m.
+            if self.meta:
+                m = node.metadata()
+                if m:
+                    st.st_mode = m.mode
+                    st.st_uid = m.uid
+                    st.st_gid = m.gid
+                    st.st_atime = max(0, xstat.fstime_floor_secs(m.atime))
+                    st.st_mtime = max(0, xstat.fstime_floor_secs(m.mtime))
+                    st.st_ctime = max(0, xstat.fstime_floor_secs(m.ctime))
             return st
         except vfs.NoSuchFile:
             return -errno.ENOENT
@@ -114,6 +121,7 @@ bup fuse [-d] [-f] <mountpoint>
 d,debug   increase debug level
 f,foreground  run in foreground
 o,allow-other allow other users to access the filesystem
+meta          report original metadata for paths when available
 """
 o = options.Options(optspec)
 (opt, flags, extra) = o.parse(sys.argv[1:])
@@ -123,7 +131,7 @@ if len(extra) != 1:
 
 git.check_repo_or_die()
 top = vfs.RefList(None)
-f = BupFs(top)
+f = BupFs(top, meta=opt.meta)
 f.fuse_args.mountpoint = extra[0]
 if opt.debug:
     f.fuse_args.add('debug')
index 33567f9126fc4290c06db179b821f20871451336..d3d78b744e9be6e4298df8cbf6e82dca02a40fef 100755 (executable)
@@ -31,6 +31,13 @@ savename2="$(printf '%(%Y-%m-%d-%H%M%S)T' "$savestamp2")" || exit $?
 
 WVPASS mkdir src
 WVPASS date > src/foo
+WVPASS chmod 644 src/foo
+WVPASS touch -t 201111111111 src/foo
+# FUSE, python-fuse, something, can't handle negative epoch times.
+# Use pre-epoch to make sure bup properly "bottoms out" at 0 for now.
+WVPASS date > src/pre-epoch
+WVPASS chmod 644 src/pre-epoch
+WVPASS touch -t 196907202018 src/pre-epoch
 WVPASS bup index src
 WVPASS bup save -n src -d "$savestamp1" --strip src
 
@@ -46,7 +53,8 @@ WVPASSEQ "$result" "$savename1
 latest"
 
 result=$(WVPASS ls mnt/src/latest) || exit $?
-WVPASSEQ "$result" "foo"
+WVPASSEQ "$result" "foo
+pre-epoch"
 
 # Right now we don't detect new saves.
 WVPASS bup save -n src -d "$savestamp2" --strip src
@@ -55,5 +63,16 @@ savename="$(WVPASS printf '%(%Y-%m-%d-%H%M%S)T' "$savestamp1")" || exit $?
 WVPASSEQ "$result" "$savename1
 latest"
 
+WVPASS fusermount -uz mnt
+
+WVSTART "extended metadata"
+WVPASS bup fuse --meta mnt
+result=$(WVPASS ls -l mnt/src/latest/) || exit $?
+readonly user=$(WVPASS id -un) || $?
+readonly group=$(WVPASS id -gn) || $?
+WVPASSEQ "$result" "total 0
+-rw-r--r-- 1 $user $group 29 Nov 11  2011 foo
+-rw-r--r-- 1 $user $group 29 Dec 31  1969 pre-epoch"
+
 WVPASS fusermount -uz mnt
 WVPASS rm -rf "$tmpdir"