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. --- bin/rcup.in | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) (limited to 'bin') 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 -- cgit v1.2.3