From 200d4d0141ff9b56438cff46d9a9b65d8a13b85d Mon Sep 17 00:00:00 2001 From: Jesus Briales Date: Fri, 18 Jan 2019 21:56:47 +0000 Subject: [PATCH] Overwrite broken links --- bin/dotsync | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/bin/dotsync b/bin/dotsync index 30d4d5c5b..f7407750b 100755 --- a/bin/dotsync +++ b/bin/dotsync @@ -153,6 +153,7 @@ symlink() getrealdotfile "$file" if [[ -e "$DOTFILE" ]] && [[ ! -h "$DOTFILE" ]]; then + # If file exists and it is not a link BACKUP="$BACKUPDIR/$(basename "$file")" echo "*** $DOTFILE already exists, backing up in $BACKUP ***" cp -r "$DOTFILE" "$BACKUP" @@ -165,10 +166,14 @@ symlink() cp "$BACKUPDIR.old/ssh/known_hosts" "$DOTFILE/" fi fi - elif [[ -e "$DOTFILE" ]]; then + elif [[ -e "$DOTFILE" ]] || [[ -h "$DOTFILE" ]] ; then + # If file exists and it is a link + # NOTE: The second condition is required because otherwise broken links + # are not detected by [[ -e ... ]] condition rm -f "$DOTFILE" ln -s "$REALFILE" "$DOTFILE" else + # The file does not exist ln -s "$REALFILE" "$DOTFILE" fi