]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/internal/script: fix copying directory when symlink fails
authorIan Alexander <jitsu@google.com>
Tue, 13 May 2025 16:41:36 +0000 (12:41 -0400)
committerIan Alexander <jitsu@google.com>
Wed, 14 May 2025 17:10:33 +0000 (10:10 -0700)
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>

src/cmd/internal/script/scripttest/setup.go

index 2826b56e87edb249aa5be47d6a1728ec27f73fd0..f9d650af1c48fc52753cee55fba697e71e14853c 100644 (file)
@@ -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)