]> arthur.barton.de Git - bup.git/commitdiff
Add initial support for ls(1) style "-d" argument to "bup ls".
authorRob Browning <rlb@defaultvalue.org>
Sat, 22 Mar 2014 05:20:20 +0000 (00:20 -0500)
committerRob Browning <rlb@defaultvalue.org>
Thu, 3 Apr 2014 19:41:15 +0000 (14:41 -0500)
Signed-off-by: Rob Browning <rlb@defaultvalue.org>
Documentation/bup-ls.md
lib/bup/ls.py
t/test-ls.sh

index 259afec4296288565bda404048f82ca7afefd9a8..bbad3dcb8e14170bbf85ef23dcb2509d1d856b26 100644 (file)
@@ -48,6 +48,10 @@ you can view its contents using `bup join` or `git show`.
 -A, \--almost-all
 :   show hidden files, except "." and "..".
 
+-d, \--directory
+:   show information about directories themselves, rather than their
+    contents, and don't follow symlinks.
+
 -l
 :   provide a detailed, long listing for each item.
 
index 444694aa6d40d007d16b43bf1cdfed271f0f3a6b..72f8b9b67b3a5dbcbe6a5a48d6ec49d635b30233 100644 (file)
@@ -1,5 +1,5 @@
 """Common code for listing files from a bup repository."""
-import copy, stat, xstat
+import copy, os.path, stat, xstat
 from bup import metadata, options, vfs
 from helpers import *
 
@@ -48,6 +48,7 @@ s,hash   show hash for each file
 a,all    show hidden files
 A,almost-all    show hidden files except . and ..
 l        use a detailed, long listing format
+d,directory show directories, not contents; don't follow symlinks
 F,classify append type indicator: dir/ sym@ fifo| sock= exec*
 file-type append type indicator: dir/ sym@ fifo| sock=
 human-readable    print human readable file sizes (i.e. 3.9K, 4.7M)
@@ -99,9 +100,12 @@ def do_ls(args, pwd, default='.', onabort=None, spec_prefix=''):
     ret = 0
     for path in (extra or [default]):
         try:
-            n = pwd.try_resolve(path)
+            if opt.directory:
+                n = pwd.lresolve(path)
+            else:
+                n = pwd.try_resolve(path)
 
-            if stat.S_ISDIR(n.mode):
+            if not opt.directory and stat.S_ISDIR(n.mode):
                 if show_hidden == 'all':
                     output_node_info(n, '.')
                     # Match non-bup "ls -a ... /".
@@ -115,7 +119,7 @@ def do_ls(args, pwd, default='.', onabort=None, spec_prefix=''):
                        or not len(name)>1 or not name.startswith('.'):
                         output_node_info(sub, name)
             else:
-                output_node_info(n, path)
+                output_node_info(n, os.path.normpath(path))
         except vfs.NodeError, e:
             log('error: %s\n' % e)
             ret = 1
index ec4d22b36a89d26e44db196347bd9bb55d8ab81f..15b5ac86046905e5150feca40fed1ba4bac7f621 100755 (executable)
@@ -34,6 +34,7 @@ WVPASS chmod -R u=rwX,g-rwx,o-rwx .
 WVPASS bup index src
 WVPASS bup save -n src src
 
+
 WVSTART "ls (short)"
 
 WVPASSEQ "$(WVPASS bup ls /)" "src"
@@ -92,6 +93,9 @@ file
 socket=
 symlink@"
 
+WVPASSEQ "$(WVPASS bup ls -d src/latest/"$tmpdir"/src)" "src/latest$tmpdir/src"
+
+
 WVSTART "ls (long)"
 
 WVPASSEQ "$(WVPASS bup ls -l / | tr -s ' ' ' ')" \
@@ -191,11 +195,16 @@ prw------- $uid/$gid 0 1969-07-20 20:18 fifo
 srwx------ $uid/$gid 0 1969-07-20 20:18 socket
 $symlink_mode $uid/$gid $symlink_size $symlink_date symlink -> file"
 
+WVPASSEQ "$(bup ls -ld "src/latest$tmpdir/src" | tr -s ' ' ' ')" \
+"drwx------ $user/$group 0 1969-07-20 20:18 src/latest$tmpdir/src"
+
+
 WVSTART "ls (backup set - long)"
 WVPASSEQ "$(bup ls -l src | cut -d' ' -f 1-2)" \
 "l--------- ?/?
 l--------- ?/?"
 
+
 WVSTART "ls (dates TZ != UTC)"
 export TZ=US/Central
 symlink_date_central="$(bup ls -l src/latest"$tmpdir"/src | grep symlink)"
@@ -209,4 +218,5 @@ srwx------ $uid/$gid 0 1969-07-20 15:18 socket
 $symlink_mode $uid/$gid $symlink_size $symlink_date_central symlink -> file"
 unset TZ
 
+
 WVPASS rm -rf "$tmpdir"