Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion bin/dotsync
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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
Expand Down