Commit f17f085e authored by Daniel Stan's avatar Daniel Stan

fonction de suppression-safe

parent 9eb652fe
......@@ -7,9 +7,27 @@ available_local () {
find $FS_DIR/$BACK_DIR -type d -printf "%P\n" | sed "s/\($PATTERN\)$/\1/; t; d" | sort
}
can_delete () {
USED=$(find $FS_DIR/$BACK_DIR -lname "*/$1" -name "parent" -printf "%P\n" | sed "s/\/parent//")
echo "Used by $USED"
check_valid () {
if [ "$FS_DIR/$BACK_DIR" != "$(dirname $FS_DIR/$BACK_DIR/$1)" ]; then
echo "$1 is not a valid backup file"
exit 1
fi
}
used_by () {
check_valid $1
find $FS_DIR/$BACK_DIR -lname "*/$1" -name "parent" -printf "%P\n" | sed "s/\/parent//"
}
delete () {
check_valid "$1"
USED=$(used_by "$1")
if [ -z "$USED" ]; then
rm -ri "$FS_DIR/$BACK_DIR/$1"
else
echo "$1 is still used by $USED"
exit 1
fi
}
not_implemented () {
......@@ -45,6 +63,15 @@ elif [ "$1" = "receive" ]; then
# Actual receive
cat > $path/gpg
elif [ "$1" = "can_delete" ]; then
can_delete $2
USED=$(used_by "$2" || exit 1)
if [ -z "$USED" ]; then
echo "$2 can be deleted"
else
echo "$2 is still used by $USED"
fi
elif [ "$1" = "delete" ]; then
delete "$2"
else
echo "Unknown command $1"
fi
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment