summaryrefslogtreecommitdiff
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
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.
-rw-r--r--Makefile.am1
-rwxr-xr-xbin/rcup.in19
-rw-r--r--test/rcup-symlink-existing.t10
3 files changed, 29 insertions, 1 deletions
diff --git a/Makefile.am b/Makefile.am
index d4ac330..ed8ea2a 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -35,6 +35,7 @@ TESTS = \
test/rcup-hostname.t \
test/rcup-standalone.t \
test/rcup-symlink-dirs.t \
+ test/rcup-symlink-existing.t \
test/rcup-usage.t \
test/rcdn-hooks.t \
test/rcdn-hooks-run-in-situ.t \
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
diff --git a/test/rcup-symlink-existing.t b/test/rcup-symlink-existing.t
new file mode 100644
index 0000000..d311b93
--- /dev/null
+++ b/test/rcup-symlink-existing.t
@@ -0,0 +1,10 @@
+ $ . "$TESTDIR/helper.sh"
+
+Symlinks files even if they are identical
+
+ $ mkdir -p .dotfiles
+ > echo find-me > "$HOME/.door"
+ > echo find-me > .dotfiles/door
+
+ $ rcup
+ > assert_linked "$HOME/.door" "$HOME/.dotfiles/door"