Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Overwrite broken links #19

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
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