From 70d66ecdb668e3947fb5e8b8f2f68f17c571e848 Mon Sep 17 00:00:00 2001 From: Dave Reisner Date: Sat, 12 Jun 2010 21:19:08 -0400 Subject: deletion: ensure that the union is unmounted before deleting. fail hard if we can't unmount. quiet down the initial grep call --- squashfu | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/squashfu b/squashfu index 7c666ed..0fa1d1e 100755 --- a/squashfu +++ b/squashfu @@ -119,8 +119,9 @@ unmount_union () { # Returns: return code from umount info "Unmounting union" umount "$UNION_MOUNT" 2>/dev/null + local ret=$? sleep .5 - return $? + return $ret } unmount_squash () { @@ -230,7 +231,8 @@ action_remove_bin () { [[ $UID != 0 ]] && die "Must be root to remove a backup" [[ ! -w "$BINVENTORY" ]] && die "Unable to write to ${BINVENTORY}" - if grep "^$1:" $BINVENTORY && [[ -d "$BINS_DIR/$1" ]]; then + + if grep -q "^$1:" $BINVENTORY && [[ -d "$BINS_DIR/$1" ]]; then if [[ -z $2 ]]; then echo "Are you SURE you want to remove this bin?" local timestamp=$(sed -n "/^$1:/s/^[0-9]*:\([0-9]*\)/\1/p" "$BINVENTORY") @@ -239,15 +241,16 @@ action_remove_bin () { "Date Created:" "$(date --rfc-3339=seconds --date="@$timestamp")" \ "Size:" "$(du -sh "$BINS_DIR/$1" 2>/dev/null | awk '{print $1}')" - echo -ne "\033[1;33m::\033[0m" + echo -ne "\033[1;33m::\033[0m " read -N1 -p "Confirm deletion (y/N) " reply echo - [[ ! "$reply" =~ [Yy] ]] && die "Delete operation aborted" + [[ ! "$reply" = [Yy] ]] && die "Delete operation aborted" fi + mountpoint -q "$UNION_MOUNT" && { unmount_union || die "Failed to unmount union"; } info "Deleting bin $1" sed -i "/^$1:[0-9]*/d" "$BINVENTORY" - rm -rf $BINS_DIR/$1 + rm -rf "$BINS_DIR/$1" else die "Bin $1 not found." fi -- cgit v1.2.3