summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlasdair G Kergon <agk@redhat.com>2016-04-06 22:36:42 +0100
committerAlasdair G Kergon <agk@redhat.com>2016-04-06 22:36:42 +0100
commit55001ae9ec2c00a070f8dfa8541f4f17a6e2a284 (patch)
tree53c63831968cb351d70e544b9ce0f82f8b734600
parent307ab2c179073d28d1c9ec9f995f2849aeab07c6 (diff)
downloadlvm2-55001ae9ec2c00a070f8dfa8541f4f17a6e2a284.tar.gz
lvmdump: Allow dir to exist already if it is empty
-rw-r--r--WHATS_NEW1
-rwxr-xr-xscripts/lvmdump.sh8
2 files changed, 7 insertions, 2 deletions
diff --git a/WHATS_NEW b/WHATS_NEW
index 98168a16d..b1da1b0db 100644
--- a/WHATS_NEW
+++ b/WHATS_NEW
@@ -1,5 +1,6 @@
Version 2.02.150 -
=================================
+ Allow the lvmdump directory to exist already provided it is empty.
Version 2.02.149 - 1st April 2016
=================================
diff --git a/scripts/lvmdump.sh b/scripts/lvmdump.sh
index 1e91a9d00..19b36d37e 100755
--- a/scripts/lvmdump.sh
+++ b/scripts/lvmdump.sh
@@ -99,8 +99,12 @@ else
dir="$HOME/$dirbase"
fi
-test -e $dir && die 3 "Fatal: $dir already exists"
-$MKDIR -p $dir || die 4 "Fatal: could not create $dir"
+if test -d $dir ; then
+ (shopt -s nullglob dotglob; cd $dir && files=(*) && ((${#files[@]}))) && die 5 "Fatal: directory $dir already exists and is not empty"
+else
+ test -e $dir && die 3 "Fatal: $dir already exists"
+ $MKDIR -p $dir || die 4 "Fatal: could not create $dir"
+fi
log="$dir/lvmdump.log"