Skip to content

Commit 9856afa

Browse files
committed
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>
1 parent 5bbac66 commit 9856afa

File tree

1 file changed

+10
-0
lines changed
  • src/cmd/internal/script/scripttest

1 file changed

+10
-0
lines changed

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,16 @@ func linkOrCopy(t *testing.T, src, dst string) {
114114
if err == nil {
115115
return
116116
}
117+
fi, err := os.Stat(src)
118+
if err != nil {
119+
t.Fatalf("copying %s to %s: %v", src, dst, err)
120+
}
121+
if fi.IsDir() {
122+
if err := os.CopyFS(dst, os.DirFS(src)); err != nil {
123+
t.Fatalf("copying %s to %s: %v", src, dst, err)
124+
}
125+
return
126+
}
117127
srcf, err := os.Open(src)
118128
if err != nil {
119129
t.Fatalf("copying %s to %s: %v", src, dst, err)

0 commit comments

Comments
 (0)