From 3cb1dc619e2af58ddaf374858f230d04c05b1eee Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Thu, 12 Mar 2026 08:28:36 +0000 Subject: [PATCH] fix(go): use early returns in pkg_link for clarity Co-authored-by: coolaj86 <122831+coolaj86@users.noreply.github.com> --- go/install.sh | 46 +++++++++++++++++++++++++++++----------------- golang/install.sh | 46 +++++++++++++++++++++++++++++----------------- 2 files changed, 58 insertions(+), 34 deletions(-) diff --git a/go/install.sh b/go/install.sh index b759de2..fb5aa40 100644 --- a/go/install.sh +++ b/go/install.sh @@ -41,26 +41,38 @@ pkg_link() { # all Go versions, so ~/go is kept stable rather than being swapped to a # versioned directory on each upgrade. b_gobin_stable="${HOME}/.local/opt/go-bin" + + # New install: create ~/go as a real directory (not a symlink) if ! test -e "$GOBIN" && ! test -L "$GOBIN"; then - # New install: create ~/go as a real directory (not a symlink) mkdir -p "$GOBIN/bin" - elif test -L "$GOBIN"; then - b_old_target="$(readlink "$GOBIN")" - if test "$b_old_target" != "$b_gobin_stable" && test -d "$b_old_target"; then - # Migrate from old versioned-symlink (e.g. go-bin-v1.14.2): - # rename the versioned directory to the stable unversioned path - # so that all installed tools are preserved on upgrade. - mv "$b_old_target" "$b_gobin_stable" - rm -f "$GOBIN" - ln -s "$b_gobin_stable" "$GOBIN" - elif ! test -d "$b_old_target"; then - # Symlink target is gone; recreate ~/go as a real directory - rm -f "$GOBIN" - mkdir -p "$GOBIN/bin" - fi - # If already pointing to the stable unversioned dir, do nothing + return fi - # If $GOBIN is already a real directory, leave it alone + + # Real directory: leave it alone + if ! test -L "$GOBIN"; then + return + fi + + b_old_target="$(readlink "$GOBIN")" + + # Already pointing to the stable unversioned dir: nothing to do + if test "$b_old_target" = "$b_gobin_stable"; then + return + fi + + # Migrate from old versioned-symlink (e.g. go-bin-v1.14.2): + # rename the versioned directory to the stable unversioned path + # so that all installed tools are preserved on upgrade. + if test -d "$b_old_target"; then + mv "$b_old_target" "$b_gobin_stable" + rm -f "$GOBIN" + ln -s "$b_gobin_stable" "$GOBIN" + return + fi + + # Symlink target is gone; recreate ~/go as a real directory + rm -f "$GOBIN" + mkdir -p "$GOBIN/bin" } pkg_post_install() { diff --git a/golang/install.sh b/golang/install.sh index b759de2..fb5aa40 100644 --- a/golang/install.sh +++ b/golang/install.sh @@ -41,26 +41,38 @@ pkg_link() { # all Go versions, so ~/go is kept stable rather than being swapped to a # versioned directory on each upgrade. b_gobin_stable="${HOME}/.local/opt/go-bin" + + # New install: create ~/go as a real directory (not a symlink) if ! test -e "$GOBIN" && ! test -L "$GOBIN"; then - # New install: create ~/go as a real directory (not a symlink) mkdir -p "$GOBIN/bin" - elif test -L "$GOBIN"; then - b_old_target="$(readlink "$GOBIN")" - if test "$b_old_target" != "$b_gobin_stable" && test -d "$b_old_target"; then - # Migrate from old versioned-symlink (e.g. go-bin-v1.14.2): - # rename the versioned directory to the stable unversioned path - # so that all installed tools are preserved on upgrade. - mv "$b_old_target" "$b_gobin_stable" - rm -f "$GOBIN" - ln -s "$b_gobin_stable" "$GOBIN" - elif ! test -d "$b_old_target"; then - # Symlink target is gone; recreate ~/go as a real directory - rm -f "$GOBIN" - mkdir -p "$GOBIN/bin" - fi - # If already pointing to the stable unversioned dir, do nothing + return fi - # If $GOBIN is already a real directory, leave it alone + + # Real directory: leave it alone + if ! test -L "$GOBIN"; then + return + fi + + b_old_target="$(readlink "$GOBIN")" + + # Already pointing to the stable unversioned dir: nothing to do + if test "$b_old_target" = "$b_gobin_stable"; then + return + fi + + # Migrate from old versioned-symlink (e.g. go-bin-v1.14.2): + # rename the versioned directory to the stable unversioned path + # so that all installed tools are preserved on upgrade. + if test -d "$b_old_target"; then + mv "$b_old_target" "$b_gobin_stable" + rm -f "$GOBIN" + ln -s "$b_gobin_stable" "$GOBIN" + return + fi + + # Symlink target is gone; recreate ~/go as a real directory + rm -f "$GOBIN" + mkdir -p "$GOBIN/bin" } pkg_post_install() {