From 14cba81f6e97d1a1fa8ffcf2d34fc96d13d79d63 Mon Sep 17 00:00:00 2001 From: Jaromil Date: Mon, 26 Dec 2016 20:40:23 +0100 Subject: [PATCH] fix is_valid_tomb check for already mounted tombs also added some more verbosity on debug --- tomb | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/tomb b/tomb index be8f29b..be66be8 100755 --- a/tomb +++ b/tomb @@ -507,20 +507,27 @@ is_valid_tomb() { _warning "Tomb file is not writable: ::1 tomb file::" $1 _fail=1 } + _verbose "tomb file is readable" + [[ ! -f "$1" ]] && { _warning "Tomb file is not a regular file: ::1 tomb file::" $1 _fail=1 } + _verbose "tomb file is a regular file" + [[ ! -s "$1" ]] && { _warning "Tomb file is empty (zero length): ::1 tomb file::" $1 _fail=1 } + _verbose "tomb file is not empty" _uid="`zstat +uid $1`" [[ "$_uid" = "$UID" ]] || { _user="`zstat -s +uid $1`" _warning "Tomb file is owned by another user: ::1 tomb owner::" $_user } + _verbose "tomb is not owned by another user" + [[ $_fail = 1 ]] && { _failure "Tomb command failed: ::1 command name::" $subcommand } @@ -536,9 +543,12 @@ is_valid_tomb() { _plot $1 # Set TOMB{PATH,DIR,FILE,NAME} # Tomb already mounted (or we cannot alter it) - [[ "`mount -l`" -regex-match "${TOMBFILE}.*\[$TOMBNAME\]$" ]] && { + [[ "`mount -l | + awk -vtomb="[$TOMBNAME]" ' +/^\/dev\/mapper\/tomb/ { if($7==tomb) print $1 }'`" = "" ]] || { _failure "Tomb is currently in use: ::1 tomb name::" $TOMBNAME } + _verbose "tomb file is not currently in use" _message "Valid tomb file found: ::1 tomb path::" $TOMBPATH