From 54c13b85ef5aef6ee84d05fa065180582b2d03dd Mon Sep 17 00:00:00 2001 From: deajan Date: Fri, 26 Jun 2015 16:31:11 +0200 Subject: [PATCH] Hotfix #22 - Missing full path in soft deletion --- CHANGELOG.md | 2 ++ osync.sh | 28 ++++++++++++++++++++++------ 2 files changed, 24 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ef964d6..d4100d5 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 ----------------------- @@ -31,6 +32,7 @@ UNDER WORK RECENT CHANGES -------------- +- 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 9369bdd..d246d85 100755 --- a/osync.sh +++ b/osync.sh @@ -1,10 +1,10 @@ -#!/usr/bin/env bash +2#!/usr/bin/env bash 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-hotfix22 -PROGRAM_BUILD=2406201502 +PROGRAM_VERSION=1.00pre-hotfix2#22 +PROGRAM_BUILD=2606201501 ## 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 @@ -870,7 +870,7 @@ function RsyncExcludeFrom function WriteLockFiles { - echo $SCRIPT_PID > "$MASTER_LOCK" + echo $SCRIPT_PID > "$MASTER_LOCK" 2> "$LOG_FILE" if [ $? != 0 ] then LogError "Could not set lock on master replica." @@ -1183,7 +1183,15 @@ function _delete_local then rm -rf "$REPLICA_DIR$3/$files" fi - mv -f "$REPLICA_DIR$files" "$REPLICA_DIR$3" + # 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." @@ -1290,7 +1298,15 @@ $SSH_CMD error_alert=0 sync_on_changes=$sync_on_changes silent=$silent DEBUG=$DE then $COMMAND_SUDO rm -rf "$REPLICA_DIR$DELETE_DIR/$files" fi - $COMMAND_SUDO mv -f "$REPLICA_DIR$files" "$REPLICA_DIR$DELETE_DIR" + # 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."