runtimes: fix Go install 'mv to subdirectory of itself' when install_dir == extracted /go
Go official tarball always extracts to <parent>/go. The old code always ran 'mv <parent>/go <install_dir>', which errors with 'cannot move /opt/go to a subdirectory of itself' when install_dir equals the extraction target (the default /opt/go). Only emit the mv when install_dir differs from the tar extraction path.
This commit is contained in:
+12
-2
@@ -304,9 +304,19 @@ class GoLang(Generator):
|
||||
out.append('log "Installing Go ' + ver + '..."')
|
||||
out.append('cd /tmp')
|
||||
out.append('curl -fsSL -O https://go.dev/dl/go' + ver + '.linux-amd64.tar.gz')
|
||||
# Go 官方 tarball 解压后固定得到 <父目录>/go
|
||||
parent = d.rsplit('/', 1)[0] if '/' in d else '/opt'
|
||||
extracted = parent.rstrip('/') + '/go'
|
||||
if extracted == d.rstrip('/'):
|
||||
# install_dir 恰好等于解压目标(/opt/go), 无需再 mv
|
||||
out.append('rm -rf ' + d)
|
||||
out.append('tar -C ' + d.rsplit('/', 1)[0] + ' -xzf go' + ver + '.linux-amd64.tar.gz')
|
||||
out.append('mv ' + d.rsplit('/', 1)[0] + '/go ' + d)
|
||||
out.append('tar -C ' + parent + ' -xzf go' + ver + '.linux-amd64.tar.gz')
|
||||
else:
|
||||
# install_dir 与解压目录不同(如 /usr/local/go), 先解压到临时父目录再移动
|
||||
out.append('rm -rf ' + d)
|
||||
out.append('rm -rf ' + parent + '/go')
|
||||
out.append('tar -C ' + parent + ' -xzf go' + ver + '.linux-amd64.tar.gz')
|
||||
out.append('mv ' + extracted + ' ' + d)
|
||||
out.append('rm -f go' + ver + '.linux-amd64.tar.gz')
|
||||
if sym:
|
||||
out.append('for b in ' + d + '/bin/*; do ln -sf "$b" /usr/local/bin/"$(basename "$b")"; done')
|
||||
|
||||
Reference in New Issue
Block a user