summaryrefslogtreecommitdiff
path: root/bin
diff options
context:
space:
mode:
authorGravatar Graham Bennett <graham@simulcra.org>2015-11-27 11:54:35 +0100
committerGravatar Graham Bennet <mike@mike-burns.com>2015-11-27 11:56:57 +0100
commit7a94e88e57d4721b4ef32275d883a10e280eb277 (patch)
treebfd54a9a9261ef2f5c3bdeac2c64a23fc908e01f /bin
parent52028b09025c5ebc41fc88bf3d7838416fbbbe54 (diff)
Symlink identical files if they are not yet linked
Edge case: a file is a copy of a dotfile but is not linked. In this case we should link it.
Diffstat (limited to 'bin')
-rwxr-xr-xbin/rcup.in19
1 files changed, 18 insertions, 1 deletions
diff --git a/bin/rcup.in b/bin/rcup.in
index bdae664..de11751 100755
--- a/bin/rcup.in
+++ b/bin/rcup.in
@@ -130,6 +130,18 @@ is_identical() {
diff -c "$1" "$2" > /dev/null 2>&1
}
+is_linked() {
+ local src="$1"
+ local dest="$2"
+
+ if [ -h "$dest" ]; then
+ local link_dest=$(readlink $dest)
+ [ "$link_dest" == "$src" ]
+ else
+ return 1
+ fi
+}
+
handle_dir() {
local dest="$1"
@@ -148,7 +160,12 @@ handle_file() {
if [ "$generate" -ne 1 -a -e "$dest" ]; then
if is_identical "$src" "$dest"; then
- $VERBOSE "identical $dest"
+ if [ "x$sigil" != "xX" ] && ! is_linked "$src" "$dest"; then
+ $VERBOSE "replacing identical but unlinked $dest"
+ replace_file "$src" "$dest" "$sigil"
+ else
+ $VERBOSE "identical $dest"
+ fi
elif [ $REPLACE_ALL -eq 1 ]; then
replace_file "$src" "$dest" "$sigil"
else