3 bup_python="$(dirname "$0")/bup-python" || exit $?
4 exec "$bup_python" "$0" ${1+"$@"}
10 from bup import options, git, vfs, xstat
11 from bup.helpers import buglvl, log
16 log('error: cannot find the python "fuse" module; please install it\n')
21 def cache_get(top, path):
22 parts = path.split('/')
27 log('cache: %r\n' % cache.keys())
31 log('cache trying: %r\n' % pre)
32 c = cache.get(tuple(pre))
37 log('resolving %r from %r\n' % (r, c.fullname()))
39 key = tuple(pre + [r])
41 log('saving: %r\n' % (key,))
48 class BupFs(fuse.Fuse):
49 def __init__(self, top, meta=False, verbose=0):
50 fuse.Fuse.__init__(self)
53 self.verbose = verbose
55 def getattr(self, path):
57 log('--getattr(%r)\n' % path)
59 node = cache_get(self.top, path)
60 st = fuse.Stat(st_mode=node.mode,
61 st_nlink=node.nlinks(),
62 # Until/unless we store the size in m.
70 st.st_atime = max(0, xstat.fstime_floor_secs(m.atime))
71 st.st_mtime = max(0, xstat.fstime_floor_secs(m.mtime))
72 st.st_ctime = max(0, xstat.fstime_floor_secs(m.ctime))
74 except vfs.NoSuchFile:
77 def readdir(self, path, offset):
79 log('--readdir(%r)\n' % path)
80 node = cache_get(self.top, path)
81 yield fuse.Direntry('.')
82 yield fuse.Direntry('..')
83 for sub in node.subs():
84 yield fuse.Direntry(sub.name)
86 def readlink(self, path):
88 log('--readlink(%r)\n' % path)
89 node = cache_get(self.top, path)
90 return node.readlink()
92 def open(self, path, flags):
94 log('--open(%r)\n' % path)
95 node = cache_get(self.top, path)
96 accmode = os.O_RDONLY | os.O_WRONLY | os.O_RDWR
97 if (flags & accmode) != os.O_RDONLY:
101 def release(self, path, flags):
103 log('--release(%r)\n' % path)
105 def read(self, path, size, offset):
107 log('--read(%r)\n' % path)
108 n = cache_get(self.top, path)
114 if not hasattr(fuse, '__version__'):
115 raise RuntimeError, "your fuse module is too old for fuse.__version__"
116 fuse.fuse_python_api = (0, 2)
120 bup fuse [-d] [-f] <mountpoint>
122 f,foreground run in foreground
123 d,debug run in the foreground and display FUSE debug information
124 o,allow-other allow other users to access the filesystem
125 meta report original metadata for paths when available
126 v,verbose increase log output (can be used more than once)
128 o = options.Options(optspec)
129 (opt, flags, extra) = o.parse(sys.argv[1:])
132 o.fatal("exactly one argument expected")
134 git.check_repo_or_die()
135 top = vfs.RefList(None)
136 f = BupFs(top, meta=opt.meta, verbose=opt.verbose)
137 f.fuse_args.mountpoint = extra[0]
139 f.fuse_args.add('debug')
141 f.fuse_args.setmod('foreground')
142 print f.multithreaded
143 f.multithreaded = False
145 f.fuse_args.add('allow_other')