diff --git a/install.sh b/install.sh index c27ca0c..a6e02df 100755 --- a/install.sh +++ b/install.sh @@ -136,6 +136,15 @@ replace_dir() { link_dotfile() { source_path=$1 target_path=$2 + resolved_source_path=$(cd "$(dirname "$source_path")" && pwd)/$(basename "$source_path") + target_parent=$(dirname "$target_path") + resolved_target_parent=$(cd "$target_parent" 2>/dev/null && pwd || printf '%s' "$target_parent") + resolved_target_path=$resolved_target_parent/$(basename "$target_path") + + if [ "$resolved_source_path" = "$resolved_target_path" ]; then + skip "$target_path resolves to the source path; refusing to create a self-referential symlink." + return + fi if [ -L "$target_path" ]; then current_target=$(readlink "$target_path")