summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPedro Alvarez <pedro.alvarez@codethink.co.uk>2016-05-13 14:16:23 (GMT)
committerPedro Alvarez <pedro.alvarez@codethink.co.uk>2016-05-13 15:42:49 (GMT)
commit1b3b5925f839d337891d73d8f71fd49b13f1010d (patch)
tree4627c8409bd422c913735a5e7bd3baba18552bc0
parentd6db02ba19525911671d35d1357e6e9f258ff573 (diff)
downloadtbdiff-baserock/pedroalvarez/symlink-fix.tar.gz
Use updated symlinks when they differbaserock/pedroalvarez/symlink-fix
-rwxr-xr-xbaserock-system-config-sync/baserock-system-config-sync18
1 files changed, 15 insertions, 3 deletions
diff --git a/baserock-system-config-sync/baserock-system-config-sync b/baserock-system-config-sync/baserock-system-config-sync
index cb37a8a..8bc4790 100755
--- a/baserock-system-config-sync/baserock-system-config-sync
+++ b/baserock-system-config-sync/baserock-system-config-sync
@@ -103,11 +103,23 @@ merge() {
if [ -d "$vp" -a ! -h "$vp" ]; then
mkdir "$vt"
elif [ -h "$vp" ]; then
- # chose a symbolic link in this order
- # of preference: Vuser, V2, V1
- if [ -h "$vu" ]; then
+ # Symbolic links.
+ if [ -h "$vu" -a -h "$v1" ]; then
+ if [ "$(readlink $v1)" == "$(readlink $vu)" ]; then
+ # User hasn't overriden the old v1 value: switch
+ # to v2.
+ cp -a "$v2" "$vt"
+ else
+ # User overwrote the v1 value; keep what they did
+ cp -a "$vu" "$vt"
+ fi
+ elif [ -h "$vu" ]; then
+ # Old behaviour that may not make sense: preserve user
+ # created symlink, if original was not a link
cp -a "$vu" "$vt"
elif [ -h "$v2" ]; then
+ # Old behaviour that may not make sense: use newly
+ # created link, if original was not a link
cp -a "$v2" "$vt"
else
cp -a "$v1" "$vt"