2 import sys, os, stat, errno, fuse, re, time, tempfile
3 from bup import options, git, vfs
4 from bup.helpers import *
25 def cache_get(top, path):
26 parts = path.split('/')
30 #log('cache: %r\n' % cache.keys())
33 #log('cache trying: %r\n' % pre)
34 c = cache.get(tuple(pre))
38 #log('resolving %r from %r\n' % (r, c.fullname()))
40 key = tuple(pre + [r])
41 #log('saving: %r\n' % (key,))
49 class BupFs(fuse.Fuse):
50 def __init__(self, top):
51 fuse.Fuse.__init__(self)
54 def getattr(self, path):
55 log('--getattr(%r)\n' % path)
57 node = cache_get(self.top, path)
59 st.st_mode = node.mode
60 st.st_nlink = node.nlinks()
61 st.st_size = node.size()
62 st.st_mtime = node.mtime
63 st.st_ctime = node.ctime
64 st.st_atime = node.atime
66 except vfs.NoSuchFile:
69 def readdir(self, path, offset):
70 log('--readdir(%r)\n' % path)
71 node = cache_get(self.top, path)
72 yield fuse.Direntry('.')
73 yield fuse.Direntry('..')
74 for sub in node.subs():
75 yield fuse.Direntry(sub.name)
77 def readlink(self, path):
78 log('--readlink(%r)\n' % path)
79 node = cache_get(self.top, path)
80 return node.readlink()
82 def open(self, path, flags):
83 log('--open(%r)\n' % path)
84 node = cache_get(self.top, path)
85 accmode = os.O_RDONLY | os.O_WRONLY | os.O_RDWR
86 if (flags & accmode) != os.O_RDONLY:
90 def release(self, path, flags):
91 log('--release(%r)\n' % path)
93 def read(self, path, size, offset):
94 log('--read(%r)\n' % path)
95 n = cache_get(self.top, path)
101 if not hasattr(fuse, '__version__'):
102 raise RuntimeError, "your fuse module is too old for fuse.__version__"
103 fuse.fuse_python_api = (0, 2)
107 bup fuse [-d] [-f] <mountpoint>
109 d,debug increase debug level
110 f,foreground run in foreground
112 o = options.Options('bup fuse', optspec)
113 (opt, flags, extra) = o.parse(sys.argv[1:])
116 o.fatal("exactly one argument expected")
118 git.check_repo_or_die()
119 top = vfs.RefList(None)
121 f.fuse_args.mountpoint = extra[0]
123 f.fuse_args.add('debug')
125 f.fuse_args.setmod('foreground')
126 print f.multithreaded
127 f.multithreaded = False
128 f.fuse_args.add('allow_other')