2 import sys, os, stat, errno, re, time, tempfile
3 from bup import options, git, vfs
4 from bup.helpers import *
8 log('bup: error: The python "fuse" module is missing.\n' +
9 'To use bup fuse, first install the python-fuse package.\n')
13 class Stat(fuse.Stat):
31 def cache_get(top, path):
32 parts = path.split('/')
36 #log('cache: %r\n' % cache.keys())
39 #log('cache trying: %r\n' % pre)
40 c = cache.get(tuple(pre))
44 #log('resolving %r from %r\n' % (r, c.fullname()))
46 key = tuple(pre + [r])
47 #log('saving: %r\n' % (key,))
55 class BupFs(fuse.Fuse):
56 def __init__(self, top):
57 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()
68 st.st_mtime = node.mtime
69 st.st_ctime = node.ctime
70 st.st_atime = node.atime
72 except vfs.NoSuchFile:
75 def readdir(self, path, offset):
76 log('--readdir(%r)\n' % path)
77 node = cache_get(self.top, path)
78 yield fuse.Direntry('.')
79 yield fuse.Direntry('..')
80 for sub in node.subs():
81 yield fuse.Direntry(sub.name)
83 def readlink(self, path):
84 log('--readlink(%r)\n' % path)
85 node = cache_get(self.top, path)
86 return node.readlink()
88 def open(self, path, flags):
89 log('--open(%r)\n' % path)
90 node = cache_get(self.top, path)
91 accmode = os.O_RDONLY | os.O_WRONLY | os.O_RDWR
92 if (flags & accmode) != os.O_RDONLY:
96 def release(self, path, flags):
97 log('--release(%r)\n' % path)
99 def read(self, path, size, offset):
100 log('--read(%r)\n' % path)
101 n = cache_get(self.top, path)
107 if not hasattr(fuse, '__version__'):
108 raise RuntimeError, "your fuse module is too old for fuse.__version__"
109 fuse.fuse_python_api = (0, 2)
113 bup fuse [-d] [-f] <mountpoint>
115 d,debug increase debug level
116 f,foreground run in foreground
117 o,allow-other allow other users to access the filesystem
119 o = options.Options('bup fuse', optspec)
120 (opt, flags, extra) = o.parse(sys.argv[1:])
123 o.fatal("exactly one argument expected")
125 git.check_repo_or_die()
126 top = vfs.RefList(None)
128 f.fuse_args.mountpoint = extra[0]
130 f.fuse_args.add('debug')
132 f.fuse_args.setmod('foreground')
133 print f.multithreaded
134 f.multithreaded = False
136 f.fuse_args.add('allow_other')