]> arthur.barton.de Git - bup.git/blobdiff - cmd/fuse-cmd.py
Don't import * from helpers
[bup.git] / cmd / fuse-cmd.py
index 5e9809ab9db7135aea9bee41d00c5fb0f8d50029..df9bf56fa399739cf9a70c3fe6216e1197ba9448 100755 (executable)
@@ -1,12 +1,19 @@
-#!/usr/bin/env python
-import sys, os, stat, errno, re, time, tempfile
-from bup import options, git, vfs
-from bup.helpers import *
+#!/bin/sh
+"""": # -*-python-*-
+bup_python="$(dirname "$0")/bup-python" || exit $?
+exec "$bup_python" "$0" ${1+"$@"}
+"""
+# end of bup preamble
+
+import sys, os, errno
+
+from bup import options, git, vfs, xstat
+from bup.helpers import log
+
 try:
     import fuse
 except ImportError:
-    log('bup: error: The python "fuse" module is missing.\n' +
-        'To use bup fuse, first install the python-fuse package.\n')
+    log('error: cannot find the python "fuse" module; please install it\n')
     sys.exit(1)
 
 
@@ -53,9 +60,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)
@@ -64,10 +72,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
@@ -115,8 +129,9 @@ 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:
@@ -124,7 +139,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')