From: Rob Browning Date: Sat, 22 Mar 2014 05:20:20 +0000 (-0500) Subject: Add initial support for ls(1) style "-d" argument to "bup ls". X-Git-Tag: 0.26-rc1~18 X-Git-Url: https://arthur.barton.de/gitweb/?p=bup.git;a=commitdiff_plain;h=2334887894f5d1ea7777859c5f0457c9ceadcb16 Add initial support for ls(1) style "-d" argument to "bup ls". Signed-off-by: Rob Browning --- diff --git a/Documentation/bup-ls.md b/Documentation/bup-ls.md index 259afec..bbad3dc 100644 --- a/Documentation/bup-ls.md +++ b/Documentation/bup-ls.md @@ -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. diff --git a/lib/bup/ls.py b/lib/bup/ls.py index 444694a..72f8b9b 100644 --- a/lib/bup/ls.py +++ b/lib/bup/ls.py @@ -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 diff --git a/t/test-ls.sh b/t/test-ls.sh index ec4d22b..15b5ac8 100755 --- a/t/test-ls.sh +++ b/t/test-ls.sh @@ -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"