Skip to content

Commit

Permalink
pull: Only remove files locally if removed remotely
Browse files Browse the repository at this point in the history
This re-introduces the behavior from ac0622c which in the backup_inline
function would detect if files were removed remotely before deleting locally.
This is necessary for long-running syncs to behave properly as files created
locally after the sync was started should be protected from removal.

It is implemented here using rsync filter rules rather than the grep expression
as before.
  • Loading branch information
greezybacon authored and Jared Hancock committed Aug 31, 2017
1 parent 4609e35 commit 07d89ab
Showing 1 changed file with 21 additions and 9 deletions.
30 changes: 21 additions & 9 deletions bin/bitpocket
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,13 @@ function log {
tail -f "$DOT_DIR/log"
}

function prefix() {
while read line
do
echo "$1$line"
done
}

function pull() {
# Actual fetch
# Pulling changes from server
Expand All @@ -133,11 +140,20 @@ function pull() {
# for logging of deleted files, which need to be sorted
exec 3> >(sort > "$TMP_DIR/pull-delete")

# Determine what will be fetched from server and make backup
# copies of any local files to be deleted or overwritten.
# Determine what will be fetched from server and make backup copies of any
# local files to be deleted or overwritten.
#
# Only delete locally if deleted remotely. To do this, use the remote-del
# file to set the *R*isk filter flag (allow delete), and protect everything
# else with the *P*rotect flag.
#
# Order of includes/excludes/filters is EXTREMELY important
rsync -auzxi --delete-delay --exclude "/$DOT_DIR" \
cat "$TMP_DIR/remote-del" \
| prefix "R " \
| rsync -auzxi --delete --exclude "/$DOT_DIR" \
--exclude-from="$TMP_DIR/local-add-del" \
--filter=". -" \
--filter="P **" \
$DO_BACKUP \
$RSYNC_OPTS $USER_RULES $REMOTE/ . \
| detect_changes \
Expand Down Expand Up @@ -170,12 +186,8 @@ function detect_changes() {
operation=${line%% *}
if [[ "$operation" == "*deleting" ]]
then
# Only delete locally if deleted remotely
if grep -q -x "/$filename" "$TMP_DIR/remote-del"
then
# Delete here rather than syncing
echo "/$filename" >&3
fi
# Mark as locally deleted
echo "/$filename" >&3
elif [[ "$operation" =~ \+\+\+\+$ ]]
then
# Mark as added locally
Expand Down

0 comments on commit 07d89ab

Please sign in to comment.