From ed6266d24ed5e6fd538d07e78eea2c11665e0aaf Mon Sep 17 00:00:00 2001 From: Rob Browning Date: Sun, 28 Feb 2016 10:14:46 -0600 Subject: [PATCH] fuse: add --verbose argument and use it Signed-off-by: Rob Browning Tested-by: Rob Browning --- Documentation/bup-fuse.md | 3 +++ cmd/fuse-cmd.py | 43 ++++++++++++++++++++++++--------------- 2 files changed, 30 insertions(+), 16 deletions(-) diff --git a/Documentation/bup-fuse.md b/Documentation/bup-fuse.md index cc2423a..ed6f5b8 100644 --- a/Documentation/bup-fuse.md +++ b/Documentation/bup-fuse.md @@ -47,6 +47,9 @@ should unmount it with `umount`(8). performance, and note that any timestamps before 1970-01-01 UTC (i.e. before the Unix epoch) will be presented as 1970-01-01 UTC. +-v, \--verbose +: increase verbosity (can be used more than once). + # EXAMPLES rm -rf /tmp/buptest mkdir /tmp/buptest diff --git a/cmd/fuse-cmd.py b/cmd/fuse-cmd.py index df9bf56..f2776e5 100755 --- a/cmd/fuse-cmd.py +++ b/cmd/fuse-cmd.py @@ -8,7 +8,7 @@ exec "$bup_python" "$0" ${1+"$@"} import sys, os, errno from bup import options, git, vfs, xstat -from bup.helpers import log +from bup.helpers import buglvl, log try: import fuse @@ -40,33 +40,38 @@ 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, meta=False): + 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() @@ -87,7 +92,8 @@ class BupFs(fuse.Fuse): 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('..') @@ -95,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: @@ -108,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) @@ -126,10 +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:]) @@ -139,7 +150,7 @@ if len(extra) != 1: git.check_repo_or_die() top = vfs.RefList(None) -f = BupFs(top, meta=opt.meta) +f = BupFs(top, meta=opt.meta, verbose=opt.verbose) f.fuse_args.mountpoint = extra[0] if opt.debug: f.fuse_args.add('debug') -- 2.39.2