diff options
author | Lars Wirzenius <liw@liw.fi> | 2013-10-21 19:31:56 +0100 |
---|---|---|
committer | Lars Wirzenius <liw@liw.fi> | 2013-10-21 19:31:56 +0100 |
commit | ddcefcab439393e4deb6d7842aef2d9d1e773415 (patch) | |
tree | cb1ec3bd8824b4620dfe77a10e2dbf4a7188a7c9 | |
parent | 052238fe969c41927292e89a81832c6ef5c62ee9 (diff) | |
parent | 9403e062bfae97eb2d9cfa074433d058c607ffeb (diff) | |
download | obnam-ddcefcab439393e4deb6d7842aef2d9d1e773415.tar.gz |
Handle trailing slashes to ls args
-rw-r--r-- | NEWS | 3 | ||||
-rw-r--r-- | obnamlib/plugins/show_plugin.py | 6 | ||||
-rw-r--r-- | yarns/ls.yarn | 106 | ||||
-rw-r--r-- | yarns/obnam.sh | 2 |
4 files changed, 116 insertions, 1 deletions
@@ -63,6 +63,9 @@ Bug fixes: where a backup repository for a client exists, but does not have a backup yet. Patch by Lars Kruse. +* `obnam ls` now handles trailing slashes in filename arguments. + Reported by Biltong. + Version 1.5, released 2013-08-08 -------------------------------- diff --git a/obnamlib/plugins/show_plugin.py b/obnamlib/plugins/show_plugin.py index 93aec835..b48f2534 100644 --- a/obnamlib/plugins/show_plugin.py +++ b/obnamlib/plugins/show_plugin.py @@ -157,9 +157,15 @@ class ShowPlugin(obnamlib.ObnamPlugin): self.app.output.write( 'Generation %s (%s - %s)\n' % (gen, started, ended)) for ls_file in args: + ls_file = self.remove_trailing_slashes(ls_file) self.show_objects(gen, ls_file) self.repo.fs.close() + def remove_trailing_slashes(self, filename): + while filename.endswith('/') and filename != '/': + filename = filename[:-1] + return filename + def format_time(self, timestamp): return time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(timestamp)) diff --git a/yarns/ls.yarn b/yarns/ls.yarn new file mode 100644 index 00000000..c40ff2d1 --- /dev/null +++ b/yarns/ls.yarn @@ -0,0 +1,106 @@ +`obnam ls` +========== + +`obnam ls` lists contents of repositories. To test this, we start +by backing up some live data to a repository, and then we query it +in various ways. + + SCENARIO obnam ls + GIVEN a live data directory xyzzy + AND a file xyzzy/foo.txt containing "foo" + AND a directory xyzzy/bar + AND a file xyzzy/bar/yo containing "yo" + AND an obnam config called xyzzy.conf + AND config xyzzy.conf sets repository to xyzzy.repo + AND config xyzzy.conf sets root to xyzzy + WHEN "obnam backup" using xyzzy.conf is run + THEN plain "obnam ls" using xyzzy.conf contains "bar/yo$" + AND "obnam ls" using xyzzy.conf when given xyzzy contains "bar/yo$" + +There was a bug in Obnam 1.5 (and possibly other versions) that +listing contents of a directory that ends in a slash (but isn't the +root directory) fails. The following is a test for that bug. + + AND "obnam ls" using xyzzy.conf when given xyzzy/ contains "bar/yo$" + +That's it. + +Implementations +=============== + +Introduction +------------ + +We run Obnam in `$DATADIR` so that any paths to test data, etc, +may be relative to `$DATADIR`. The `run_obnam` shell function in +`obnam.sh` allows us to do that safely. + +Live data creation +------------------ + +There's several steps to creating live data. First is to create +directory for the live data. We let the user choose the name, in case +they need to have more than one live data (perhaps for simulating +multiple clients). + + IMPLEMENTS GIVEN a live data directory (\S+) + mkdir "$DATADIR/$MATCH_1" + +Create a file. This is meant for live data creation, but it can +actually create any file. The contents printed using `printf`(1), so +that escapes may be used. + + IMPLEMENTS GIVEN a file (\S+) containing "(.*)" + printf "$MATCH_1" > "$DATADIR/$MATCH_1" + +Likewise, a directory may be created. + + IMPLEMENTS GIVEN a directory (\S+) + mkdir "$DATADIR/$MATCH_1" + +Obnam configuration file creation +--------------------------------- + +Various tests need to set up configuration files with specific +settings. + + IMPLEMENTS GIVEN an obnam config called (\S+) + printf '[config]\n' > "$DATADIR/$MATCH_1" + + IMPLEMENTS GIVEN config (\S+) sets (\S+) to (\S+) + printf '%s = %s\n' "$MATCH_2" "$MATCH_3" >> "$DATADIR/$MATCH_1" + +Backing up with Obnam +--------------------- + +We need to backup with Obnam. + + IMPLEMENTS WHEN "obnam backup" using (\S+) is run + cd "$DATADIR" + run_obnam --config "$DATADIR/$MATCH_1" backup + +Checking `obnam ls` results +--------------------------- + +`obnam ls` produces output that mimicks (but doesn't exactly match) +that of `ls -lAR` using GNU coreutils and other popular +implementations of the Unix `ls`(1) command. This makes exact output +matching a bit tricky to do. Instead, we check whether specific files +are in the output. + + IMPLEMENTS THEN plain "obnam ls" using (\S+) contains "(.+)" + cd "$DATADIR" + run_obnam --config "$DATADIR/$MATCH_1" ls | grep "$MATCH_2" + +This is similar to a plain `obnam ls`, but we give it an argument, to +restrict what gets listed. If the argument is not an absolute path, we +make it one, since Obnam expects it to be. It is, unfortunately, +difficult to let the user of this IMPLEMENTS specify an absolute path. + + IMPLEMENTS THEN "obnam ls" using (\S+) when given (\S+) contains "(.+)" + cd "$DATADIR" + case "$MATCH_2" in + /*) path="$MATCH_2" ;; + *) path="$(pwd)/$MATCH_2" ;; + esac + run_obnam --config "$DATADIR/$MATCH_1" ls "$path" | grep "$MATCH_3" diff --git a/yarns/obnam.sh b/yarns/obnam.sh index 9de72ba7..eafc8b8d 100644 --- a/yarns/obnam.sh +++ b/yarns/obnam.sh @@ -21,7 +21,7 @@ run_obnam() { - ./obnam --no-default-config "$@" + "$SRCDIR/obnam" --no-default-config "$@" } |