From c3052e6825c5501e5faaaf7137334513e9a172ed Mon Sep 17 00:00:00 2001 From: Rob Browning Date: Tue, 29 Apr 2014 20:16:54 -0500 Subject: [PATCH] Return integers, not strings from get_commit_dates() Returning strings broke bup fuse (surprising that it worked elsewhere), and since we have no fuse tests, it wasn't immediately apparent. So fix the bug and add some initial (trivial) fuse tests so that at least this particular problem doesn't happen again. To cleanup after the fuse tests, detect fuse mounts in t/cleanup-mounts-under, and try to unmount them. Signed-off-by: Rob Browning --- Makefile | 1 + lib/bup/git.py | 2 +- t/cleanup-mounts-under | 10 ++++--- t/test-fuse.sh | 59 ++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 68 insertions(+), 4 deletions(-) create mode 100755 t/test-fuse.sh diff --git a/Makefile b/Makefile index d8b19b5..8989838 100644 --- a/Makefile +++ b/Makefile @@ -88,6 +88,7 @@ runtests-python: all runtests-cmdline: all test -e t/tmp || mkdir t/tmp + TMPDIR="$(test_tmp)" t/test-fuse.sh TMPDIR="$(test_tmp)" t/test-drecurse.sh TMPDIR="$(test_tmp)" t/test-cat-file.sh TMPDIR="$(test_tmp)" t/test-compression.sh diff --git a/lib/bup/git.py b/lib/bup/git.py index 2552c45..1e2364a 100644 --- a/lib/bup/git.py +++ b/lib/bup/git.py @@ -764,7 +764,7 @@ def get_commit_dates(refs): result = [] cmd = ['git', 'show', '-s', '--pretty=format:%ct'] for chunk in batchpipe(cmd, refs, preexec_fn=_gitenv): - result += chunk.splitlines() + result += [int(x) for x in chunk.splitlines()] return result diff --git a/t/cleanup-mounts-under b/t/cleanup-mounts-under index 6d5cb87..a8ba611 100755 --- a/t/cleanup-mounts-under +++ b/t/cleanup-mounts-under @@ -23,10 +23,14 @@ for target in targets: top = os.path.realpath(target) proc_mounts = open('/proc/mounts', 'r') for line in proc_mounts: - _, point, _ = line.split(' ', 2) + _, point, fstype, _ = line.split(' ', 3) point = mntent_unescape(point) if top == point or os.path.commonprefix((top + '/', point)) == top + '/': - if subprocess.call(['umount', point]) != 0: - exit_status = 1 + if fstype.startswith('fuse'): + if subprocess.call(['fusermount', '-uz', point]) != 0: + exit_status = 1 + else: + if subprocess.call(['umount', '-l', point]) != 0: + exit_status = 1 sys.exit(exit_status) diff --git a/t/test-fuse.sh b/t/test-fuse.sh new file mode 100755 index 0000000..33567f9 --- /dev/null +++ b/t/test-fuse.sh @@ -0,0 +1,59 @@ +#!/usr/bin/env bash +. ./wvtest-bup.sh + +set -o pipefail + +if ! fusermount -V; then + echo 'skipping FUSE tests: fusermount does not appear to work' + exit 0 +fi + +if ! groups | grep -q fuse && test "$(t/root-status)" != root; then + echo 'skipping FUSE tests: you are not root and not in the fuse group' + exit 0 +fi + +top="$(WVPASS pwd)" || exit $? +tmpdir="$(WVPASS wvmktempdir)" || exit $? + +export BUP_DIR="$tmpdir/bup" +export GIT_DIR="$tmpdir/bup" + +bup() { "$top/bup" "$@"; } + +WVPASS bup init +WVPASS cd "$tmpdir" + +savestamp1=$(WVPASS python -c 'import time; print int(time.time())') || exit $? +savestamp2=$(($savestamp1 + 1)) +savename1="$(printf '%(%Y-%m-%d-%H%M%S)T' "$savestamp1")" || exit $? +savename2="$(printf '%(%Y-%m-%d-%H%M%S)T' "$savestamp2")" || exit $? + +WVPASS mkdir src +WVPASS date > src/foo +WVPASS bup index src +WVPASS bup save -n src -d "$savestamp1" --strip src + +WVSTART "basics" +WVPASS mkdir mnt +WVPASS bup fuse mnt + +result=$(WVPASS ls mnt) || exit $? +WVPASSEQ src "$result" + +result=$(WVPASS ls mnt/src) || exit $? +WVPASSEQ "$result" "$savename1 +latest" + +result=$(WVPASS ls mnt/src/latest) || exit $? +WVPASSEQ "$result" "foo" + +# Right now we don't detect new saves. +WVPASS bup save -n src -d "$savestamp2" --strip src +result=$(WVPASS ls mnt/src) || exit $? +savename="$(WVPASS printf '%(%Y-%m-%d-%H%M%S)T' "$savestamp1")" || exit $? +WVPASSEQ "$result" "$savename1 +latest" + +WVPASS fusermount -uz mnt +WVPASS rm -rf "$tmpdir" -- 2.39.2