From 7a94e88e57d4721b4ef32275d883a10e280eb277 Mon Sep 17 00:00:00 2001 From: Graham Bennett Date: Fri, 27 Nov 2015 11:54:35 +0100 Subject: 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. --- Makefile.am | 1 + bin/rcup.in | 19 ++++++++++++++++++- test/rcup-symlink-existing.t | 10 ++++++++++ 3 files changed, 29 insertions(+), 1 deletion(-) create mode 100644 test/rcup-symlink-existing.t 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" -- cgit v1.2.3