2 import sys, os, stat, errno, fuse, re, time, tempfile
3 from bup import options, git, vfs
4 from bup.helpers import *
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()
59 st.st_mtime = node.mtime
60 st.st_ctime = node.ctime
61 st.st_atime = node.atime
63 except vfs.NoSuchFile:
66 def readdir(self, path, offset):
67 log('--readdir(%r)\n' % path)
68 node = cache_get(self.top, path)
69 yield fuse.Direntry('.')
70 yield fuse.Direntry('..')
71 for sub in node.subs():
72 yield fuse.Direntry(sub.name)
74 def readlink(self, path):
75 log('--readlink(%r)\n' % path)
76 node = cache_get(self.top, path)
77 return node.readlink()
79 def open(self, path, flags):
80 log('--open(%r)\n' % path)
81 node = cache_get(self.top, path)
82 accmode = os.O_RDONLY | os.O_WRONLY | os.O_RDWR
83 if (flags & accmode) != os.O_RDONLY:
87 def release(self, path, flags):
88 log('--release(%r)\n' % path)
90 def read(self, path, size, offset):
91 log('--read(%r)\n' % path)
92 n = cache_get(self.top, path)
93 return n.readbytes(offset, size)
96 if not hasattr(fuse, '__version__'):
97 raise RuntimeError, "your fuse module is too old for fuse.__version__"
98 fuse.fuse_python_api = (0, 2)
102 bup fuse [-d] [-f] <mountpoint>
104 d,debug increase debug level
105 f,foreground run in foreground
107 o = options.Options('bup fuse', optspec)
108 (opt, flags, extra) = o.parse(sys.argv[1:])
111 o.fatal("exactly one argument expected")
113 git.check_repo_or_die()
114 top = vfs.RefList(None)
116 f.fuse_args.mountpoint = extra[0]
118 f.fuse_args.add('debug')
120 f.fuse_args.setmod('foreground')
121 print f.multithreaded
122 f.multithreaded = False
123 f.fuse_args.add('allow_other')