]> arthur.barton.de Git - bup.git/blobdiff - cmd/fuse-cmd.py
fuse-cmd.py: given --meta, report original metadata
[bup.git] / cmd / fuse-cmd.py
index 64880975d861eb71be80ce34e15a6ea8b853a718..30776cb36b0013adf0bf49de831b5768baa349f6 100755 (executable)
@@ -1,7 +1,12 @@
 #!/usr/bin/env python
-import sys, os, stat, errno, fuse, re, time, tempfile
-from bup import options, git, vfs
+import sys, os, errno
+from bup import options, git, vfs, xstat
 from bup.helpers import *
+try:
+    import fuse
+except ImportError:
+    log('error: cannot find the python "fuse" module; please install it\n')
+    sys.exit(1)
 
 
 class Stat(fuse.Stat):
@@ -47,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)
@@ -58,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
@@ -108,8 +120,10 @@ 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('bup fuse', optspec)
+o = options.Options(optspec)
 (opt, flags, extra) = o.parse(sys.argv[1:])
 
 if len(extra) != 1:
@@ -117,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')
@@ -125,6 +139,7 @@ if opt.foreground:
     f.fuse_args.setmod('foreground')
 print f.multithreaded
 f.multithreaded = False
-f.fuse_args.add('allow_other')
+if opt.allow_other:
+    f.fuse_args.add('allow_other')
 
 f.main()