3 from bup import options, git, vfs, xstat
4 from bup.helpers import *
8 log('error: cannot find the python "fuse" module; please install it\n')
12 class Stat(fuse.Stat):
30 def cache_get(top, path):
31 parts = path.split('/')
35 #log('cache: %r\n' % cache.keys())
38 #log('cache trying: %r\n' % pre)
39 c = cache.get(tuple(pre))
43 #log('resolving %r from %r\n' % (r, c.fullname()))
45 key = tuple(pre + [r])
46 #log('saving: %r\n' % (key,))
54 class BupFs(fuse.Fuse):
55 def __init__(self, top, meta=False):
56 fuse.Fuse.__init__(self)
60 def getattr(self, path):
61 log('--getattr(%r)\n' % path)
63 node = cache_get(self.top, path)
65 st.st_mode = node.mode
66 st.st_nlink = node.nlinks()
67 st.st_size = node.size() # Until/unless we store the size in m.
74 st.st_atime = max(0, xstat.fstime_floor_secs(m.atime))
75 st.st_mtime = max(0, xstat.fstime_floor_secs(m.mtime))
76 st.st_ctime = max(0, xstat.fstime_floor_secs(m.ctime))
78 except vfs.NoSuchFile:
81 def readdir(self, path, offset):
82 log('--readdir(%r)\n' % path)
83 node = cache_get(self.top, path)
84 yield fuse.Direntry('.')
85 yield fuse.Direntry('..')
86 for sub in node.subs():
87 yield fuse.Direntry(sub.name)
89 def readlink(self, path):
90 log('--readlink(%r)\n' % path)
91 node = cache_get(self.top, path)
92 return node.readlink()
94 def open(self, path, flags):
95 log('--open(%r)\n' % path)
96 node = cache_get(self.top, path)
97 accmode = os.O_RDONLY | os.O_WRONLY | os.O_RDWR
98 if (flags & accmode) != os.O_RDONLY:
102 def release(self, path, flags):
103 log('--release(%r)\n' % path)
105 def read(self, path, size, offset):
106 log('--read(%r)\n' % path)
107 n = cache_get(self.top, path)
113 if not hasattr(fuse, '__version__'):
114 raise RuntimeError, "your fuse module is too old for fuse.__version__"
115 fuse.fuse_python_api = (0, 2)
119 bup fuse [-d] [-f] <mountpoint>
121 d,debug increase debug level
122 f,foreground run in foreground
123 o,allow-other allow other users to access the filesystem
124 meta report original metadata for paths when available
126 o = options.Options(optspec)
127 (opt, flags, extra) = o.parse(sys.argv[1:])
130 o.fatal("exactly one argument expected")
132 git.check_repo_or_die()
133 top = vfs.RefList(None)
134 f = BupFs(top, meta=opt.meta)
135 f.fuse_args.mountpoint = extra[0]
137 f.fuse_args.add('debug')
139 f.fuse_args.setmod('foreground')
140 print f.multithreaded
141 f.multithreaded = False
143 f.fuse_args.add('allow_other')