]> 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 ffcd036ffffd275ebfd73aad7b30f8d448d6cf39..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):
@@ -16,6 +21,9 @@ class Stat(fuse.Stat):
         self.st_atime = 0
         self.st_mtime = 0
         self.st_ctime = 0
+        self.st_blocks = 0
+        self.st_blksize = 0
+        self.st_rdev = 0
 
 
 cache = {}
@@ -44,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)
@@ -55,7 +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_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
@@ -87,7 +105,9 @@ class BupFs(fuse.Fuse):
     def read(self, path, size, offset):
         log('--read(%r)\n' % path)
         n = cache_get(self.top, path)
-        return n.readbytes(offset, size)
+        o = n.open()
+        o.seek(offset)
+        return o.read(size)
 
 
 if not hasattr(fuse, '__version__'):
@@ -100,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:
@@ -109,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')
@@ -117,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()