From 7c1bae5624e574f438a87ba2c32bf4dec0ea1988 Mon Sep 17 00:00:00 2001 From: David Disseldorp Date: Fri, 22 May 2015 17:22:51 +0200 Subject: [PATCH] tests: don't choke on deleted losetup paths If a file has been deleted with a loopback device attached, then the `losetup --all` output will carry: /dev/loopX: [0032]:344213 (/.../src/test-ceph-disk/vdf.disk (deleted)) This causes the losetup parsing in reset_leftover_dev() to throw an error, e.g.: rreset_leftover_dev: 430: test '(/home/ddiss/ceph/src/test-ceph-disk/vdf.disk' '(deleted))' = '(/home/ddiss/ceph/src/test-ceph-disk/vdf.disk)' test/ceph-disk.sh: line 430: test: too many arguments Fix this by quoting the path variable for the string comparison. Signed-off-by: David Disseldorp --- src/test/ceph-disk.sh | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/test/ceph-disk.sh b/src/test/ceph-disk.sh index d6cceb38a0e..c6bb4d5ff2f 100755 --- a/src/test/ceph-disk.sh +++ b/src/test/ceph-disk.sh @@ -419,7 +419,9 @@ function reset_leftover_dev() { local path=$1 losetup --all | sed -e 's/://' | while read dev id associated_path ; do - if test $associated_path = "($path)" ; then + # if $path has been deleted with a dev attached, then $associated_path + # will carry "($path (deleted))". + if test "$associated_path" = "($path)" ; then reset_dev $dev losetup --detach $dev fi -- 2.47.3