]> arthur.barton.de Git - bup.git/commitdiff
ftp: honour pwd for ls
authorJohannes Berg <johannes@sipsolutions.net>
Tue, 28 Jul 2020 20:38:01 +0000 (22:38 +0200)
committerRob Browning <rlb@defaultvalue.org>
Sun, 18 Apr 2021 18:19:04 +0000 (13:19 -0500)
Honour the current working directory for 'ls' by changing
ls.within_repo() to get the pwd, and using posixpath to
build the correct path to do the ls for.

Signed-off-by: Johannes Berg <johannes@sipsolutions.net>
Reviewed-by: Rob Browning <rlb@defaultvalue.org>
lib/bup/cmd/ftp.py
lib/bup/ls.py

index 40449a652502cf8932eaeb98771229786b4cc987..0dba70ef39e8ed414686c180edfb6ece36417032 100755 (executable)
@@ -20,13 +20,14 @@ class OptionError(Exception):
     pass
 
 
-def do_ls(repo, args, out):
+def do_ls(repo, pwd, args, out):
+    pwd_str = b'/'.join(name for name, item in pwd) or b'/'
     try:
-        opt = ls.opts_from_cmdline(args, onabort=OptionError)
+        opt = ls.opts_from_cmdline(args, onabort=OptionError, pwd=pwd_str)
     except OptionError as e:
         log('error: %s' % e)
         return
-    return ls.within_repo(repo, opt, out)
+    return ls.within_repo(repo, opt, out, pwd_str)
 
 
 def write_to_file(inf, outf):
@@ -154,8 +155,7 @@ def main(argv):
         #log('execute: %r %r\n' % (cmd, parm))
         try:
             if cmd == b'ls':
-                # FIXME: respect pwd (perhaps via ls accepting resolve path/parent)
-                do_ls(repo, words[1:], out)
+                do_ls(repo, pwd, words[1:], out)
                 out.flush()
             elif cmd == b'cd':
                 np = pwd
index 9ea313352c9a4d0a618e3448947826af25dfb3e7..970995dfd7e2a5cedc961ba8e1796a9dc498470e 100644 (file)
@@ -5,6 +5,7 @@ from binascii import hexlify
 from itertools import chain
 from stat import S_ISDIR, S_ISLNK
 import copy, locale, os.path, stat, sys
+import posixpath
 
 from bup import metadata, options, vfs, xstat
 from bup.compat import argv_bytes
@@ -71,7 +72,7 @@ human-readable    print human readable file sizes (i.e. 3.9K, 4.7M)
 n,numeric-ids list numeric IDs (user, group, etc.) rather than names
 """
 
-def opts_from_cmdline(args, onabort=None):
+def opts_from_cmdline(args, onabort=None, pwd=b'/'):
     """Parse ls command line arguments and return a dictionary of ls
     options, agumented with "classification", "long_listing",
     "paths", and "show_hidden".
@@ -82,7 +83,7 @@ def opts_from_cmdline(args, onabort=None):
     else:
         opt, flags, extra = Options(optspec).parse_bytes(args)
 
-    opt.paths = [argv_bytes(x) for x in extra] or (b'/',)
+    opt.paths = [argv_bytes(x) for x in extra] or (pwd,)
     opt.long_listing = opt.l
     opt.classification = None
     opt.show_hidden = None
@@ -98,7 +99,7 @@ def opts_from_cmdline(args, onabort=None):
             opt.show_hidden = 'almost'
     return opt
 
-def within_repo(repo, opt, out):
+def within_repo(repo, opt, out, pwd=b''):
 
     if opt.commit_hash:
         opt.hash = True
@@ -115,6 +116,7 @@ def within_repo(repo, opt, out):
     ret = 0
     pending = []
     for path in opt.paths:
+        path = posixpath.join(pwd, path)
         try:
             if opt.directory:
                 resolved = vfs.resolve(repo, path, follow=False)