Skip to content
Browse files

deletion: ensure that the union is unmounted before deleting. fail ha…

…rd if we can't unmount. quiet down the initial grep call
  • Loading branch information...
1 parent 8ccb3b8 commit 70d66ecdb668e3947fb5e8b8f2f68f17c571e848 @falconindy committed
Showing with 8 additions and 5 deletions.
  1. +8 −5 squashfu
View
13 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

0 comments on commit 70d66ec

Please sign in to comment.
Something went wrong with that request. Please try again.