From 083781c12a98bf42351f75e830821b436871faef Mon Sep 17 00:00:00 2001 From: pvincent Date: Tue, 24 May 2022 13:30:55 +0400 Subject: [PATCH] transfer_mv safer on same directories --- tools/transfer_mv | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/tools/transfer_mv b/tools/transfer_mv index b866e6d..06af1c5 100755 --- a/tools/transfer_mv +++ b/tools/transfer_mv @@ -1,5 +1,10 @@ #!/bin/bash -[ ! -d "$1" ] && echo "SOURCE FOLDER $1 not reachable!" && exit -1 -rsync -a --no-inc-recursive --info=progress2 --remove-source-files "$1" "$2" && find "$1" -type d -empty -delete +SOURCE=$(realpath "$1") +DEST=$(realpath "$2") +[ ! -d "$SOURCE" ] && echo "SOURCE FOLDER <$SOURCE> not reachable!" && exit 1 +[ ! -d "$DEST" ] && echo "DESTINATION FOLDER missing!" && exit 2 +[ "$SOURCE" == "$DEST" ] && echo "SOURCE and DESTINATION overriden!" && exit 3 + +rsync -a --no-inc-recursive --info=progress2 --remove-source-files "$SOURCE" "$DEST" && find "$SOURCE" -type d -empty -delete