diff --git a/bin/dotsync b/bin/dotsync index 3f1dea43f..da48dece8 100755 --- a/bin/dotsync +++ b/bin/dotsync @@ -154,6 +154,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" @@ -166,10 +167,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 mkdir -p "$DOTFILE_DIR" ln -s "$REALFILE" "$DOTFILE" fi