2 import sys, os, stat, errno, fuse, re, time, tempfile
3 import options, git, vfs
22 def cache_get(top, path):
23 parts = path.split('/')
27 #log('cache: %r\n' % cache.keys())
30 #log('cache trying: %r\n' % pre)
31 c = cache.get(tuple(pre))
35 #log('resolving %r from %r\n' % (r, c.fullname()))
37 key = tuple(pre + [r])
38 #log('saving: %r\n' % (key,))
46 class BupFs(fuse.Fuse):
47 def __init__(self, top):
48 fuse.Fuse.__init__(self)
51 def getattr(self, path):
52 log('--getattr(%r)\n' % path)
54 node = cache_get(self.top, path)
56 st.st_mode = node.mode
57 st.st_nlink = node.nlinks()
58 st.st_size = node.size()
60 except vfs.NoSuchFile:
63 def readdir(self, path, offset):
64 log('--readdir(%r)\n' % path)
65 node = cache_get(self.top, path)
66 yield fuse.Direntry('.')
67 yield fuse.Direntry('..')
68 for sub in node.subs():
69 yield fuse.Direntry(sub.name)
71 def readlink(self, path):
72 log('--readlink(%r)\n' % path)
73 node = cache_get(self.top, path)
74 return node.readlink()
76 def open(self, path, flags):
77 log('--open(%r)\n' % path)
78 node = cache_get(self.top, path)
79 accmode = os.O_RDONLY | os.O_WRONLY | os.O_RDWR
80 if (flags & accmode) != os.O_RDONLY:
84 def release(self, path, flags):
85 log('--release(%r)\n' % path)
87 def read(self, path, size, offset):
88 log('--read(%r)\n' % path)
89 n = cache_get(self.top, path)
90 return n.readbytes(offset, size)
93 if not hasattr(fuse, '__version__'):
94 raise RuntimeError, "your fuse module is too old for fuse.__version__"
95 fuse.fuse_python_api = (0, 2)
99 bup fuse [-d] [-f] <mountpoint>
101 d,debug increase debug level
102 f,foreground run in foreground
104 o = options.Options('bup fuse', optspec)
105 (opt, flags, extra) = o.parse(sys.argv[1:])
108 o.fatal("exactly one argument expected")
110 git.check_repo_or_die()
111 top = vfs.RefList(None)
113 f.fuse_args.mountpoint = extra[0]
115 f.fuse_args.add('debug')
117 f.fuse_args.setmod('foreground')
118 print f.multithreaded
119 f.multithreaded = False
120 f.fuse_args.add('allow_other')