diff options
author | Malf Furious <m@lfurio.us> | 2017-09-01 06:28:44 -0400 |
---|---|---|
committer | Malf Furious <m@lfurio.us> | 2017-09-01 06:28:44 -0400 |
commit | 5692053379147dde8a8cabc226b73c2d5184f4c0 (patch) | |
tree | 0bb1ec21f05f876705f6eae0a47bc77569471a72 /rsync.sh | |
parent | 587bde913d67b67d6d7e1fcb8b133a35e0606125 (diff) | |
download | systrunk-5692053379147dde8a8cabc226b73c2d5184f4c0.tar.gz systrunk-5692053379147dde8a8cabc226b73c2d5184f4c0.zip |
Rewrite rsync mod to drop remote support
Also added some helpers for the merge implementation.
Diffstat (limited to 'rsync.sh')
-rw-r--r-- | rsync.sh | 103 |
1 files changed, 84 insertions, 19 deletions
@@ -2,14 +2,12 @@ # systr_rsync_normal <src> <dst> [<link>] # # Perform normal rsync operations to transfer files to or from the -# repository. If <link> is set, it is used as the --link-dest value -# for rsync. This function is polymorphic for both local and remote -# repositories. +# repository. If <link> is set, it is used as the --link-dest value. ## function systr_rsync_normal { if [ $# -lt 2 ]; then - echo "Fatal: too few arguments to systr_rsync_normal" + echo "Fatal: too few args to rsync_normal" >&2 exit 1 fi @@ -22,21 +20,88 @@ function systr_rsync_normal link="" fi - if [[ "$remote" == "" ]]; then - rsync -az --info=progress2 --info=stats2 \ - --delete --exclude='*.systr' \ - $link \ - "$src" "$dst" + rsync -az --info=progress2 --info=stats2 --delete \ + --exclude='*.systr' $link "$src" "$dst" +} + +## +# systr_rsync_diff <src> <compare> <dst> +# +# Copy files from <src> to <dst>, but only if they've changed +# since the state in <compare>. Empty directories are +# purged from <dst> afterward. +## +function systr_rsync_diff +{ + if [ $# -lt 3 ]; then + echo "Fatal: too few args to rsync_diff" >&2 + exit 1 + fi + + src="$1" + compare="--compare-dest=$2" + dst="$3" + + rsync -az --delete --exclude='*.systr' $compare \ + "$src" "$dst" + + find "$dst" -type d -empty -delete +} + +## +# systr_rsync_del <src> <compare> <dst> +# +# Delete files in <dst>, only if they have been deleted from +# <compare> to <src>. Deleted files in <dst> are 'backed up', +# in rsync lingo, meaning they are actually renamed with a +# suffix appended to the original filename. +# +# If <src> is the worktree ("."), our file suffix will be +# '&' to signify files deleted by us. Otherwise, the suffix +# will be '~' to signify files deleted by 'them'. +## +function systr_rsync_del +{ + if [ $# -lt 3 ]; then + echo "Fatal: too few args to rsync_del" >&2 + exit 1 + fi + + src="$1" + compare="--compare-dest=$2" + dst="$3" + + if [[ "$src" == "." ]]; then + suffix="--suffix='&'" else - if [[ "$src" == "." ]]; then - dst="$remote:$dst" - else - src="$remote:$src" - fi - - rsync -az -e ssh --info=progress2 --info=stats2 \ - --delete --exclude='*.systr' \ - $link \ - "$src" "$dst" + suffix="--suffix='~'" fi + + rsync -azb $suffix --existing --ignore-existing \ + --delete --exclude='*.systr' $compare \ + "$src" "$dst" +} + +## +# systr_rsync_merge <src> <dst> +# +# Finish setting up a merge, by copying files from the +# temporary directory to the merge staging directory. +# +# Files in <dst> overwritten by this operation will +# be suffixed with '*' to signify files modified by +# both of us. +## +function systr_rsync_merge +{ + if [ $# -lt 2 ]; then + echo "Fatal: too few args to rsync_merge" >&2 + exit 1 + fi + + src="$1" + dst="$2" + + rsync -azb --suffix='*' --exclude='*.systr' \ + "$src" "$dst" } |