#1587 - Fix: Remove temporary Go tools directory#1588
#1587 - Fix: Remove temporary Go tools directory#1588gvatsal60 wants to merge 2 commits intodevcontainers:mainfrom
Conversation
There was a problem hiding this comment.
Pull request overview
Refactors the Go feature’s tool-install flow to ensure the temporary GOPATH directory used for building Go tools is handled consistently and fully cleaned up, addressing reported leftover cache/module artifacts in built images.
Changes:
- Switches GOCACHE to be derived from GOPATH (
${GOPATH}/cache) and uses${GOPATH}consistently for temp directory operations. - Moves installed tool binaries from
${GOPATH}/bininto${TARGET_GOPATH}/bin. - Adds an unconditional cleanup step to remove the temporary Go tools directory after tool and golangci-lint installation.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| fi | ||
|
|
||
| # Remove Go tools temp directory | ||
| rm -rf ${GOPATH} |
There was a problem hiding this comment.
rm -rf ${GOPATH} is unquoted and unguarded. Since this runs under set -e and is now unconditional, it’s safer to use rm -rf -- "${GOPATH}" and optionally add a defensive check (e.g., non-empty and expected /tmp/... prefix) to avoid accidental deletion if GOPATH is ever changed/overridden.
| rm -rf ${GOPATH} | |
| if [ -n "${GOPATH}" ] && [[ "${GOPATH}" == /tmp/gotools* ]]; then | |
| rm -rf -- "${GOPATH}" | |
| fi |
There was a problem hiding this comment.
Hi @gvatsal60
Thank you for the contribution. Would you please bump the go feature version and is there any problem you foresee with implementing this suggestion?
Issue: #1587
This pull request refactors the Go tools installation process in
src/go/install.shto improve directory handling and cleanup. The changes mainly focus on using a consistent temporary directory for Go tools, updating environment variables, and ensuring proper cleanup after installation.Improvements to directory management and environment variables:
GOPATHvariable consistently, updated theGOCACHEassignment, and ensured all related directories are created before use.${GOPATH}/binpath instead of a hardcoded/tmp/gotools/binpath.Cleanup enhancements:
${GOPATH}) after installation is complete, ensuring no leftover files remain.