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

Fix missing symlinks on MacOS #27603

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
21 changes: 19 additions & 2 deletions go/install/install_darwin.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ import (
"github.com/keybase/client/go/logger"
"github.com/keybase/client/go/mounter"
"github.com/keybase/client/go/protocol/keybase1"

"golang.org/x/sys/unix"
)

// defaultLaunchdWait is how long we should wait after install & start.
Expand Down Expand Up @@ -697,8 +699,23 @@ func createCommandLine(binPath string, linkPath string, log Log) error {
}
}

log.Info("Linking %s to %s", linkPath, binPath)
return os.Symlink(binPath, linkPath)
dirPath := filepath.Dir(linkPath)

if err := unix.Access(dirPath, unix.W_OK); err != nil {
log.Info("Directory %s is not writable, using sudo to create symlink", dirPath)
cmd := exec.Command("/bin/sh", "-c", fmt.Sprintf("sudo ln -s %s %s", binPath, linkPath))
output, err := cmd.CombinedOutput()
if err != nil {
log.Error("Failed to create symlink with sudo: %s", string(output))
return err
}
log.Info("Symlink created with sudo")

return nil
} else {
log.Info("Linking %s to %s", linkPath, binPath)
return os.Symlink(binPath, linkPath)
}
}

func installCommandLineForBinPath(binPath string, linkPath string, force bool, log Log) error {
Expand Down