diff --git a/CHANGELOG.md b/CHANGELOG.md index dd3a701..273a3bf 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,7 @@ SHORT FUTURE IMPROVEMENTS ------------------------- - Tree functions execute piped commands (grep, awk) on local system when launched on remote slave which can cause more bandwith usage +- Function calls give variables like $1, $2 etc. Reassign them to local variables with better names for easier code reading FAR FUTURE IMPROVEMENTS ----------------------- @@ -32,6 +33,7 @@ RECENT CHANGES -------------- - Improved ssh uri recognition (thanks to onovy) +- Fixed #22 (missing full path in soft deletion) - Fixed #21 by adding portable shell readlink / realpath from https://github.com/mkropat/sh-realpath - Added detection of osync.sh script in osync-batch.sh to overcome mising path in crontab - Fixed osync-batch.sh script when osync is in executable path like /usr/local/bin diff --git a/osync.sh b/osync.sh index 93456ba..df21ab3 100755 --- a/osync.sh +++ b/osync.sh @@ -4,7 +4,7 @@ PROGRAM="Osync" # Rsync based two way sync engine with fault tolerance AUTHOR="(L) 2013-2015 by Orsiris \"Ozy\" de Jong" CONTACT="http://www.netpower.fr/osync - ozy@netpower.fr" PROGRAM_VERSION=1.00pre -PROGRAM_BUILD=2606201501 +PROGRAM_BUILD=2015062701 ## type doesn't work on platforms other than linux (bash). If if doesn't work, always assume output is not a zero exitcode if ! type -p "$BASH" > /dev/null @@ -1179,7 +1179,19 @@ function _delete_local if [ $dryrun -ne 1 ] then - mv "$REPLICA_DIR$files" "$REPLICA_DIR$3" + if [ -e "$REPLICA_DIR$3/$files" ] + then + rm -rf "$REPLICA_DIR$3/$files" + fi + # In order to keep full path on soft deletion, create parent directories before move + parentdir="$(dirname "$files")" + if [ "$parentdir" != "." ] + then + mkdir --parents "$REPLICA_DIR$3/$parentdir" + mv -f "$REPLICA_DIR$files" "$REPLICA_DIR$3/$parentdir" + else + mv -f "$REPLICA_DIR$files" "$REPLICA_DIR$3" + fi if [ $? != 0 ] then LogError "Cannot move $REPLICA_DIR$files to deletion directory." @@ -1282,7 +1294,19 @@ $SSH_CMD error_alert=0 sync_on_changes=$sync_on_changes silent=$silent DEBUG=$DE if [ $dryrun -ne 1 ] then - $COMMAND_SUDO mv "$REPLICA_DIR$files" "$REPLICA_DIR$DELETE_DIR" + if [ -e "$REPLICA_DIR$DELETE_DIR/$files" ] + then + $COMMAND_SUDO rm -rf "$REPLICA_DIR$DELETE_DIR/$files" + fi + # In order to keep full path on soft deletion, create parent directories before move + parentdir="$(dirname "$files")" + if [ "$parentdir" != "." ] + then + $COMMAND_SUDO mkdir --parents "$REPLICA_DIR$DELETE_DIR/$parentdir" + $COMMAND_SUDO mv -f "$REPLICA_DIR$files" "$REPLICA_DIR$DELETE_DIR/$parentdir" + else + $COMMAND_SUDO mv -f "$REPLICA_DIR$files" "$REPLICA_DIR$DELETE_DIR" + fi if [ $? != 0 ] then LogError "Cannot move $REPLICA_DIR$files to deletion directory."