X-Git-Url: https://arthur.barton.de/gitweb/?a=blobdiff_plain;f=cmd%2Ffuse-cmd.py;h=f2776e54853c60ddc0293ce48911ba4a5b59308c;hb=ed6266d24ed5e6fd538d07e78eea2c11665e0aaf;hp=9253a18de996efbea4f58b2125a851bcd1144232;hpb=581e9dff93565d57d777ac3a2b93c09844c7263b;p=bup.git diff --git a/cmd/fuse-cmd.py b/cmd/fuse-cmd.py index 9253a18..f2776e5 100755 --- a/cmd/fuse-cmd.py +++ b/cmd/fuse-cmd.py @@ -1,12 +1,19 @@ -#!/usr/bin/env python +#!/bin/sh +"""": # -*-python-*- +bup_python="$(dirname "$0")/bup-python" || exit $? +exec "$bup_python" "$0" ${1+"$@"} +""" +# end of bup preamble + import sys, os, errno -from bup import options, git, vfs -from bup.helpers import * + +from bup import options, git, vfs, xstat +from bup.helpers import buglvl, log + try: import fuse except ImportError: - log('bup: error: The python "fuse" module is missing.\n' + - 'To use bup fuse, first install the python-fuse package.\n') + log('error: cannot find the python "fuse" module; please install it\n') sys.exit(1) @@ -33,47 +40,60 @@ def cache_get(top, path): cache[('',)] = top c = None max = len(parts) - #log('cache: %r\n' % cache.keys()) + if buglvl >= 1: + log('cache: %r\n' % cache.keys()) for i in range(max): pre = parts[:max-i] - #log('cache trying: %r\n' % pre) + if buglvl >= 1: + log('cache trying: %r\n' % pre) c = cache.get(tuple(pre)) if c: rest = parts[max-i:] for r in rest: - #log('resolving %r from %r\n' % (r, c.fullname())) + if buglvl >= 1: + log('resolving %r from %r\n' % (r, c.fullname())) c = c.lresolve(r) key = tuple(pre + [r]) - #log('saving: %r\n' % (key,)) + if buglvl >= 1: + log('saving: %r\n' % (key,)) cache[key] = c break assert(c) return c - - + class BupFs(fuse.Fuse): - def __init__(self, top): + def __init__(self, top, meta=False, verbose=0): fuse.Fuse.__init__(self) self.top = top + self.meta = meta + self.verbose = verbose def getattr(self, path): - log('--getattr(%r)\n' % path) + if self.verbose > 0: + log('--getattr(%r)\n' % path) try: node = cache_get(self.top, path) st = Stat() st.st_mode = node.mode st.st_nlink = node.nlinks() - st.st_size = node.size() - st.st_mtime = node.mtime - st.st_ctime = node.ctime - st.st_atime = node.atime + st.st_size = node.size() # Until/unless we store the size in m. + if self.meta: + m = node.metadata() + if m: + st.st_mode = m.mode + st.st_uid = m.uid + st.st_gid = m.gid + st.st_atime = max(0, xstat.fstime_floor_secs(m.atime)) + st.st_mtime = max(0, xstat.fstime_floor_secs(m.mtime)) + st.st_ctime = max(0, xstat.fstime_floor_secs(m.ctime)) return st except vfs.NoSuchFile: return -errno.ENOENT def readdir(self, path, offset): - log('--readdir(%r)\n' % path) + if self.verbose > 0: + log('--readdir(%r)\n' % path) node = cache_get(self.top, path) yield fuse.Direntry('.') yield fuse.Direntry('..') @@ -81,12 +101,14 @@ class BupFs(fuse.Fuse): yield fuse.Direntry(sub.name) def readlink(self, path): - log('--readlink(%r)\n' % path) + if self.verbose > 0: + log('--readlink(%r)\n' % path) node = cache_get(self.top, path) return node.readlink() def open(self, path, flags): - log('--open(%r)\n' % path) + if self.verbose > 0: + log('--open(%r)\n' % path) node = cache_get(self.top, path) accmode = os.O_RDONLY | os.O_WRONLY | os.O_RDWR if (flags & accmode) != os.O_RDONLY: @@ -94,10 +116,12 @@ class BupFs(fuse.Fuse): node.open() def release(self, path, flags): - log('--release(%r)\n' % path) + if self.verbose > 0: + log('--release(%r)\n' % path) def read(self, path, size, offset): - log('--read(%r)\n' % path) + if self.verbose > 0: + log('--read(%r)\n' % path) n = cache_get(self.top, path) o = n.open() o.seek(offset) @@ -112,9 +136,11 @@ fuse.fuse_python_api = (0, 2) optspec = """ bup fuse [-d] [-f] -- -d,debug increase debug level f,foreground run in foreground +d,debug run in the foreground and display FUSE debug information o,allow-other allow other users to access the filesystem +meta report original metadata for paths when available +v,verbose increase log output (can be used more than once) """ o = options.Options(optspec) (opt, flags, extra) = o.parse(sys.argv[1:]) @@ -124,7 +150,7 @@ if len(extra) != 1: git.check_repo_or_die() top = vfs.RefList(None) -f = BupFs(top) +f = BupFs(top, meta=opt.meta, verbose=opt.verbose) f.fuse_args.mountpoint = extra[0] if opt.debug: f.fuse_args.add('debug')