Skip to content

Commit 53c9b90

Browse files
committed
create binary symlinks with relative location
since the installed binary as well as the symlink reside in the same directory, relative paths should be safe to use without having to worry about crossing filesystem boundaries. closes #158
1 parent a73034c commit 53c9b90

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

get.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -806,7 +806,8 @@ func install(ctx context.Context, logger *log.Logger, r *runner.Runner, modDir s
806806
}
807807

808808
// go install does not define -modfile flag, so we mimic go install with go build -o instead.
809-
binPath := filepath.Join(gobin, fmt.Sprintf("%s-%s", name, pkg.Module.Version))
809+
binName := fmt.Sprintf("%s-%s", name, pkg.Module.Version)
810+
binPath := filepath.Join(gobin, binName)
810811

811812
// New context with new environment files.
812813
modCtx = r.With(ctx, modFile.Filepath(), modDir, pkg.BuildEnvs)
@@ -825,10 +826,11 @@ func install(ctx context.Context, logger *log.Logger, r *runner.Runner, modDir s
825826
return nil
826827
}
827828

828-
if err := os.RemoveAll(filepath.Join(gobin, name)); err != nil {
829+
lnPath := filepath.Join(gobin, name)
830+
if err := os.RemoveAll(lnPath); err != nil {
829831
return errors.Wrap(err, "rm")
830832
}
831-
if err := os.Symlink(binPath, filepath.Join(gobin, name)); err != nil {
833+
if err := os.Symlink(binName, lnPath); err != nil {
832834
return errors.Wrap(err, "symlink")
833835
}
834836
return nil

0 commit comments

Comments
 (0)