From b9bd50c8695b7beac69daccc1a0ae12cbed37aa6 Mon Sep 17 00:00:00 2001 From: cnbug Date: Thu, 6 Aug 2026 14:03:25 +0800 Subject: [PATCH] runtimes: fix Go install 'mv to subdirectory of itself' when install_dir == extracted /go Go official tarball always extracts to /go. The old code always ran 'mv /go ', 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. --- generators/runtimes.py | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/generators/runtimes.py b/generators/runtimes.py index cbeb37a..6014fc1 100644 --- a/generators/runtimes.py +++ b/generators/runtimes.py @@ -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') - 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) + # 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 ' + 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')