]> arthur.barton.de Git - bup.git/commitdiff
fuse: convert to internal command
authorRob Browning <rlb@defaultvalue.org>
Fri, 12 Feb 2021 21:57:38 +0000 (15:57 -0600)
committerRob Browning <rlb@defaultvalue.org>
Sat, 6 Mar 2021 18:29:39 +0000 (12:29 -0600)
Signed-off-by: Rob Browning <rlb@defaultvalue.org>
lib/bup/cmd/fuse.py
lib/cmd/bup

index 38e64afef311a03f2d18afe3a0c142a524479717..96bf6179ebe4800b05a8558d69011ca8b8a8386d 100755 (executable)
@@ -1,26 +1,6 @@
-#!/bin/sh
-"""": # -*-python-*-
-# https://sourceware.org/bugzilla/show_bug.cgi?id=26034
-export "BUP_ARGV_0"="$0"
-arg_i=1
-for arg in "$@"; do
-    export "BUP_ARGV_${arg_i}"="$arg"
-    shift
-    arg_i=$((arg_i + 1))
-done
-# Here to end of preamble replaced during install
-bup_python="$(dirname "$0")/../../../config/bin/python" || exit $?
-exec "$bup_python" "$0"
-"""
-# end of bup preamble
 
 from __future__ import absolute_import, print_function
-
-# Intentionally replace the dirname "$0" that python prepends
-import os, sys
-sys.path[0] = os.path.dirname(os.path.realpath(__file__)) + '/../..'
-
-import errno
+import errno, os, sys
 
 try:
     import fuse
@@ -46,7 +26,7 @@ if sys.version_info[0] > 2:
               file=sys.stderr)
         sys.exit(2)
 
-from bup import compat, options, git, vfs, xstat
+from bup import options, git, vfs, xstat
 from bup.compat import argv_bytes, fsdecode, py_maj
 from bup.helpers import log
 from bup.repo import LocalRepo
@@ -66,7 +46,6 @@ class BupFs(fuse.Fuse):
     
     def getattr(self, path):
         path = argv_bytes(path)
-        global opt
         if self.verbose > 0:
             log('--getattr(%r)\n' % path)
         res = vfs.resolve(self.repo, path, want_meta=(not self.fake_metadata),
@@ -99,7 +78,7 @@ class BupFs(fuse.Fuse):
             yield -errno.ENOENT
         yield fuse.Direntry('..')
         # FIXME: make sure want_meta=False is being completely respected
-        for ent_name, ent_item in vfs.contents(repo, dir_item, want_meta=False):
+        for ent_name, ent_item in vfs.contents(self.repo, dir_item, want_meta=False):
             fusename = fsdecode(ent_name.replace(b'/', b'-'))
             yield fuse.Direntry(fusename)
 
@@ -111,7 +90,7 @@ class BupFs(fuse.Fuse):
         name, item = res[-1]
         if not item:
             return -errno.ENOENT
-        return fsdecode(vfs.readlink(repo, item))
+        return fsdecode(vfs.readlink(self.repo, item))
 
     def open(self, path, flags):
         path = argv_bytes(path)
@@ -136,7 +115,7 @@ class BupFs(fuse.Fuse):
         name, item = res[-1]
         if not item:
             return -errno.ENOENT
-        with vfs.fopen(repo, item) as f:
+        with vfs.fopen(self.repo, item) as f:
             f.seek(offset)
             return f.read(size)
 
@@ -150,32 +129,34 @@ 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(compat.argv[1:])
-if not opt.verbose:
-    opt.verbose = 0
-
-# Set stderr to be line buffered, even if it's not connected to the console
-# so that we'll be able to see diagnostics in a timely fashion.
-errfd = sys.stderr.fileno()
-sys.stderr.flush()
-sys.stderr = os.fdopen(errfd, 'w', 1)
-
-if len(extra) != 1:
-    o.fatal('only one mount point argument expected')
-
-git.check_repo_or_die()
-repo = LocalRepo()
-f = BupFs(repo=repo, verbose=opt.verbose, fake_metadata=(not opt.meta))
-
-# This is likely wrong, but the fuse module doesn't currently accept bytes
-f.fuse_args.mountpoint = extra[0]
-
-if opt.debug:
-    f.fuse_args.add('debug')
-if opt.foreground:
-    f.fuse_args.setmod('foreground')
-f.multithreaded = False
-if opt.allow_other:
-    f.fuse_args.add('allow_other')
-f.main()
+
+def main(argv):
+    o = options.Options(optspec)
+    opt, flags, extra = o.parse_bytes(argv[1:])
+    if not opt.verbose:
+        opt.verbose = 0
+
+    # Set stderr to be line buffered, even if it's not connected to the console
+    # so that we'll be able to see diagnostics in a timely fashion.
+    errfd = sys.stderr.fileno()
+    sys.stderr.flush()
+    sys.stderr = os.fdopen(errfd, 'w', 1)
+
+    if len(extra) != 1:
+        o.fatal('only one mount point argument expected')
+
+    git.check_repo_or_die()
+    repo = LocalRepo()
+    f = BupFs(repo=repo, verbose=opt.verbose, fake_metadata=(not opt.meta))
+
+    # This is likely wrong, but the fuse module doesn't currently accept bytes
+    f.fuse_args.mountpoint = extra[0]
+
+    if opt.debug:
+        f.fuse_args.add('debug')
+    if opt.foreground:
+        f.fuse_args.setmod('foreground')
+    f.multithreaded = False
+    if opt.allow_other:
+        f.fuse_args.add('allow_other')
+    f.main()
index 759d10c20aafc07c11c2523e7fe3cd54bb97171c..e474b341c899e4087b6d794170fb79812ee21308 100755 (executable)
@@ -193,6 +193,7 @@ try:
                            b'features',
                            b'ftp',
                            b'fsck',
+                           b'fuse',
                            b'gc',
                            b'get',
                            b'help',