aboutsummaryrefslogtreecommitdiff
path: root/src/cmd/internal/script/scripttest
diff options
context:
space:
mode:
authorIan Alexander <jitsu@google.com>2025-05-13 12:41:36 -0400
committerIan Alexander <jitsu@google.com>2025-05-14 10:10:33 -0700
commit9856afa77042d901288845f31c79885ba68da464 (patch)
tree7c1255d1ff2710df93ada9445a1365921891dddd /src/cmd/internal/script/scripttest
parent5bbac667c5c7bd1bde1750586c92f5932134c871 (diff)
downloadgo-9856afa77042d901288845f31c79885ba68da464.tar.xz
cmd/internal/script: fix copying directory when symlink fails
The change fixes `linkOrCopy` to work on systems wihtout symlinks, when copying directories. This was originally noticed on Windows systems when the user did not have admin privs. Fixes #73692 Change-Id: I8ca66d65e99433ad38e70314abfabafd43794b79 Reviewed-on: https://go-review.googlesource.com/c/go/+/672275 Reviewed-by: Michael Matloob <matloob@golang.org> Reviewed-by: Michael Matloob <matloob@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Diffstat (limited to 'src/cmd/internal/script/scripttest')
-rw-r--r--src/cmd/internal/script/scripttest/setup.go10
1 files changed, 10 insertions, 0 deletions
diff --git a/src/cmd/internal/script/scripttest/setup.go b/src/cmd/internal/script/scripttest/setup.go
index 2826b56e87..f9d650af1c 100644
--- a/src/cmd/internal/script/scripttest/setup.go
+++ b/src/cmd/internal/script/scripttest/setup.go
@@ -114,6 +114,16 @@ func linkOrCopy(t *testing.T, src, dst string) {
if err == nil {
return
}
+ fi, err := os.Stat(src)
+ if err != nil {
+ t.Fatalf("copying %s to %s: %v", src, dst, err)
+ }
+ if fi.IsDir() {
+ if err := os.CopyFS(dst, os.DirFS(src)); err != nil {
+ t.Fatalf("copying %s to %s: %v", src, dst, err)
+ }
+ return
+ }
srcf, err := os.Open(src)
if err != nil {
t.Fatalf("copying %s to %s: %v", src, dst, err)