3 from bup import options, git, vfs
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):
56 fuse.Fuse.__init__(self)
59 def getattr(self, path):
60 log('--getattr(%r)\n' % path)
62 node = cache_get(self.top, path)
64 st.st_mode = node.mode
65 st.st_nlink = node.nlinks()
66 st.st_size = node.size()
67 st.st_mtime = node.mtime
68 st.st_ctime = node.ctime
69 st.st_atime = node.atime
71 except vfs.NoSuchFile:
74 def readdir(self, path, offset):
75 log('--readdir(%r)\n' % path)
76 node = cache_get(self.top, path)
77 yield fuse.Direntry('.')
78 yield fuse.Direntry('..')
79 for sub in node.subs():
80 yield fuse.Direntry(sub.name)
82 def readlink(self, path):
83 log('--readlink(%r)\n' % path)
84 node = cache_get(self.top, path)
85 return node.readlink()
87 def open(self, path, flags):
88 log('--open(%r)\n' % path)
89 node = cache_get(self.top, path)
90 accmode = os.O_RDONLY | os.O_WRONLY | os.O_RDWR
91 if (flags & accmode) != os.O_RDONLY:
95 def release(self, path, flags):
96 log('--release(%r)\n' % path)
98 def read(self, path, size, offset):
99 log('--read(%r)\n' % path)
100 n = cache_get(self.top, path)
106 if not hasattr(fuse, '__version__'):
107 raise RuntimeError, "your fuse module is too old for fuse.__version__"
108 fuse.fuse_python_api = (0, 2)
112 bup fuse [-d] [-f] <mountpoint>
114 d,debug increase debug level
115 f,foreground run in foreground
116 o,allow-other allow other users to access the filesystem
118 o = options.Options(optspec)
119 (opt, flags, extra) = o.parse(sys.argv[1:])
122 o.fatal("exactly one argument expected")
124 git.check_repo_or_die()
125 top = vfs.RefList(None)
127 f.fuse_args.mountpoint = extra[0]
129 f.fuse_args.add('debug')
131 f.fuse_args.setmod('foreground')
132 print f.multithreaded
133 f.multithreaded = False
135 f.fuse_args.add('allow_other')