From: Rob Browning Date: Fri, 30 May 2014 02:54:49 +0000 (-0500) Subject: fuse-cmd.py: given --meta, report original metadata X-Git-Tag: 0.26-rc2~10 X-Git-Url: https://arthur.barton.de/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=ceacdc2cefcd74fafe568c81b633387bbd379605;hp=1716d1816048e020cfde7ce8b08bc0c9a2264554;p=bup.git fuse-cmd.py: given --meta, report original metadata 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 --- diff --git a/Documentation/bup-fuse.md b/Documentation/bup-fuse.md index 1a9e761..cc2423a 100644 --- a/Documentation/bup-fuse.md +++ b/Documentation/bup-fuse.md @@ -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 diff --git a/cmd/fuse-cmd.py b/cmd/fuse-cmd.py index 1621f1e..30776cb 100755 --- a/cmd/fuse-cmd.py +++ b/cmd/fuse-cmd.py @@ -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] 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') diff --git a/t/test-fuse.sh b/t/test-fuse.sh index 33567f9..d3d78b7 100755 --- a/t/test-fuse.sh +++ b/t/test-fuse.sh @@ -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"