Skip to content

Commit 961631a

Browse files
xieyuschengopherbot
authored andcommitted
internal/testfiles: replace outdated function with os.CopyFS
Change-Id: I3e8ccfa7e529a8e0c7469fde580edb02035cbfb9 Reviewed-on: https://go-review.googlesource.com/c/tools/+/660335 LUCI-TryBot-Result: Go LUCI <[email protected]> Reviewed-by: Dmitri Shuralyov <[email protected]> Reviewed-by: Alan Donovan <[email protected]> Auto-Submit: Alan Donovan <[email protected]>
1 parent bf12eb7 commit 961631a

File tree

1 file changed

+1
-29
lines changed

1 file changed

+1
-29
lines changed

internal/testfiles/testfiles.go

Lines changed: 1 addition & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
package testfiles
88

99
import (
10-
"io"
1110
"io/fs"
1211
"os"
1312
"path/filepath"
@@ -46,7 +45,7 @@ import (
4645
func CopyToTmp(t testing.TB, src fs.FS, rename ...string) string {
4746
dstdir := t.TempDir()
4847

49-
if err := copyFS(dstdir, src); err != nil {
48+
if err := os.CopyFS(dstdir, src); err != nil {
5049
t.Fatal(err)
5150
}
5251
for _, r := range rename {
@@ -64,33 +63,6 @@ func CopyToTmp(t testing.TB, src fs.FS, rename ...string) string {
6463
return dstdir
6564
}
6665

67-
// Copy the files in src to dst.
68-
// Use os.CopyFS when 1.23 can be used in x/tools.
69-
func copyFS(dstdir string, src fs.FS) error {
70-
return fs.WalkDir(src, ".", func(path string, d fs.DirEntry, err error) error {
71-
if err != nil {
72-
return err
73-
}
74-
newpath := filepath.Join(dstdir, path)
75-
if d.IsDir() {
76-
return os.MkdirAll(newpath, 0777)
77-
}
78-
r, err := src.Open(path)
79-
if err != nil {
80-
return err
81-
}
82-
defer r.Close()
83-
84-
w, err := os.Create(newpath)
85-
if err != nil {
86-
return err
87-
}
88-
defer w.Close()
89-
_, err = io.Copy(w, r)
90-
return err
91-
})
92-
}
93-
9466
// ExtractTxtarFileToTmp read a txtar archive on a given path,
9567
// extracts it to a temporary directory, and returns the
9668
// temporary directory.

0 commit comments

Comments
 (0)