From 55001ae9ec2c00a070f8dfa8541f4f17a6e2a284 Mon Sep 17 00:00:00 2001 From: Alasdair G Kergon Date: Wed, 6 Apr 2016 22:36:42 +0100 Subject: [PATCH] lvmdump: Allow dir to exist already if it is empty --- WHATS_NEW | 1 + scripts/lvmdump.sh | 8 ++++++-- 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"