From: Alasdair G Kergon Date: Wed, 6 Apr 2016 21:36:42 +0000 (+0100) Subject: lvmdump: Allow dir to exist already if it is empty X-Git-Tag: v2_02_150~17 X-Git-Url: https://sourceware.org/git/?a=commitdiff_plain;h=55001ae9ec2c00a070f8dfa8541f4f17a6e2a284;p=lvm2.git lvmdump: Allow dir to exist already if it is empty --- 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"