3 bup_python="$(dirname "$0")/bup-python" || exit $?
4 exec "$bup_python" "$0" ${1+"$@"}
8 from bup import options, git, vfs, xstat
9 from bup.helpers import *
13 log('error: cannot find the python "fuse" module; please install it\n')
17 class Stat(fuse.Stat):
35 def cache_get(top, path):
36 parts = path.split('/')
40 #log('cache: %r\n' % cache.keys())
43 #log('cache trying: %r\n' % pre)
44 c = cache.get(tuple(pre))
48 #log('resolving %r from %r\n' % (r, c.fullname()))
50 key = tuple(pre + [r])
51 #log('saving: %r\n' % (key,))
59 class BupFs(fuse.Fuse):
60 def __init__(self, top, meta=False):
61 fuse.Fuse.__init__(self)
65 def getattr(self, path):
66 log('--getattr(%r)\n' % path)
68 node = cache_get(self.top, path)
70 st.st_mode = node.mode
71 st.st_nlink = node.nlinks()
72 st.st_size = node.size() # Until/unless we store the size in m.
79 st.st_atime = max(0, xstat.fstime_floor_secs(m.atime))
80 st.st_mtime = max(0, xstat.fstime_floor_secs(m.mtime))
81 st.st_ctime = max(0, xstat.fstime_floor_secs(m.ctime))
83 except vfs.NoSuchFile:
86 def readdir(self, path, offset):
87 log('--readdir(%r)\n' % path)
88 node = cache_get(self.top, path)
89 yield fuse.Direntry('.')
90 yield fuse.Direntry('..')
91 for sub in node.subs():
92 yield fuse.Direntry(sub.name)
94 def readlink(self, path):
95 log('--readlink(%r)\n' % path)
96 node = cache_get(self.top, path)
97 return node.readlink()
99 def open(self, path, flags):
100 log('--open(%r)\n' % path)
101 node = cache_get(self.top, path)
102 accmode = os.O_RDONLY | os.O_WRONLY | os.O_RDWR
103 if (flags & accmode) != os.O_RDONLY:
107 def release(self, path, flags):
108 log('--release(%r)\n' % path)
110 def read(self, path, size, offset):
111 log('--read(%r)\n' % path)
112 n = cache_get(self.top, path)
118 if not hasattr(fuse, '__version__'):
119 raise RuntimeError, "your fuse module is too old for fuse.__version__"
120 fuse.fuse_python_api = (0, 2)
124 bup fuse [-d] [-f] <mountpoint>
126 d,debug increase debug level
127 f,foreground run in foreground
128 o,allow-other allow other users to access the filesystem
129 meta report original metadata for paths when available
131 o = options.Options(optspec)
132 (opt, flags, extra) = o.parse(sys.argv[1:])
135 o.fatal("exactly one argument expected")
137 git.check_repo_or_die()
138 top = vfs.RefList(None)
139 f = BupFs(top, meta=opt.meta)
140 f.fuse_args.mountpoint = extra[0]
142 f.fuse_args.add('debug')
144 f.fuse_args.setmod('foreground')
145 print f.multithreaded
146 f.multithreaded = False
148 f.fuse_args.add('allow_other')