mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
all: update to use os.ReadFile, os.WriteFile, os.CreateTemp, os.MkdirTemp
As part of #42026, these helpers from io/ioutil were moved to os. (ioutil.TempFile and TempDir became os.CreateTemp and MkdirTemp.) Update the Go tree to use the preferred names. As usual, code compiled with the Go 1.4 bootstrap toolchain and code vendored from other sources is excluded. ReadDir changes are in a separate CL, because they are not a simple search and replace. For #42026. Change-Id: If318df0216d57e95ea0c4093b89f65e5b0ababb3 Reviewed-on: https://go-review.googlesource.com/c/go/+/266365 Trust: Russ Cox <rsc@golang.org> Run-TryBot: Russ Cox <rsc@golang.org> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Ian Lance Taylor <iant@golang.org>
This commit is contained in:
parent
5627a4dc30
commit
4f1b0a44cb
215 changed files with 556 additions and 704 deletions
|
|
@ -10,7 +10,6 @@ import (
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"io/ioutil"
|
|
||||||
"math"
|
"math"
|
||||||
"os"
|
"os"
|
||||||
"path"
|
"path"
|
||||||
|
|
@ -773,7 +772,7 @@ func TestReadTruncation(t *testing.T) {
|
||||||
"testdata/pax-path-hdr.tar",
|
"testdata/pax-path-hdr.tar",
|
||||||
"testdata/sparse-formats.tar",
|
"testdata/sparse-formats.tar",
|
||||||
} {
|
} {
|
||||||
buf, err := ioutil.ReadFile(p)
|
buf, err := os.ReadFile(p)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("unexpected error: %v", err)
|
t.Fatalf("unexpected error: %v", err)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -11,7 +11,6 @@ import (
|
||||||
"internal/testenv"
|
"internal/testenv"
|
||||||
"io"
|
"io"
|
||||||
"io/fs"
|
"io/fs"
|
||||||
"io/ioutil"
|
|
||||||
"math"
|
"math"
|
||||||
"os"
|
"os"
|
||||||
"path"
|
"path"
|
||||||
|
|
@ -263,7 +262,7 @@ func TestFileInfoHeaderDir(t *testing.T) {
|
||||||
func TestFileInfoHeaderSymlink(t *testing.T) {
|
func TestFileInfoHeaderSymlink(t *testing.T) {
|
||||||
testenv.MustHaveSymlink(t)
|
testenv.MustHaveSymlink(t)
|
||||||
|
|
||||||
tmpdir, err := ioutil.TempDir("", "TestFileInfoHeaderSymlink")
|
tmpdir, err := os.MkdirTemp("", "TestFileInfoHeaderSymlink")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -9,7 +9,6 @@ import (
|
||||||
"encoding/hex"
|
"encoding/hex"
|
||||||
"errors"
|
"errors"
|
||||||
"io"
|
"io"
|
||||||
"io/ioutil"
|
|
||||||
"os"
|
"os"
|
||||||
"path"
|
"path"
|
||||||
"reflect"
|
"reflect"
|
||||||
|
|
@ -520,7 +519,7 @@ func TestWriter(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if v.file != "" {
|
if v.file != "" {
|
||||||
want, err := ioutil.ReadFile(v.file)
|
want, err := os.ReadFile(v.file)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("ReadFile() = %v, want nil", err)
|
t.Fatalf("ReadFile() = %v, want nil", err)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -11,7 +11,6 @@ import (
|
||||||
"internal/obscuretestdata"
|
"internal/obscuretestdata"
|
||||||
"io"
|
"io"
|
||||||
"io/fs"
|
"io/fs"
|
||||||
"io/ioutil"
|
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"regexp"
|
"regexp"
|
||||||
|
|
@ -629,7 +628,7 @@ func readTestFile(t *testing.T, zt ZipTest, ft ZipTestFile, f *File) {
|
||||||
var c []byte
|
var c []byte
|
||||||
if ft.Content != nil {
|
if ft.Content != nil {
|
||||||
c = ft.Content
|
c = ft.Content
|
||||||
} else if c, err = ioutil.ReadFile("testdata/" + ft.File); err != nil {
|
} else if c, err = os.ReadFile("testdata/" + ft.File); err != nil {
|
||||||
t.Error(err)
|
t.Error(err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
@ -685,7 +684,7 @@ func TestInvalidFiles(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func messWith(fileName string, corrupter func(b []byte)) (r io.ReaderAt, size int64) {
|
func messWith(fileName string, corrupter func(b []byte)) (r io.ReaderAt, size int64) {
|
||||||
data, err := ioutil.ReadFile(filepath.Join("testdata", fileName))
|
data, err := os.ReadFile(filepath.Join("testdata", fileName))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic("Error reading " + fileName + ": " + err.Error())
|
panic("Error reading " + fileName + ": " + err.Error())
|
||||||
}
|
}
|
||||||
|
|
@ -792,17 +791,17 @@ func returnRecursiveZip() (r io.ReaderAt, size int64) {
|
||||||
//
|
//
|
||||||
// func main() {
|
// func main() {
|
||||||
// bigZip := makeZip("big.file", io.LimitReader(zeros{}, 1<<32-1))
|
// bigZip := makeZip("big.file", io.LimitReader(zeros{}, 1<<32-1))
|
||||||
// if err := ioutil.WriteFile("/tmp/big.zip", bigZip, 0666); err != nil {
|
// if err := os.WriteFile("/tmp/big.zip", bigZip, 0666); err != nil {
|
||||||
// log.Fatal(err)
|
// log.Fatal(err)
|
||||||
// }
|
// }
|
||||||
//
|
//
|
||||||
// biggerZip := makeZip("big.zip", bytes.NewReader(bigZip))
|
// biggerZip := makeZip("big.zip", bytes.NewReader(bigZip))
|
||||||
// if err := ioutil.WriteFile("/tmp/bigger.zip", biggerZip, 0666); err != nil {
|
// if err := os.WriteFile("/tmp/bigger.zip", biggerZip, 0666); err != nil {
|
||||||
// log.Fatal(err)
|
// log.Fatal(err)
|
||||||
// }
|
// }
|
||||||
//
|
//
|
||||||
// biggestZip := makeZip("bigger.zip", bytes.NewReader(biggerZip))
|
// biggestZip := makeZip("bigger.zip", bytes.NewReader(biggerZip))
|
||||||
// if err := ioutil.WriteFile("/tmp/biggest.zip", biggestZip, 0666); err != nil {
|
// if err := os.WriteFile("/tmp/biggest.zip", biggestZip, 0666); err != nil {
|
||||||
// log.Fatal(err)
|
// log.Fatal(err)
|
||||||
// }
|
// }
|
||||||
// }
|
// }
|
||||||
|
|
|
||||||
|
|
@ -10,8 +10,8 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"io/fs"
|
"io/fs"
|
||||||
"io/ioutil"
|
|
||||||
"math/rand"
|
"math/rand"
|
||||||
|
"os"
|
||||||
"strings"
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
@ -237,7 +237,7 @@ func TestWriterTime(t *testing.T) {
|
||||||
t.Fatalf("unexpected Close error: %v", err)
|
t.Fatalf("unexpected Close error: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
want, err := ioutil.ReadFile("testdata/time-go.zip")
|
want, err := os.ReadFile("testdata/time-go.zip")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("unexpected ReadFile error: %v", err)
|
t.Fatalf("unexpected ReadFile error: %v", err)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -8,7 +8,6 @@ import (
|
||||||
"bufio"
|
"bufio"
|
||||||
"bytes"
|
"bytes"
|
||||||
"internal/testenv"
|
"internal/testenv"
|
||||||
"io/ioutil"
|
|
||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
|
@ -98,8 +97,8 @@ func testAddr2Line(t *testing.T, exepath, addr string) {
|
||||||
if !os.SameFile(fi1, fi2) {
|
if !os.SameFile(fi1, fi2) {
|
||||||
t.Fatalf("addr2line_test.go and %s are not same file", srcPath)
|
t.Fatalf("addr2line_test.go and %s are not same file", srcPath)
|
||||||
}
|
}
|
||||||
if srcLineNo != "107" {
|
if srcLineNo != "106" {
|
||||||
t.Fatalf("line number = %v; want 107", srcLineNo)
|
t.Fatalf("line number = %v; want 106", srcLineNo)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -107,7 +106,7 @@ func testAddr2Line(t *testing.T, exepath, addr string) {
|
||||||
func TestAddr2Line(t *testing.T) {
|
func TestAddr2Line(t *testing.T) {
|
||||||
testenv.MustHaveGoBuild(t)
|
testenv.MustHaveGoBuild(t)
|
||||||
|
|
||||||
tmpDir, err := ioutil.TempDir("", "TestAddr2Line")
|
tmpDir, err := os.MkdirTemp("", "TestAddr2Line")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal("TempDir failed: ", err)
|
t.Fatal("TempDir failed: ", err)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -17,7 +17,6 @@ import (
|
||||||
"go/token"
|
"go/token"
|
||||||
"go/types"
|
"go/types"
|
||||||
"io"
|
"io"
|
||||||
"io/ioutil"
|
|
||||||
"log"
|
"log"
|
||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
|
|
@ -342,7 +341,7 @@ func fileFeatures(filename string) []string {
|
||||||
if filename == "" {
|
if filename == "" {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
bs, err := ioutil.ReadFile(filename)
|
bs, err := os.ReadFile(filename)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatalf("Error reading file %s: %v", filename, err)
|
log.Fatalf("Error reading file %s: %v", filename, err)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -9,7 +9,6 @@ import (
|
||||||
"flag"
|
"flag"
|
||||||
"fmt"
|
"fmt"
|
||||||
"go/build"
|
"go/build"
|
||||||
"io/ioutil"
|
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"sort"
|
"sort"
|
||||||
|
|
@ -75,7 +74,7 @@ func TestGolden(t *testing.T) {
|
||||||
f.Close()
|
f.Close()
|
||||||
}
|
}
|
||||||
|
|
||||||
bs, err := ioutil.ReadFile(goldenFile)
|
bs, err := os.ReadFile(goldenFile)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("opening golden.txt for package %q: %v", fi.Name(), err)
|
t.Fatalf("opening golden.txt for package %q: %v", fi.Name(), err)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -12,7 +12,6 @@ import (
|
||||||
"go/parser"
|
"go/parser"
|
||||||
"go/token"
|
"go/token"
|
||||||
"io"
|
"io"
|
||||||
"io/ioutil"
|
|
||||||
"log"
|
"log"
|
||||||
"os"
|
"os"
|
||||||
"sort"
|
"sort"
|
||||||
|
|
@ -304,7 +303,7 @@ func (f *File) Visit(node ast.Node) ast.Visitor {
|
||||||
|
|
||||||
func annotate(name string) {
|
func annotate(name string) {
|
||||||
fset := token.NewFileSet()
|
fset := token.NewFileSet()
|
||||||
content, err := ioutil.ReadFile(name)
|
content, err := os.ReadFile(name)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatalf("cover: %s: %s", name, err)
|
log.Fatalf("cover: %s: %s", name, err)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -13,7 +13,6 @@ import (
|
||||||
"go/parser"
|
"go/parser"
|
||||||
"go/token"
|
"go/token"
|
||||||
"internal/testenv"
|
"internal/testenv"
|
||||||
"io/ioutil"
|
|
||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
|
@ -81,7 +80,7 @@ var debug = flag.Bool("debug", false, "keep rewritten files for debugging")
|
||||||
// We use TestMain to set up a temporary directory and remove it when
|
// We use TestMain to set up a temporary directory and remove it when
|
||||||
// the tests are done.
|
// the tests are done.
|
||||||
func TestMain(m *testing.M) {
|
func TestMain(m *testing.M) {
|
||||||
dir, err := ioutil.TempDir("", "go-testcover")
|
dir, err := os.MkdirTemp("", "go-testcover")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Fprintln(os.Stderr, err)
|
fmt.Fprintln(os.Stderr, err)
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
|
|
@ -173,7 +172,7 @@ func TestCover(t *testing.T) {
|
||||||
buildCover(t)
|
buildCover(t)
|
||||||
|
|
||||||
// Read in the test file (testTest) and write it, with LINEs specified, to coverInput.
|
// Read in the test file (testTest) and write it, with LINEs specified, to coverInput.
|
||||||
file, err := ioutil.ReadFile(testTest)
|
file, err := os.ReadFile(testTest)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
@ -192,7 +191,7 @@ func TestCover(t *testing.T) {
|
||||||
[]byte("}"))
|
[]byte("}"))
|
||||||
lines = append(lines, []byte("func unFormatted2(b bool) {if b{}else{}}"))
|
lines = append(lines, []byte("func unFormatted2(b bool) {if b{}else{}}"))
|
||||||
|
|
||||||
if err := ioutil.WriteFile(coverInput, bytes.Join(lines, []byte("\n")), 0666); err != nil {
|
if err := os.WriteFile(coverInput, bytes.Join(lines, []byte("\n")), 0666); err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -208,11 +207,11 @@ func TestCover(t *testing.T) {
|
||||||
|
|
||||||
// Copy testmain to testTempDir, so that it is in the same directory
|
// Copy testmain to testTempDir, so that it is in the same directory
|
||||||
// as coverOutput.
|
// as coverOutput.
|
||||||
b, err := ioutil.ReadFile(testMain)
|
b, err := os.ReadFile(testMain)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
if err := ioutil.WriteFile(tmpTestMain, b, 0444); err != nil {
|
if err := os.WriteFile(tmpTestMain, b, 0444); err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -220,7 +219,7 @@ func TestCover(t *testing.T) {
|
||||||
cmd = exec.Command(testenv.GoToolPath(t), "run", tmpTestMain, coverOutput)
|
cmd = exec.Command(testenv.GoToolPath(t), "run", tmpTestMain, coverOutput)
|
||||||
run(cmd, t)
|
run(cmd, t)
|
||||||
|
|
||||||
file, err = ioutil.ReadFile(coverOutput)
|
file, err = os.ReadFile(coverOutput)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
@ -251,7 +250,7 @@ func TestDirectives(t *testing.T) {
|
||||||
// Read the source file and find all the directives. We'll keep
|
// Read the source file and find all the directives. We'll keep
|
||||||
// track of whether each one has been seen in the output.
|
// track of whether each one has been seen in the output.
|
||||||
testDirectives := filepath.Join(testdata, "directives.go")
|
testDirectives := filepath.Join(testdata, "directives.go")
|
||||||
source, err := ioutil.ReadFile(testDirectives)
|
source, err := os.ReadFile(testDirectives)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
@ -398,7 +397,7 @@ func TestCoverHTML(t *testing.T) {
|
||||||
|
|
||||||
// Extract the parts of the HTML with comment markers,
|
// Extract the parts of the HTML with comment markers,
|
||||||
// and compare against a golden file.
|
// and compare against a golden file.
|
||||||
entireHTML, err := ioutil.ReadFile(htmlHTML)
|
entireHTML, err := os.ReadFile(htmlHTML)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
@ -420,7 +419,7 @@ func TestCoverHTML(t *testing.T) {
|
||||||
if scan.Err() != nil {
|
if scan.Err() != nil {
|
||||||
t.Error(scan.Err())
|
t.Error(scan.Err())
|
||||||
}
|
}
|
||||||
golden, err := ioutil.ReadFile(htmlGolden)
|
golden, err := os.ReadFile(htmlGolden)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("reading golden file: %v", err)
|
t.Fatalf("reading golden file: %v", err)
|
||||||
}
|
}
|
||||||
|
|
@ -457,7 +456,7 @@ func TestHtmlUnformatted(t *testing.T) {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := ioutil.WriteFile(filepath.Join(htmlUDir, "go.mod"), []byte("module htmlunformatted\n"), 0666); err != nil {
|
if err := os.WriteFile(filepath.Join(htmlUDir, "go.mod"), []byte("module htmlunformatted\n"), 0666); err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -474,10 +473,10 @@ lab:
|
||||||
|
|
||||||
const htmlUTestContents = `package htmlunformatted`
|
const htmlUTestContents = `package htmlunformatted`
|
||||||
|
|
||||||
if err := ioutil.WriteFile(htmlU, []byte(htmlUContents), 0444); err != nil {
|
if err := os.WriteFile(htmlU, []byte(htmlUContents), 0444); err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
if err := ioutil.WriteFile(htmlUTest, []byte(htmlUTestContents), 0444); err != nil {
|
if err := os.WriteFile(htmlUTest, []byte(htmlUTestContents), 0444); err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -540,13 +539,13 @@ func TestFuncWithDuplicateLines(t *testing.T) {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := ioutil.WriteFile(filepath.Join(lineDupDir, "go.mod"), []byte("module linedup\n"), 0666); err != nil {
|
if err := os.WriteFile(filepath.Join(lineDupDir, "go.mod"), []byte("module linedup\n"), 0666); err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
if err := ioutil.WriteFile(lineDupGo, []byte(lineDupContents), 0444); err != nil {
|
if err := os.WriteFile(lineDupGo, []byte(lineDupContents), 0444); err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
if err := ioutil.WriteFile(lineDupTestGo, []byte(lineDupTestContents), 0444); err != nil {
|
if err := os.WriteFile(lineDupTestGo, []byte(lineDupTestContents), 0444); err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -11,7 +11,6 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"html/template"
|
"html/template"
|
||||||
"io"
|
"io"
|
||||||
"io/ioutil"
|
|
||||||
"math"
|
"math"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
|
@ -43,7 +42,7 @@ func htmlOutput(profile, outfile string) error {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
src, err := ioutil.ReadFile(file)
|
src, err := os.ReadFile(file)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("can't read %q: %v", fn, err)
|
return fmt.Errorf("can't read %q: %v", fn, err)
|
||||||
}
|
}
|
||||||
|
|
@ -62,7 +61,7 @@ func htmlOutput(profile, outfile string) error {
|
||||||
var out *os.File
|
var out *os.File
|
||||||
if outfile == "" {
|
if outfile == "" {
|
||||||
var dir string
|
var dir string
|
||||||
dir, err = ioutil.TempDir("", "cover")
|
dir, err = os.MkdirTemp("", "cover")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -15,7 +15,6 @@ import (
|
||||||
"go/token"
|
"go/token"
|
||||||
"io"
|
"io"
|
||||||
"io/fs"
|
"io/fs"
|
||||||
"io/ioutil"
|
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"sort"
|
"sort"
|
||||||
|
|
@ -217,7 +216,7 @@ func processFile(filename string, useStdin bool) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
return ioutil.WriteFile(f.Name(), newSrc, 0)
|
return os.WriteFile(f.Name(), newSrc, 0)
|
||||||
}
|
}
|
||||||
|
|
||||||
func gofmt(n interface{}) string {
|
func gofmt(n interface{}) string {
|
||||||
|
|
|
||||||
|
|
@ -9,7 +9,6 @@ import (
|
||||||
"go/ast"
|
"go/ast"
|
||||||
"go/parser"
|
"go/parser"
|
||||||
"go/token"
|
"go/token"
|
||||||
"io/ioutil"
|
|
||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
|
@ -162,12 +161,12 @@ func typecheck(cfg *TypeConfig, f *ast.File) (typeof map[interface{}]string, ass
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
dir, err := ioutil.TempDir(os.TempDir(), "fix_cgo_typecheck")
|
dir, err := os.MkdirTemp(os.TempDir(), "fix_cgo_typecheck")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
defer os.RemoveAll(dir)
|
defer os.RemoveAll(dir)
|
||||||
err = ioutil.WriteFile(filepath.Join(dir, "in.go"), txt, 0600)
|
err = os.WriteFile(filepath.Join(dir, "in.go"), txt, 0600)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
@ -176,7 +175,7 @@ func typecheck(cfg *TypeConfig, f *ast.File) (typeof map[interface{}]string, ass
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
out, err := ioutil.ReadFile(filepath.Join(dir, "_cgo_gotypes.go"))
|
out, err := os.ReadFile(filepath.Join(dir, "_cgo_gotypes.go"))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -17,7 +17,6 @@ import (
|
||||||
"internal/testenv"
|
"internal/testenv"
|
||||||
"io"
|
"io"
|
||||||
"io/fs"
|
"io/fs"
|
||||||
"io/ioutil"
|
|
||||||
"log"
|
"log"
|
||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
|
|
@ -100,7 +99,7 @@ func TestMain(m *testing.M) {
|
||||||
|
|
||||||
// Run with a temporary TMPDIR to check that the tests don't
|
// Run with a temporary TMPDIR to check that the tests don't
|
||||||
// leave anything behind.
|
// leave anything behind.
|
||||||
topTmpdir, err := ioutil.TempDir("", "cmd-go-test-")
|
topTmpdir, err := os.MkdirTemp("", "cmd-go-test-")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
@ -109,7 +108,7 @@ func TestMain(m *testing.M) {
|
||||||
}
|
}
|
||||||
os.Setenv(tempEnvName(), topTmpdir)
|
os.Setenv(tempEnvName(), topTmpdir)
|
||||||
|
|
||||||
dir, err := ioutil.TempDir(topTmpdir, "tmpdir")
|
dir, err := os.MkdirTemp(topTmpdir, "tmpdir")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
@ -616,7 +615,7 @@ func (tg *testgoData) makeTempdir() {
|
||||||
tg.t.Helper()
|
tg.t.Helper()
|
||||||
if tg.tempdir == "" {
|
if tg.tempdir == "" {
|
||||||
var err error
|
var err error
|
||||||
tg.tempdir, err = ioutil.TempDir("", "gotest")
|
tg.tempdir, err = os.MkdirTemp("", "gotest")
|
||||||
tg.must(err)
|
tg.must(err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -633,7 +632,7 @@ func (tg *testgoData) tempFile(path, contents string) {
|
||||||
bytes = formatted
|
bytes = formatted
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
tg.must(ioutil.WriteFile(filepath.Join(tg.tempdir, path), bytes, 0644))
|
tg.must(os.WriteFile(filepath.Join(tg.tempdir, path), bytes, 0644))
|
||||||
}
|
}
|
||||||
|
|
||||||
// tempDir adds a temporary directory for a run of testgo.
|
// tempDir adds a temporary directory for a run of testgo.
|
||||||
|
|
@ -833,7 +832,7 @@ func TestNewReleaseRebuildsStalePackagesInGOPATH(t *testing.T) {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
dest := filepath.Join("goroot", copydir, srcrel)
|
dest := filepath.Join("goroot", copydir, srcrel)
|
||||||
data, err := ioutil.ReadFile(path)
|
data, err := os.ReadFile(path)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
@ -850,18 +849,18 @@ func TestNewReleaseRebuildsStalePackagesInGOPATH(t *testing.T) {
|
||||||
tg.setenv("GOROOT", tg.path("goroot"))
|
tg.setenv("GOROOT", tg.path("goroot"))
|
||||||
|
|
||||||
addVar := func(name string, idx int) (restore func()) {
|
addVar := func(name string, idx int) (restore func()) {
|
||||||
data, err := ioutil.ReadFile(name)
|
data, err := os.ReadFile(name)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
old := data
|
old := data
|
||||||
data = append(data, fmt.Sprintf("var DummyUnusedVar%d bool\n", idx)...)
|
data = append(data, fmt.Sprintf("var DummyUnusedVar%d bool\n", idx)...)
|
||||||
if err := ioutil.WriteFile(name, append(data, '\n'), 0666); err != nil {
|
if err := os.WriteFile(name, append(data, '\n'), 0666); err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
tg.sleep()
|
tg.sleep()
|
||||||
return func() {
|
return func() {
|
||||||
if err := ioutil.WriteFile(name, old, 0666); err != nil {
|
if err := os.WriteFile(name, old, 0666); err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -2674,7 +2673,7 @@ echo $* >>`+tg.path("pkg-config.out"))
|
||||||
tg.setenv("GOPATH", tg.path("."))
|
tg.setenv("GOPATH", tg.path("."))
|
||||||
tg.setenv("PKG_CONFIG", tg.path("pkg-config.sh"))
|
tg.setenv("PKG_CONFIG", tg.path("pkg-config.sh"))
|
||||||
tg.run("build", "x")
|
tg.run("build", "x")
|
||||||
out, err := ioutil.ReadFile(tg.path("pkg-config.out"))
|
out, err := os.ReadFile(tg.path("pkg-config.out"))
|
||||||
tg.must(err)
|
tg.must(err)
|
||||||
out = bytes.TrimSpace(out)
|
out = bytes.TrimSpace(out)
|
||||||
want := "--cflags --static --static -- a a\n--libs --static --static -- a a"
|
want := "--cflags --static --static -- a a\n--libs --static --static -- a a"
|
||||||
|
|
|
||||||
|
|
@ -5,7 +5,6 @@
|
||||||
package main_test
|
package main_test
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"io/ioutil"
|
|
||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
|
@ -20,14 +19,14 @@ func TestAbsolutePath(t *testing.T) {
|
||||||
defer tg.cleanup()
|
defer tg.cleanup()
|
||||||
tg.parallel()
|
tg.parallel()
|
||||||
|
|
||||||
tmp, err := ioutil.TempDir("", "TestAbsolutePath")
|
tmp, err := os.MkdirTemp("", "TestAbsolutePath")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
defer robustio.RemoveAll(tmp)
|
defer robustio.RemoveAll(tmp)
|
||||||
|
|
||||||
file := filepath.Join(tmp, "a.go")
|
file := filepath.Join(tmp, "a.go")
|
||||||
err = ioutil.WriteFile(file, []byte{}, 0644)
|
err = os.WriteFile(file, []byte{}, 0644)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@ package main_test
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"io/ioutil"
|
"os"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"cmd/go/internal/help"
|
"cmd/go/internal/help"
|
||||||
|
|
@ -23,7 +23,7 @@ func TestDocsUpToDate(t *testing.T) {
|
||||||
buf := new(bytes.Buffer)
|
buf := new(bytes.Buffer)
|
||||||
// Match the command in mkalldocs.sh that generates alldocs.go.
|
// Match the command in mkalldocs.sh that generates alldocs.go.
|
||||||
help.Help(buf, []string{"documentation"})
|
help.Help(buf, []string{"documentation"})
|
||||||
data, err := ioutil.ReadFile("alldocs.go")
|
data, err := os.ReadFile("alldocs.go")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("error reading alldocs.go: %v", err)
|
t.Fatalf("error reading alldocs.go: %v", err)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -5,7 +5,6 @@
|
||||||
package auth
|
package auth
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"io/ioutil"
|
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"runtime"
|
"runtime"
|
||||||
|
|
@ -99,7 +98,7 @@ func readNetrc() {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
data, err := ioutil.ReadFile(path)
|
data, err := os.ReadFile(path)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if !os.IsNotExist(err) {
|
if !os.IsNotExist(err) {
|
||||||
netrcErr = err
|
netrcErr = err
|
||||||
|
|
|
||||||
|
|
@ -10,7 +10,6 @@ import (
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"io/ioutil"
|
|
||||||
urlpkg "net/url"
|
urlpkg "net/url"
|
||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
|
|
@ -117,7 +116,7 @@ func printOSDetails(w io.Writer) {
|
||||||
case "illumos", "solaris":
|
case "illumos", "solaris":
|
||||||
// Be sure to use the OS-supplied uname, in "/usr/bin":
|
// Be sure to use the OS-supplied uname, in "/usr/bin":
|
||||||
printCmdOut(w, "uname -srv: ", "/usr/bin/uname", "-srv")
|
printCmdOut(w, "uname -srv: ", "/usr/bin/uname", "-srv")
|
||||||
out, err := ioutil.ReadFile("/etc/release")
|
out, err := os.ReadFile("/etc/release")
|
||||||
if err == nil {
|
if err == nil {
|
||||||
fmt.Fprintf(w, "/etc/release: %s\n", out)
|
fmt.Fprintf(w, "/etc/release: %s\n", out)
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -177,7 +176,7 @@ func printGlibcVersion(w io.Writer) {
|
||||||
src := []byte(`int main() {}`)
|
src := []byte(`int main() {}`)
|
||||||
srcfile := filepath.Join(tempdir, "go-bug.c")
|
srcfile := filepath.Join(tempdir, "go-bug.c")
|
||||||
outfile := filepath.Join(tempdir, "go-bug")
|
outfile := filepath.Join(tempdir, "go-bug")
|
||||||
err := ioutil.WriteFile(srcfile, src, 0644)
|
err := os.WriteFile(srcfile, src, 0644)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
|
||||||
5
src/cmd/go/internal/cache/cache.go
vendored
5
src/cmd/go/internal/cache/cache.go
vendored
|
|
@ -13,7 +13,6 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"io/fs"
|
"io/fs"
|
||||||
"io/ioutil"
|
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
|
@ -239,7 +238,7 @@ func (c *Cache) GetBytes(id ActionID) ([]byte, Entry, error) {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, entry, err
|
return nil, entry, err
|
||||||
}
|
}
|
||||||
data, _ := ioutil.ReadFile(c.OutputFile(entry.OutputID))
|
data, _ := os.ReadFile(c.OutputFile(entry.OutputID))
|
||||||
if sha256.Sum256(data) != entry.OutputID {
|
if sha256.Sum256(data) != entry.OutputID {
|
||||||
return nil, entry, &entryNotFoundError{Err: errors.New("bad checksum")}
|
return nil, entry, &entryNotFoundError{Err: errors.New("bad checksum")}
|
||||||
}
|
}
|
||||||
|
|
@ -378,7 +377,7 @@ func (c *Cache) putIndexEntry(id ActionID, out OutputID, size int64, allowVerify
|
||||||
// Truncate the file only *after* writing it.
|
// Truncate the file only *after* writing it.
|
||||||
// (This should be a no-op, but truncate just in case of previous corruption.)
|
// (This should be a no-op, but truncate just in case of previous corruption.)
|
||||||
//
|
//
|
||||||
// This differs from ioutil.WriteFile, which truncates to 0 *before* writing
|
// This differs from os.WriteFile, which truncates to 0 *before* writing
|
||||||
// via os.O_TRUNC. Truncating only after writing ensures that a second write
|
// via os.O_TRUNC. Truncating only after writing ensures that a second write
|
||||||
// of the same content to the same file is idempotent, and does not — even
|
// of the same content to the same file is idempotent, and does not — even
|
||||||
// temporarily! — undo the effect of the first write.
|
// temporarily! — undo the effect of the first write.
|
||||||
|
|
|
||||||
13
src/cmd/go/internal/cache/cache_test.go
vendored
13
src/cmd/go/internal/cache/cache_test.go
vendored
|
|
@ -8,7 +8,6 @@ import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"encoding/binary"
|
"encoding/binary"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
@ -20,7 +19,7 @@ func init() {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestBasic(t *testing.T) {
|
func TestBasic(t *testing.T) {
|
||||||
dir, err := ioutil.TempDir("", "cachetest-")
|
dir, err := os.MkdirTemp("", "cachetest-")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
@ -65,7 +64,7 @@ func TestBasic(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestGrowth(t *testing.T) {
|
func TestGrowth(t *testing.T) {
|
||||||
dir, err := ioutil.TempDir("", "cachetest-")
|
dir, err := os.MkdirTemp("", "cachetest-")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
@ -118,7 +117,7 @@ func TestVerifyPanic(t *testing.T) {
|
||||||
t.Fatal("initEnv did not set verify")
|
t.Fatal("initEnv did not set verify")
|
||||||
}
|
}
|
||||||
|
|
||||||
dir, err := ioutil.TempDir("", "cachetest-")
|
dir, err := os.MkdirTemp("", "cachetest-")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
@ -151,7 +150,7 @@ func dummyID(x int) [HashSize]byte {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestCacheTrim(t *testing.T) {
|
func TestCacheTrim(t *testing.T) {
|
||||||
dir, err := ioutil.TempDir("", "cachetest-")
|
dir, err := os.MkdirTemp("", "cachetest-")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
@ -207,7 +206,7 @@ func TestCacheTrim(t *testing.T) {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
c.OutputFile(entry.OutputID)
|
c.OutputFile(entry.OutputID)
|
||||||
data, err := ioutil.ReadFile(filepath.Join(dir, "trim.txt"))
|
data, err := os.ReadFile(filepath.Join(dir, "trim.txt"))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
@ -220,7 +219,7 @@ func TestCacheTrim(t *testing.T) {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
c.OutputFile(entry.OutputID)
|
c.OutputFile(entry.OutputID)
|
||||||
data2, err := ioutil.ReadFile(filepath.Join(dir, "trim.txt"))
|
data2, err := os.ReadFile(filepath.Join(dir, "trim.txt"))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
3
src/cmd/go/internal/cache/default.go
vendored
3
src/cmd/go/internal/cache/default.go
vendored
|
|
@ -6,7 +6,6 @@ package cache
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"sync"
|
"sync"
|
||||||
|
|
@ -49,7 +48,7 @@ func initDefaultCache() {
|
||||||
}
|
}
|
||||||
if _, err := os.Stat(filepath.Join(dir, "README")); err != nil {
|
if _, err := os.Stat(filepath.Join(dir, "README")); err != nil {
|
||||||
// Best effort.
|
// Best effort.
|
||||||
ioutil.WriteFile(filepath.Join(dir, "README"), []byte(cacheREADME), 0666)
|
os.WriteFile(filepath.Join(dir, "README"), []byte(cacheREADME), 0666)
|
||||||
}
|
}
|
||||||
|
|
||||||
c, err := Open(dir)
|
c, err := Open(dir)
|
||||||
|
|
|
||||||
3
src/cmd/go/internal/cache/hash_test.go
vendored
3
src/cmd/go/internal/cache/hash_test.go
vendored
|
|
@ -6,7 +6,6 @@ package cache
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
|
||||||
"os"
|
"os"
|
||||||
"testing"
|
"testing"
|
||||||
)
|
)
|
||||||
|
|
@ -28,7 +27,7 @@ func TestHash(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestHashFile(t *testing.T) {
|
func TestHashFile(t *testing.T) {
|
||||||
f, err := ioutil.TempFile("", "cmd-go-test-")
|
f, err := os.CreateTemp("", "cmd-go-test-")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -12,7 +12,6 @@ import (
|
||||||
"go/build"
|
"go/build"
|
||||||
"internal/cfg"
|
"internal/cfg"
|
||||||
"io"
|
"io"
|
||||||
"io/ioutil"
|
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"runtime"
|
"runtime"
|
||||||
|
|
@ -187,7 +186,7 @@ func initEnvCache() {
|
||||||
if file == "" {
|
if file == "" {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
data, err := ioutil.ReadFile(file)
|
data, err := os.ReadFile(file)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -10,7 +10,6 @@ import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"go/build"
|
"go/build"
|
||||||
"io/ioutil"
|
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"runtime"
|
"runtime"
|
||||||
|
|
@ -452,7 +451,7 @@ func updateEnvFile(add map[string]string, del map[string]bool) {
|
||||||
if file == "" {
|
if file == "" {
|
||||||
base.Fatalf("go env: cannot find go env config: %v", err)
|
base.Fatalf("go env: cannot find go env config: %v", err)
|
||||||
}
|
}
|
||||||
data, err := ioutil.ReadFile(file)
|
data, err := os.ReadFile(file)
|
||||||
if err != nil && (!os.IsNotExist(err) || len(add) == 0) {
|
if err != nil && (!os.IsNotExist(err) || len(add) == 0) {
|
||||||
base.Fatalf("go env: reading go env config: %v", err)
|
base.Fatalf("go env: reading go env config: %v", err)
|
||||||
}
|
}
|
||||||
|
|
@ -506,11 +505,11 @@ func updateEnvFile(add map[string]string, del map[string]bool) {
|
||||||
}
|
}
|
||||||
|
|
||||||
data = []byte(strings.Join(lines, ""))
|
data = []byte(strings.Join(lines, ""))
|
||||||
err = ioutil.WriteFile(file, data, 0666)
|
err = os.WriteFile(file, data, 0666)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
// Try creating directory.
|
// Try creating directory.
|
||||||
os.MkdirAll(filepath.Dir(file), 0777)
|
os.MkdirAll(filepath.Dir(file), 0777)
|
||||||
err = ioutil.WriteFile(file, data, 0666)
|
err = os.WriteFile(file, data, 0666)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
base.Fatalf("go env: writing go env config: %v", err)
|
base.Fatalf("go env: writing go env config: %v", err)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -86,7 +86,7 @@ func Init(wd string) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
b, err := ioutil.ReadFile(OverlayFile)
|
b, err := os.ReadFile(OverlayFile)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("reading overlay file: %v", err)
|
return fmt.Errorf("reading overlay file: %v", err)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -8,7 +8,6 @@ import (
|
||||||
"internal/testenv"
|
"internal/testenv"
|
||||||
"io"
|
"io"
|
||||||
"io/fs"
|
"io/fs"
|
||||||
"io/ioutil"
|
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"reflect"
|
"reflect"
|
||||||
|
|
@ -47,7 +46,7 @@ func initOverlay(t *testing.T, config string) {
|
||||||
if err := os.MkdirAll(filepath.Dir(name), 0777); err != nil {
|
if err := os.MkdirAll(filepath.Dir(name), 0777); err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
if err := ioutil.WriteFile(name, f.Data, 0666); err != nil {
|
if err := os.WriteFile(name, f.Data, 0666); err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -13,7 +13,6 @@ import (
|
||||||
"go/parser"
|
"go/parser"
|
||||||
"go/token"
|
"go/token"
|
||||||
"io"
|
"io"
|
||||||
"io/ioutil"
|
|
||||||
"log"
|
"log"
|
||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
|
|
@ -201,7 +200,7 @@ func runGenerate(ctx context.Context, cmd *base.Command, args []string) {
|
||||||
|
|
||||||
// generate runs the generation directives for a single file.
|
// generate runs the generation directives for a single file.
|
||||||
func generate(absFile string) bool {
|
func generate(absFile string) bool {
|
||||||
src, err := ioutil.ReadFile(absFile)
|
src, err := os.ReadFile(absFile)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatalf("generate: %s", err)
|
log.Fatalf("generate: %s", err)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -8,6 +8,7 @@ import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"internal/testenv"
|
"internal/testenv"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
|
"os"
|
||||||
"path"
|
"path"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"runtime"
|
"runtime"
|
||||||
|
|
@ -66,7 +67,7 @@ func TestScanDir(t *testing.T) {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
t.Run(dir.Name(), func(t *testing.T) {
|
t.Run(dir.Name(), func(t *testing.T) {
|
||||||
tagsData, err := ioutil.ReadFile(filepath.Join("testdata", dir.Name(), "tags.txt"))
|
tagsData, err := os.ReadFile(filepath.Join("testdata", dir.Name(), "tags.txt"))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("error reading tags: %v", err)
|
t.Fatalf("error reading tags: %v", err)
|
||||||
}
|
}
|
||||||
|
|
@ -75,7 +76,7 @@ func TestScanDir(t *testing.T) {
|
||||||
tags[t] = true
|
tags[t] = true
|
||||||
}
|
}
|
||||||
|
|
||||||
wantData, err := ioutil.ReadFile(filepath.Join("testdata", dir.Name(), "want.txt"))
|
wantData, err := os.ReadFile(filepath.Join("testdata", dir.Name(), "want.txt"))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("error reading want: %v", err)
|
t.Fatalf("error reading want: %v", err)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1147,7 +1147,7 @@ var (
|
||||||
// goModPath returns the module path in the go.mod in dir, if any.
|
// goModPath returns the module path in the go.mod in dir, if any.
|
||||||
func goModPath(dir string) (path string) {
|
func goModPath(dir string) (path string) {
|
||||||
return goModPathCache.Do(dir, func() interface{} {
|
return goModPathCache.Do(dir, func() interface{} {
|
||||||
data, err := ioutil.ReadFile(filepath.Join(dir, "go.mod"))
|
data, err := os.ReadFile(filepath.Join(dir, "go.mod"))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
|
|
@ -1728,7 +1728,7 @@ func (p *Package) load(ctx context.Context, path string, stk *ImportStack, impor
|
||||||
// not work for any package that lacks a Target — such as a non-main
|
// not work for any package that lacks a Target — such as a non-main
|
||||||
// package in module mode. We should probably fix that.
|
// package in module mode. We should probably fix that.
|
||||||
shlibnamefile := p.Target[:len(p.Target)-2] + ".shlibname"
|
shlibnamefile := p.Target[:len(p.Target)-2] + ".shlibname"
|
||||||
shlib, err := ioutil.ReadFile(shlibnamefile)
|
shlib, err := os.ReadFile(shlibnamefile)
|
||||||
if err != nil && !os.IsNotExist(err) {
|
if err != nil && !os.IsNotExist(err) {
|
||||||
base.Fatalf("reading shlibname: %v", err)
|
base.Fatalf("reading shlibname: %v", err)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -9,7 +9,6 @@ package filelock_test
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"internal/testenv"
|
"internal/testenv"
|
||||||
"io/ioutil"
|
|
||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
|
@ -51,9 +50,9 @@ func mustTempFile(t *testing.T) (f *os.File, remove func()) {
|
||||||
t.Helper()
|
t.Helper()
|
||||||
|
|
||||||
base := filepath.Base(t.Name())
|
base := filepath.Base(t.Name())
|
||||||
f, err := ioutil.TempFile("", base)
|
f, err := os.CreateTemp("", base)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf(`ioutil.TempFile("", %q) = %v`, base, err)
|
t.Fatalf(`os.CreateTemp("", %q) = %v`, base, err)
|
||||||
}
|
}
|
||||||
t.Logf("fd %d = %s", f.Fd(), f.Name())
|
t.Logf("fd %d = %s", f.Fd(), f.Name())
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -10,7 +10,6 @@ package lockedfile_test
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"internal/testenv"
|
"internal/testenv"
|
||||||
"io/ioutil"
|
|
||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
|
@ -23,7 +22,7 @@ import (
|
||||||
func mustTempDir(t *testing.T) (dir string, remove func()) {
|
func mustTempDir(t *testing.T) (dir string, remove func()) {
|
||||||
t.Helper()
|
t.Helper()
|
||||||
|
|
||||||
dir, err := ioutil.TempDir("", filepath.Base(t.Name()))
|
dir, err := os.MkdirTemp("", filepath.Base(t.Name()))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
@ -155,8 +154,8 @@ func TestCanLockExistingFile(t *testing.T) {
|
||||||
defer remove()
|
defer remove()
|
||||||
path := filepath.Join(dir, "existing.txt")
|
path := filepath.Join(dir, "existing.txt")
|
||||||
|
|
||||||
if err := ioutil.WriteFile(path, []byte("ok"), 0777); err != nil {
|
if err := os.WriteFile(path, []byte("ok"), 0777); err != nil {
|
||||||
t.Fatalf("ioutil.WriteFile: %v", err)
|
t.Fatalf("os.WriteFile: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
f, err := lockedfile.Edit(path)
|
f, err := lockedfile.Edit(path)
|
||||||
|
|
@ -201,7 +200,7 @@ func TestSpuriousEDEADLK(t *testing.T) {
|
||||||
}
|
}
|
||||||
defer b.Close()
|
defer b.Close()
|
||||||
|
|
||||||
if err := ioutil.WriteFile(filepath.Join(dir, "locked"), []byte("ok"), 0666); err != nil {
|
if err := os.WriteFile(filepath.Join(dir, "locked"), []byte("ok"), 0666); err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -155,7 +155,7 @@ func runVendor(ctx context.Context, cmd *base.Command, args []string) {
|
||||||
base.Fatalf("go mod vendor: %v", err)
|
base.Fatalf("go mod vendor: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := ioutil.WriteFile(filepath.Join(vdir, "modules.txt"), buf.Bytes(), 0666); err != nil {
|
if err := os.WriteFile(filepath.Join(vdir, "modules.txt"), buf.Bytes(), 0666); err != nil {
|
||||||
base.Fatalf("go mod vendor: %v", err)
|
base.Fatalf("go mod vendor: %v", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -10,7 +10,6 @@ import (
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/fs"
|
"io/fs"
|
||||||
"io/ioutil"
|
|
||||||
"os"
|
"os"
|
||||||
"runtime"
|
"runtime"
|
||||||
|
|
||||||
|
|
@ -87,7 +86,7 @@ func verifyMod(mod module.Version) []error {
|
||||||
_, zipErr = os.Stat(zip)
|
_, zipErr = os.Stat(zip)
|
||||||
}
|
}
|
||||||
dir, dirErr := modfetch.DownloadDir(mod)
|
dir, dirErr := modfetch.DownloadDir(mod)
|
||||||
data, err := ioutil.ReadFile(zip + "hash")
|
data, err := os.ReadFile(zip + "hash")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if zipErr != nil && errors.Is(zipErr, fs.ErrNotExist) &&
|
if zipErr != nil && errors.Is(zipErr, fs.ErrNotExist) &&
|
||||||
dirErr != nil && errors.Is(dirErr, fs.ErrNotExist) {
|
dirErr != nil && errors.Is(dirErr, fs.ErrNotExist) {
|
||||||
|
|
|
||||||
|
|
@ -9,7 +9,6 @@ import (
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
"internal/testenv"
|
"internal/testenv"
|
||||||
"io/ioutil"
|
|
||||||
"log"
|
"log"
|
||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
|
|
@ -37,7 +36,7 @@ func testMain(m *testing.M) int {
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
dir, err := ioutil.TempDir("", "modconv-test-")
|
dir, err := os.MkdirTemp("", "modconv-test-")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
@ -167,7 +166,7 @@ func TestConvertLegacyConfig(t *testing.T) {
|
||||||
|
|
||||||
for name := range Converters {
|
for name := range Converters {
|
||||||
file := filepath.Join(dir, name)
|
file := filepath.Join(dir, name)
|
||||||
data, err := ioutil.ReadFile(file)
|
data, err := os.ReadFile(file)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
f := new(modfile.File)
|
f := new(modfile.File)
|
||||||
f.AddModuleStmt(tt.path)
|
f.AddModuleStmt(tt.path)
|
||||||
|
|
|
||||||
|
|
@ -7,7 +7,7 @@ package modconv
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"testing"
|
"testing"
|
||||||
)
|
)
|
||||||
|
|
@ -42,7 +42,7 @@ func Test(t *testing.T) {
|
||||||
if Converters[extMap[ext]] == nil {
|
if Converters[extMap[ext]] == nil {
|
||||||
t.Fatalf("Converters[%q] == nil", extMap[ext])
|
t.Fatalf("Converters[%q] == nil", extMap[ext])
|
||||||
}
|
}
|
||||||
data, err := ioutil.ReadFile(test)
|
data, err := os.ReadFile(test)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
@ -50,7 +50,7 @@ func Test(t *testing.T) {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
want, err := ioutil.ReadFile(test[:len(test)-len(ext)] + ".out")
|
want, err := os.ReadFile(test[:len(test)-len(ext)] + ".out")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Error(err)
|
t.Error(err)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -5,14 +5,13 @@
|
||||||
package modfetch
|
package modfetch
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"io/ioutil"
|
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"testing"
|
"testing"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestWriteDiskCache(t *testing.T) {
|
func TestWriteDiskCache(t *testing.T) {
|
||||||
tmpdir, err := ioutil.TempDir("", "go-writeCache-test-")
|
tmpdir, err := os.MkdirTemp("", "go-writeCache-test-")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -12,7 +12,6 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"io/fs"
|
"io/fs"
|
||||||
"io/ioutil"
|
|
||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
|
@ -189,7 +188,7 @@ func WorkDir(typ, name string) (dir, lockfile string, err error) {
|
||||||
}
|
}
|
||||||
defer unlock()
|
defer unlock()
|
||||||
|
|
||||||
data, err := ioutil.ReadFile(dir + ".info")
|
data, err := os.ReadFile(dir + ".info")
|
||||||
info, err2 := os.Stat(dir)
|
info, err2 := os.Stat(dir)
|
||||||
if err == nil && err2 == nil && info.IsDir() {
|
if err == nil && err2 == nil && info.IsDir() {
|
||||||
// Info file and directory both already exist: reuse.
|
// Info file and directory both already exist: reuse.
|
||||||
|
|
@ -211,7 +210,7 @@ func WorkDir(typ, name string) (dir, lockfile string, err error) {
|
||||||
if err := os.MkdirAll(dir, 0777); err != nil {
|
if err := os.MkdirAll(dir, 0777); err != nil {
|
||||||
return "", "", err
|
return "", "", err
|
||||||
}
|
}
|
||||||
if err := ioutil.WriteFile(dir+".info", []byte(key), 0666); err != nil {
|
if err := os.WriteFile(dir+".info", []byte(key), 0666); err != nil {
|
||||||
os.RemoveAll(dir)
|
os.RemoveAll(dir)
|
||||||
return "", "", err
|
return "", "", err
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -12,7 +12,6 @@ import (
|
||||||
"internal/testenv"
|
"internal/testenv"
|
||||||
"io"
|
"io"
|
||||||
"io/fs"
|
"io/fs"
|
||||||
"io/ioutil"
|
|
||||||
"log"
|
"log"
|
||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
|
|
@ -54,7 +53,7 @@ func testMain(m *testing.M) int {
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
dir, err := ioutil.TempDir("", "gitrepo-test-")
|
dir, err := os.MkdirTemp("", "gitrepo-test-")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -15,7 +15,6 @@ import (
|
||||||
"flag"
|
"flag"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"io/ioutil"
|
|
||||||
"log"
|
"log"
|
||||||
"os"
|
"os"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
@ -124,7 +123,7 @@ func main() {
|
||||||
}
|
}
|
||||||
|
|
||||||
if f[3] != "-" {
|
if f[3] != "-" {
|
||||||
if err := ioutil.WriteFile(f[3], data, 0666); err != nil {
|
if err := os.WriteFile(f[3], data, 0666); err != nil {
|
||||||
fmt.Fprintf(os.Stderr, "?%s\n", err)
|
fmt.Fprintf(os.Stderr, "?%s\n", err)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -10,7 +10,6 @@ import (
|
||||||
"internal/lazyregexp"
|
"internal/lazyregexp"
|
||||||
"io"
|
"io"
|
||||||
"io/fs"
|
"io/fs"
|
||||||
"io/ioutil"
|
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"sort"
|
"sort"
|
||||||
|
|
@ -433,7 +432,7 @@ func (r *vcsRepo) ReadZip(rev, subdir string, maxSize int64) (zip io.ReadCloser,
|
||||||
if rev == "latest" {
|
if rev == "latest" {
|
||||||
rev = r.cmd.latest
|
rev = r.cmd.latest
|
||||||
}
|
}
|
||||||
f, err := ioutil.TempFile("", "go-readzip-*.zip")
|
f, err := os.CreateTemp("", "go-readzip-*.zip")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -11,7 +11,6 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"io/fs"
|
"io/fs"
|
||||||
"io/ioutil"
|
|
||||||
"os"
|
"os"
|
||||||
"path"
|
"path"
|
||||||
"sort"
|
"sort"
|
||||||
|
|
@ -966,7 +965,7 @@ func (r *codeRepo) Zip(dst io.Writer, version string) error {
|
||||||
subdir = strings.Trim(subdir, "/")
|
subdir = strings.Trim(subdir, "/")
|
||||||
|
|
||||||
// Spool to local file.
|
// Spool to local file.
|
||||||
f, err := ioutil.TempFile("", "go-codehost-")
|
f, err := os.CreateTemp("", "go-codehost-")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
dl.Close()
|
dl.Close()
|
||||||
return err
|
return err
|
||||||
|
|
|
||||||
|
|
@ -11,7 +11,6 @@ import (
|
||||||
"hash"
|
"hash"
|
||||||
"internal/testenv"
|
"internal/testenv"
|
||||||
"io"
|
"io"
|
||||||
"io/ioutil"
|
|
||||||
"log"
|
"log"
|
||||||
"os"
|
"os"
|
||||||
"reflect"
|
"reflect"
|
||||||
|
|
@ -38,7 +37,7 @@ func testMain(m *testing.M) int {
|
||||||
// code, bypass the sum database.
|
// code, bypass the sum database.
|
||||||
cfg.GOSUMDB = "off"
|
cfg.GOSUMDB = "off"
|
||||||
|
|
||||||
dir, err := ioutil.TempDir("", "gitrepo-test-")
|
dir, err := os.MkdirTemp("", "gitrepo-test-")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
@ -424,7 +423,7 @@ var codeRepoTests = []codeRepoTest{
|
||||||
func TestCodeRepo(t *testing.T) {
|
func TestCodeRepo(t *testing.T) {
|
||||||
testenv.MustHaveExternalNetwork(t)
|
testenv.MustHaveExternalNetwork(t)
|
||||||
|
|
||||||
tmpdir, err := ioutil.TempDir("", "modfetch-test-")
|
tmpdir, err := os.MkdirTemp("", "modfetch-test-")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
@ -491,9 +490,9 @@ func TestCodeRepo(t *testing.T) {
|
||||||
|
|
||||||
needHash := !testing.Short() && (tt.zipFileHash != "" || tt.zipSum != "")
|
needHash := !testing.Short() && (tt.zipFileHash != "" || tt.zipSum != "")
|
||||||
if tt.zip != nil || tt.zipErr != "" || needHash {
|
if tt.zip != nil || tt.zipErr != "" || needHash {
|
||||||
f, err := ioutil.TempFile(tmpdir, tt.version+".zip.")
|
f, err := os.CreateTemp(tmpdir, tt.version+".zip.")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("ioutil.TempFile: %v", err)
|
t.Fatalf("os.CreateTemp: %v", err)
|
||||||
}
|
}
|
||||||
zipfile := f.Name()
|
zipfile := f.Name()
|
||||||
defer func() {
|
defer func() {
|
||||||
|
|
@ -655,7 +654,7 @@ var codeRepoVersionsTests = []struct {
|
||||||
func TestCodeRepoVersions(t *testing.T) {
|
func TestCodeRepoVersions(t *testing.T) {
|
||||||
testenv.MustHaveExternalNetwork(t)
|
testenv.MustHaveExternalNetwork(t)
|
||||||
|
|
||||||
tmpdir, err := ioutil.TempDir("", "vgo-modfetch-test-")
|
tmpdir, err := os.MkdirTemp("", "vgo-modfetch-test-")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
@ -729,7 +728,7 @@ var latestTests = []struct {
|
||||||
func TestLatest(t *testing.T) {
|
func TestLatest(t *testing.T) {
|
||||||
testenv.MustHaveExternalNetwork(t)
|
testenv.MustHaveExternalNetwork(t)
|
||||||
|
|
||||||
tmpdir, err := ioutil.TempDir("", "vgo-modfetch-test-")
|
tmpdir, err := os.MkdirTemp("", "vgo-modfetch-test-")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -12,7 +12,6 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"io/fs"
|
"io/fs"
|
||||||
"io/ioutil"
|
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"sort"
|
"sort"
|
||||||
|
|
@ -136,7 +135,7 @@ func download(ctx context.Context, mod module.Version) (dir string, err error) {
|
||||||
if err := os.MkdirAll(parentDir, 0777); err != nil {
|
if err := os.MkdirAll(parentDir, 0777); err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
if err := ioutil.WriteFile(partialPath, nil, 0666); err != nil {
|
if err := os.WriteFile(partialPath, nil, 0666); err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
if err := modzip.Unzip(dir, mod, zipfile); err != nil {
|
if err := modzip.Unzip(dir, mod, zipfile); err != nil {
|
||||||
|
|
@ -223,7 +222,7 @@ func downloadZip(ctx context.Context, mod module.Version, zipfile string) (err e
|
||||||
// contents of the file (by hashing it) before we commit it. Because the file
|
// contents of the file (by hashing it) before we commit it. Because the file
|
||||||
// is zip-compressed, we need an actual file — or at least an io.ReaderAt — to
|
// is zip-compressed, we need an actual file — or at least an io.ReaderAt — to
|
||||||
// validate it: we can't just tee the stream as we write it.
|
// validate it: we can't just tee the stream as we write it.
|
||||||
f, err := ioutil.TempFile(filepath.Dir(zipfile), filepath.Base(renameio.Pattern(zipfile)))
|
f, err := os.CreateTemp(filepath.Dir(zipfile), filepath.Base(renameio.Pattern(zipfile)))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -24,7 +24,6 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"internal/testenv"
|
"internal/testenv"
|
||||||
"io"
|
"io"
|
||||||
"io/ioutil"
|
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
@ -81,7 +80,7 @@ func TestZipSums(t *testing.T) {
|
||||||
if *modCacheDir != "" {
|
if *modCacheDir != "" {
|
||||||
cfg.BuildContext.GOPATH = *modCacheDir
|
cfg.BuildContext.GOPATH = *modCacheDir
|
||||||
} else {
|
} else {
|
||||||
tmpDir, err := ioutil.TempDir("", "TestZipSums")
|
tmpDir, err := os.MkdirTemp("", "TestZipSums")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -632,7 +632,7 @@ func setDefaultBuildMod() {
|
||||||
func convertLegacyConfig(modPath string) (from string, err error) {
|
func convertLegacyConfig(modPath string) (from string, err error) {
|
||||||
for _, name := range altConfigs {
|
for _, name := range altConfigs {
|
||||||
cfg := filepath.Join(modRoot, name)
|
cfg := filepath.Join(modRoot, name)
|
||||||
data, err := ioutil.ReadFile(cfg)
|
data, err := os.ReadFile(cfg)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
convert := modconv.Converters[name]
|
convert := modconv.Converters[name]
|
||||||
if convert == nil {
|
if convert == nil {
|
||||||
|
|
@ -753,7 +753,7 @@ func findModulePath(dir string) (string, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Look for Godeps.json declaring import path.
|
// Look for Godeps.json declaring import path.
|
||||||
data, _ := ioutil.ReadFile(filepath.Join(dir, "Godeps/Godeps.json"))
|
data, _ := os.ReadFile(filepath.Join(dir, "Godeps/Godeps.json"))
|
||||||
var cfg1 struct{ ImportPath string }
|
var cfg1 struct{ ImportPath string }
|
||||||
json.Unmarshal(data, &cfg1)
|
json.Unmarshal(data, &cfg1)
|
||||||
if cfg1.ImportPath != "" {
|
if cfg1.ImportPath != "" {
|
||||||
|
|
@ -761,7 +761,7 @@ func findModulePath(dir string) (string, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Look for vendor.json declaring import path.
|
// Look for vendor.json declaring import path.
|
||||||
data, _ = ioutil.ReadFile(filepath.Join(dir, "vendor/vendor.json"))
|
data, _ = os.ReadFile(filepath.Join(dir, "vendor/vendor.json"))
|
||||||
var cfg2 struct{ RootPath string }
|
var cfg2 struct{ RootPath string }
|
||||||
json.Unmarshal(data, &cfg2)
|
json.Unmarshal(data, &cfg2)
|
||||||
if cfg2.RootPath != "" {
|
if cfg2.RootPath != "" {
|
||||||
|
|
@ -813,7 +813,7 @@ var (
|
||||||
)
|
)
|
||||||
|
|
||||||
func findImportComment(file string) string {
|
func findImportComment(file string) string {
|
||||||
data, err := ioutil.ReadFile(file)
|
data, err := os.ReadFile(file)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -7,7 +7,6 @@ package modload
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"internal/testenv"
|
"internal/testenv"
|
||||||
"io/ioutil"
|
|
||||||
"log"
|
"log"
|
||||||
"os"
|
"os"
|
||||||
"path"
|
"path"
|
||||||
|
|
@ -27,7 +26,7 @@ func TestMain(m *testing.M) {
|
||||||
func testMain(m *testing.M) int {
|
func testMain(m *testing.M) int {
|
||||||
cfg.GOPROXY = "direct"
|
cfg.GOPROXY = "direct"
|
||||||
|
|
||||||
dir, err := ioutil.TempDir("", "modload-test-")
|
dir, err := os.MkdirTemp("", "modload-test-")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -8,7 +8,7 @@ import (
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/fs"
|
"io/fs"
|
||||||
"io/ioutil"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strings"
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
|
|
@ -40,7 +40,7 @@ func readVendorList() {
|
||||||
vendorPkgModule = make(map[string]module.Version)
|
vendorPkgModule = make(map[string]module.Version)
|
||||||
vendorVersion = make(map[string]string)
|
vendorVersion = make(map[string]string)
|
||||||
vendorMeta = make(map[module.Version]vendorMetadata)
|
vendorMeta = make(map[module.Version]vendorMetadata)
|
||||||
data, err := ioutil.ReadFile(filepath.Join(ModRoot(), "vendor/modules.txt"))
|
data, err := os.ReadFile(filepath.Join(ModRoot(), "vendor/modules.txt"))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if !errors.Is(err, fs.ErrNotExist) {
|
if !errors.Is(err, fs.ErrNotExist) {
|
||||||
base.Fatalf("go: %s", err)
|
base.Fatalf("go: %s", err)
|
||||||
|
|
|
||||||
|
|
@ -25,7 +25,7 @@ func Pattern(filename string) string {
|
||||||
return filepath.Join(filepath.Dir(filename), filepath.Base(filename)+patternSuffix)
|
return filepath.Join(filepath.Dir(filename), filepath.Base(filename)+patternSuffix)
|
||||||
}
|
}
|
||||||
|
|
||||||
// WriteFile is like ioutil.WriteFile, but first writes data to an arbitrary
|
// WriteFile is like os.WriteFile, but first writes data to an arbitrary
|
||||||
// file in the same directory as filename, then renames it atomically to the
|
// file in the same directory as filename, then renames it atomically to the
|
||||||
// final name.
|
// final name.
|
||||||
//
|
//
|
||||||
|
|
@ -67,7 +67,7 @@ func WriteToFile(filename string, data io.Reader, perm fs.FileMode) (err error)
|
||||||
return robustio.Rename(f.Name(), filename)
|
return robustio.Rename(f.Name(), filename)
|
||||||
}
|
}
|
||||||
|
|
||||||
// ReadFile is like ioutil.ReadFile, but on Windows retries spurious errors that
|
// ReadFile is like os.ReadFile, but on Windows retries spurious errors that
|
||||||
// may occur if the file is concurrently replaced.
|
// may occur if the file is concurrently replaced.
|
||||||
//
|
//
|
||||||
// Errors are classified heuristically and retries are bounded, so even this
|
// Errors are classified heuristically and retries are bounded, so even this
|
||||||
|
|
|
||||||
|
|
@ -10,7 +10,6 @@ import (
|
||||||
"encoding/binary"
|
"encoding/binary"
|
||||||
"errors"
|
"errors"
|
||||||
"internal/testenv"
|
"internal/testenv"
|
||||||
"io/ioutil"
|
|
||||||
"math/rand"
|
"math/rand"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
|
@ -30,7 +29,7 @@ func TestConcurrentReadsAndWrites(t *testing.T) {
|
||||||
testenv.SkipFlaky(t, 33041)
|
testenv.SkipFlaky(t, 33041)
|
||||||
}
|
}
|
||||||
|
|
||||||
dir, err := ioutil.TempDir("", "renameio")
|
dir, err := os.MkdirTemp("", "renameio")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -8,7 +8,6 @@ package renameio
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"io/fs"
|
"io/fs"
|
||||||
"io/ioutil"
|
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"syscall"
|
"syscall"
|
||||||
|
|
@ -16,7 +15,7 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestWriteFileModeAppliesUmask(t *testing.T) {
|
func TestWriteFileModeAppliesUmask(t *testing.T) {
|
||||||
dir, err := ioutil.TempDir("", "renameio")
|
dir, err := os.MkdirTemp("", "renameio")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("Failed to create temporary directory: %v", err)
|
t.Fatalf("Failed to create temporary directory: %v", err)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -22,7 +22,7 @@ func Rename(oldpath, newpath string) error {
|
||||||
return rename(oldpath, newpath)
|
return rename(oldpath, newpath)
|
||||||
}
|
}
|
||||||
|
|
||||||
// ReadFile is like ioutil.ReadFile, but on Windows retries errors that may
|
// ReadFile is like os.ReadFile, but on Windows retries errors that may
|
||||||
// occur if the file is concurrently replaced.
|
// occur if the file is concurrently replaced.
|
||||||
//
|
//
|
||||||
// (See golang.org/issue/31247 and golang.org/issue/32188.)
|
// (See golang.org/issue/31247 and golang.org/issue/32188.)
|
||||||
|
|
|
||||||
|
|
@ -8,7 +8,6 @@ package robustio
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
"io/ioutil"
|
|
||||||
"math/rand"
|
"math/rand"
|
||||||
"os"
|
"os"
|
||||||
"syscall"
|
"syscall"
|
||||||
|
|
@ -70,11 +69,11 @@ func rename(oldpath, newpath string) (err error) {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
// readFile is like ioutil.ReadFile, but retries ephemeral errors.
|
// readFile is like os.ReadFile, but retries ephemeral errors.
|
||||||
func readFile(filename string) ([]byte, error) {
|
func readFile(filename string) ([]byte, error) {
|
||||||
var b []byte
|
var b []byte
|
||||||
err := retry(func() (err error, mayRetry bool) {
|
err := retry(func() (err error, mayRetry bool) {
|
||||||
b, err = ioutil.ReadFile(filename)
|
b, err = os.ReadFile(filename)
|
||||||
|
|
||||||
// Unlike in rename, we do not retry errFileNotFound here: it can occur
|
// Unlike in rename, we do not retry errFileNotFound here: it can occur
|
||||||
// as a spurious error, but the file may also genuinely not exist, so the
|
// as a spurious error, but the file may also genuinely not exist, so the
|
||||||
|
|
|
||||||
|
|
@ -7,7 +7,6 @@
|
||||||
package robustio
|
package robustio
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"io/ioutil"
|
|
||||||
"os"
|
"os"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
@ -16,7 +15,7 @@ func rename(oldpath, newpath string) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
func readFile(filename string) ([]byte, error) {
|
func readFile(filename string) ([]byte, error) {
|
||||||
return ioutil.ReadFile(filename)
|
return os.ReadFile(filename)
|
||||||
}
|
}
|
||||||
|
|
||||||
func removeAll(path string) error {
|
func removeAll(path string) error {
|
||||||
|
|
|
||||||
|
|
@ -884,7 +884,7 @@ func builderTest(b *work.Builder, ctx context.Context, p *load.Package) (buildAc
|
||||||
if !cfg.BuildN {
|
if !cfg.BuildN {
|
||||||
// writeTestmain writes _testmain.go,
|
// writeTestmain writes _testmain.go,
|
||||||
// using the test description gathered in t.
|
// using the test description gathered in t.
|
||||||
if err := ioutil.WriteFile(testDir+"_testmain.go", *pmain.Internal.TestmainGo, 0666); err != nil {
|
if err := os.WriteFile(testDir+"_testmain.go", *pmain.Internal.TestmainGo, 0666); err != nil {
|
||||||
return nil, nil, nil, err
|
return nil, nil, nil, err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -1616,7 +1616,7 @@ func (c *runCache) saveOutput(a *work.Action) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// See comment about two-level lookup in tryCacheWithID above.
|
// See comment about two-level lookup in tryCacheWithID above.
|
||||||
testlog, err := ioutil.ReadFile(a.Objdir + "testlog.txt")
|
testlog, err := os.ReadFile(a.Objdir + "testlog.txt")
|
||||||
if err != nil || !bytes.HasPrefix(testlog, testlogMagic) || testlog[len(testlog)-1] != '\n' {
|
if err != nil || !bytes.HasPrefix(testlog, testlogMagic) || testlog[len(testlog)-1] != '\n' {
|
||||||
if cache.DebugTest {
|
if cache.DebugTest {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
||||||
|
|
@ -34,7 +34,7 @@ package txtar
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
"os"
|
||||||
"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
@ -66,7 +66,7 @@ func Format(a *Archive) []byte {
|
||||||
|
|
||||||
// ParseFile parses the named file as an archive.
|
// ParseFile parses the named file as an archive.
|
||||||
func ParseFile(file string) (*Archive, error) {
|
func ParseFile(file string) (*Archive, error) {
|
||||||
data, err := ioutil.ReadFile(file)
|
data, err := os.ReadFile(file)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -7,7 +7,6 @@ package vcs
|
||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
"internal/testenv"
|
"internal/testenv"
|
||||||
"io/ioutil"
|
|
||||||
"os"
|
"os"
|
||||||
"path"
|
"path"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
|
@ -208,7 +207,7 @@ func TestRepoRootForImportPath(t *testing.T) {
|
||||||
|
|
||||||
// Test that vcsFromDir correctly inspects a given directory and returns the right VCS and root.
|
// Test that vcsFromDir correctly inspects a given directory and returns the right VCS and root.
|
||||||
func TestFromDir(t *testing.T) {
|
func TestFromDir(t *testing.T) {
|
||||||
tempDir, err := ioutil.TempDir("", "vcstest")
|
tempDir, err := os.MkdirTemp("", "vcstest")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -7,7 +7,6 @@ package web
|
||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
"io/fs"
|
"io/fs"
|
||||||
"io/ioutil"
|
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
@ -16,7 +15,7 @@ import (
|
||||||
func TestGetFileURL(t *testing.T) {
|
func TestGetFileURL(t *testing.T) {
|
||||||
const content = "Hello, file!\n"
|
const content = "Hello, file!\n"
|
||||||
|
|
||||||
f, err := ioutil.TempFile("", "web-TestGetFileURL")
|
f, err := os.CreateTemp("", "web-TestGetFileURL")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -14,7 +14,6 @@ import (
|
||||||
"debug/elf"
|
"debug/elf"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"runtime"
|
"runtime"
|
||||||
|
|
@ -253,7 +252,7 @@ func (b *Builder) Init() {
|
||||||
if cfg.BuildN {
|
if cfg.BuildN {
|
||||||
b.WorkDir = "$WORK"
|
b.WorkDir = "$WORK"
|
||||||
} else {
|
} else {
|
||||||
tmp, err := ioutil.TempDir(cfg.Getenv("GOTMPDIR"), "go-build")
|
tmp, err := os.MkdirTemp(cfg.Getenv("GOTMPDIR"), "go-build")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
base.Fatalf("go: creating work dir: %v", err)
|
base.Fatalf("go: creating work dir: %v", err)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -8,7 +8,6 @@ import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/fs"
|
"io/fs"
|
||||||
"io/ioutil"
|
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"reflect"
|
"reflect"
|
||||||
|
|
@ -170,7 +169,7 @@ func TestSharedLibName(t *testing.T) {
|
||||||
for _, data := range testData {
|
for _, data := range testData {
|
||||||
func() {
|
func() {
|
||||||
if data.rootedAt != "" {
|
if data.rootedAt != "" {
|
||||||
tmpGopath, err := ioutil.TempDir("", "gopath")
|
tmpGopath, err := os.MkdirTemp("", "gopath")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
@ -238,7 +237,7 @@ func TestRespectSetgidDir(t *testing.T) {
|
||||||
return cmdBuf.WriteString(fmt.Sprint(a...))
|
return cmdBuf.WriteString(fmt.Sprint(a...))
|
||||||
}
|
}
|
||||||
|
|
||||||
setgiddir, err := ioutil.TempDir("", "SetGroupID")
|
setgiddir, err := os.MkdirTemp("", "SetGroupID")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
@ -258,9 +257,9 @@ func TestRespectSetgidDir(t *testing.T) {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
pkgfile, err := ioutil.TempFile("", "pkgfile")
|
pkgfile, err := os.CreateTemp("", "pkgfile")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("ioutil.TempFile(\"\", \"pkgfile\"): %v", err)
|
t.Fatalf("os.CreateTemp(\"\", \"pkgfile\"): %v", err)
|
||||||
}
|
}
|
||||||
defer os.Remove(pkgfile.Name())
|
defer os.Remove(pkgfile.Name())
|
||||||
defer pkgfile.Close()
|
defer pkgfile.Close()
|
||||||
|
|
|
||||||
|
|
@ -7,7 +7,6 @@ package work
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
|
||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
@ -344,7 +343,7 @@ func (b *Builder) gccgoBuildIDFile(a *Action) (string, error) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := ioutil.WriteFile(sfile, buf.Bytes(), 0666); err != nil {
|
if err := os.WriteFile(sfile, buf.Bytes(), 0666); err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -16,7 +16,6 @@ import (
|
||||||
"internal/lazyregexp"
|
"internal/lazyregexp"
|
||||||
"io"
|
"io"
|
||||||
"io/fs"
|
"io/fs"
|
||||||
"io/ioutil"
|
|
||||||
"log"
|
"log"
|
||||||
"math/rand"
|
"math/rand"
|
||||||
"os"
|
"os"
|
||||||
|
|
@ -94,7 +93,7 @@ func (b *Builder) Do(ctx context.Context, root *Action) {
|
||||||
base.Fatalf("go: refusing to write action graph to %v\n", file)
|
base.Fatalf("go: refusing to write action graph to %v\n", file)
|
||||||
}
|
}
|
||||||
js := actionGraphJSON(root)
|
js := actionGraphJSON(root)
|
||||||
if err := ioutil.WriteFile(file, []byte(js), 0666); err != nil {
|
if err := os.WriteFile(file, []byte(js), 0666); err != nil {
|
||||||
fmt.Fprintf(os.Stderr, "go: writing action graph: %v\n", err)
|
fmt.Fprintf(os.Stderr, "go: writing action graph: %v\n", err)
|
||||||
base.SetExitStatus(1)
|
base.SetExitStatus(1)
|
||||||
}
|
}
|
||||||
|
|
@ -636,7 +635,7 @@ OverlayLoop:
|
||||||
sfiles, gccfiles = filter(sfiles, sfiles[:0], gccfiles)
|
sfiles, gccfiles = filter(sfiles, sfiles[:0], gccfiles)
|
||||||
} else {
|
} else {
|
||||||
for _, sfile := range sfiles {
|
for _, sfile := range sfiles {
|
||||||
data, err := ioutil.ReadFile(filepath.Join(a.Package.Dir, sfile))
|
data, err := os.ReadFile(filepath.Join(a.Package.Dir, sfile))
|
||||||
if err == nil {
|
if err == nil {
|
||||||
if bytes.HasPrefix(data, []byte("TEXT")) || bytes.Contains(data, []byte("\nTEXT")) ||
|
if bytes.HasPrefix(data, []byte("TEXT")) || bytes.Contains(data, []byte("\nTEXT")) ||
|
||||||
bytes.HasPrefix(data, []byte("DATA")) || bytes.Contains(data, []byte("\nDATA")) ||
|
bytes.HasPrefix(data, []byte("DATA")) || bytes.Contains(data, []byte("\nDATA")) ||
|
||||||
|
|
@ -1471,7 +1470,7 @@ func (b *Builder) installShlibname(ctx context.Context, a *Action) error {
|
||||||
|
|
||||||
// TODO: BuildN
|
// TODO: BuildN
|
||||||
a1 := a.Deps[0]
|
a1 := a.Deps[0]
|
||||||
err := ioutil.WriteFile(a.Target, []byte(filepath.Base(a1.Target)+"\n"), 0666)
|
err := os.WriteFile(a.Target, []byte(filepath.Base(a1.Target)+"\n"), 0666)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
@ -1788,7 +1787,7 @@ func (b *Builder) writeFile(file string, text []byte) error {
|
||||||
if cfg.BuildN {
|
if cfg.BuildN {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
return ioutil.WriteFile(file, text, 0666)
|
return os.WriteFile(file, text, 0666)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Install the cgo export header file, if there is one.
|
// Install the cgo export header file, if there is one.
|
||||||
|
|
@ -2537,7 +2536,7 @@ func (b *Builder) gccSupportsFlag(compiler []string, flag string) bool {
|
||||||
|
|
||||||
tmp := os.DevNull
|
tmp := os.DevNull
|
||||||
if runtime.GOOS == "windows" {
|
if runtime.GOOS == "windows" {
|
||||||
f, err := ioutil.TempFile(b.WorkDir, "")
|
f, err := os.CreateTemp(b.WorkDir, "")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
@ -2840,7 +2839,7 @@ func (b *Builder) cgo(a *Action, cgoExe, objdir string, pcCFLAGS, pcLDFLAGS, cgo
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
src, err := ioutil.ReadFile(f)
|
src, err := os.ReadFile(f)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, nil, err
|
return nil, nil, err
|
||||||
}
|
}
|
||||||
|
|
@ -3070,7 +3069,7 @@ func (b *Builder) swigDoIntSize(objdir string) (intsize string, err error) {
|
||||||
return "$INTBITS", nil
|
return "$INTBITS", nil
|
||||||
}
|
}
|
||||||
src := filepath.Join(b.WorkDir, "swig_intsize.go")
|
src := filepath.Join(b.WorkDir, "swig_intsize.go")
|
||||||
if err = ioutil.WriteFile(src, []byte(swigIntSizeCode), 0666); err != nil {
|
if err = os.WriteFile(src, []byte(swigIntSizeCode), 0666); err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
srcs := []string{src}
|
srcs := []string{src}
|
||||||
|
|
@ -3230,7 +3229,7 @@ func passLongArgsInResponseFiles(cmd *exec.Cmd) (cleanup func()) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
tf, err := ioutil.TempFile("", "args")
|
tf, err := os.CreateTemp("", "args")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatalf("error writing long arguments to response file: %v", err)
|
log.Fatalf("error writing long arguments to response file: %v", err)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -9,7 +9,6 @@ import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"io/ioutil"
|
|
||||||
"log"
|
"log"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
|
@ -426,11 +425,11 @@ func toolVerify(a *Action, b *Builder, p *load.Package, newTool string, ofile st
|
||||||
if err := b.run(a, p.Dir, p.ImportPath, nil, newArgs...); err != nil {
|
if err := b.run(a, p.Dir, p.ImportPath, nil, newArgs...); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
data1, err := ioutil.ReadFile(ofile)
|
data1, err := os.ReadFile(ofile)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
data2, err := ioutil.ReadFile(ofile + ".new")
|
data2, err := os.ReadFile(ofile + ".new")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
@ -580,7 +579,7 @@ func pluginPath(a *Action) string {
|
||||||
}
|
}
|
||||||
fmt.Fprintf(h, "build ID: %s\n", buildID)
|
fmt.Fprintf(h, "build ID: %s\n", buildID)
|
||||||
for _, file := range str.StringList(p.GoFiles, p.CgoFiles, p.SFiles) {
|
for _, file := range str.StringList(p.GoFiles, p.CgoFiles, p.SFiles) {
|
||||||
data, err := ioutil.ReadFile(filepath.Join(p.Dir, file))
|
data, err := os.ReadFile(filepath.Join(p.Dir, file))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
base.Fatalf("go: %s", err)
|
base.Fatalf("go: %s", err)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,6 @@ package work
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
|
||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
|
@ -271,7 +270,7 @@ func (tools gccgoToolchain) link(b *Builder, root *Action, out, importcfg string
|
||||||
}
|
}
|
||||||
|
|
||||||
readCgoFlags := func(flagsFile string) error {
|
readCgoFlags := func(flagsFile string) error {
|
||||||
flags, err := ioutil.ReadFile(flagsFile)
|
flags, err := os.ReadFile(flagsFile)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -15,7 +15,6 @@ import (
|
||||||
"go/build"
|
"go/build"
|
||||||
"internal/testenv"
|
"internal/testenv"
|
||||||
"io/fs"
|
"io/fs"
|
||||||
"io/ioutil"
|
|
||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
|
@ -220,7 +219,7 @@ func (ts *testScript) run() {
|
||||||
for _, f := range a.Files {
|
for _, f := range a.Files {
|
||||||
name := ts.mkabs(ts.expand(f.Name, false))
|
name := ts.mkabs(ts.expand(f.Name, false))
|
||||||
ts.check(os.MkdirAll(filepath.Dir(name), 0777))
|
ts.check(os.MkdirAll(filepath.Dir(name), 0777))
|
||||||
ts.check(ioutil.WriteFile(name, f.Data, 0666))
|
ts.check(os.WriteFile(name, f.Data, 0666))
|
||||||
}
|
}
|
||||||
|
|
||||||
// With -v or -testwork, start log with full environment.
|
// With -v or -testwork, start log with full environment.
|
||||||
|
|
@ -377,19 +376,19 @@ var (
|
||||||
|
|
||||||
func isCaseSensitive(t *testing.T) bool {
|
func isCaseSensitive(t *testing.T) bool {
|
||||||
onceCaseSensitive.Do(func() {
|
onceCaseSensitive.Do(func() {
|
||||||
tmpdir, err := ioutil.TempDir("", "case-sensitive")
|
tmpdir, err := os.MkdirTemp("", "case-sensitive")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal("failed to create directory to determine case-sensitivity:", err)
|
t.Fatal("failed to create directory to determine case-sensitivity:", err)
|
||||||
}
|
}
|
||||||
defer os.RemoveAll(tmpdir)
|
defer os.RemoveAll(tmpdir)
|
||||||
|
|
||||||
fcap := filepath.Join(tmpdir, "FILE")
|
fcap := filepath.Join(tmpdir, "FILE")
|
||||||
if err := ioutil.WriteFile(fcap, []byte{}, 0644); err != nil {
|
if err := os.WriteFile(fcap, []byte{}, 0644); err != nil {
|
||||||
t.Fatal("error writing file to determine case-sensitivity:", err)
|
t.Fatal("error writing file to determine case-sensitivity:", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
flow := filepath.Join(tmpdir, "file")
|
flow := filepath.Join(tmpdir, "file")
|
||||||
_, err = ioutil.ReadFile(flow)
|
_, err = os.ReadFile(flow)
|
||||||
switch {
|
switch {
|
||||||
case err == nil:
|
case err == nil:
|
||||||
caseSensitive = false
|
caseSensitive = false
|
||||||
|
|
@ -450,9 +449,9 @@ func (ts *testScript) cmdAddcrlf(want simpleStatus, args []string) {
|
||||||
|
|
||||||
for _, file := range args {
|
for _, file := range args {
|
||||||
file = ts.mkabs(file)
|
file = ts.mkabs(file)
|
||||||
data, err := ioutil.ReadFile(file)
|
data, err := os.ReadFile(file)
|
||||||
ts.check(err)
|
ts.check(err)
|
||||||
ts.check(ioutil.WriteFile(file, bytes.ReplaceAll(data, []byte("\n"), []byte("\r\n")), 0666))
|
ts.check(os.WriteFile(file, bytes.ReplaceAll(data, []byte("\n"), []byte("\r\n")), 0666))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -557,12 +556,12 @@ func (ts *testScript) doCmdCmp(args []string, env, quiet bool) {
|
||||||
} else if name1 == "stderr" {
|
} else if name1 == "stderr" {
|
||||||
text1 = ts.stderr
|
text1 = ts.stderr
|
||||||
} else {
|
} else {
|
||||||
data, err := ioutil.ReadFile(ts.mkabs(name1))
|
data, err := os.ReadFile(ts.mkabs(name1))
|
||||||
ts.check(err)
|
ts.check(err)
|
||||||
text1 = string(data)
|
text1 = string(data)
|
||||||
}
|
}
|
||||||
|
|
||||||
data, err := ioutil.ReadFile(ts.mkabs(name2))
|
data, err := os.ReadFile(ts.mkabs(name2))
|
||||||
ts.check(err)
|
ts.check(err)
|
||||||
text2 = string(data)
|
text2 = string(data)
|
||||||
|
|
||||||
|
|
@ -614,14 +613,14 @@ func (ts *testScript) cmdCp(want simpleStatus, args []string) {
|
||||||
info, err := os.Stat(src)
|
info, err := os.Stat(src)
|
||||||
ts.check(err)
|
ts.check(err)
|
||||||
mode = info.Mode() & 0777
|
mode = info.Mode() & 0777
|
||||||
data, err = ioutil.ReadFile(src)
|
data, err = os.ReadFile(src)
|
||||||
ts.check(err)
|
ts.check(err)
|
||||||
}
|
}
|
||||||
targ := dst
|
targ := dst
|
||||||
if dstDir {
|
if dstDir {
|
||||||
targ = filepath.Join(dst, filepath.Base(src))
|
targ = filepath.Join(dst, filepath.Base(src))
|
||||||
}
|
}
|
||||||
err := ioutil.WriteFile(targ, data, mode)
|
err := os.WriteFile(targ, data, mode)
|
||||||
switch want {
|
switch want {
|
||||||
case failure:
|
case failure:
|
||||||
if err == nil {
|
if err == nil {
|
||||||
|
|
@ -897,7 +896,7 @@ func scriptMatch(ts *testScript, want simpleStatus, args []string, text, name st
|
||||||
isGrep := name == "grep"
|
isGrep := name == "grep"
|
||||||
if isGrep {
|
if isGrep {
|
||||||
name = args[1] // for error messages
|
name = args[1] // for error messages
|
||||||
data, err := ioutil.ReadFile(ts.mkabs(args[1]))
|
data, err := os.ReadFile(ts.mkabs(args[1]))
|
||||||
ts.check(err)
|
ts.check(err)
|
||||||
text = string(data)
|
text = string(data)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
13
src/cmd/go/testdata/addmod.go
vendored
13
src/cmd/go/testdata/addmod.go
vendored
|
|
@ -23,7 +23,6 @@ import (
|
||||||
"flag"
|
"flag"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/fs"
|
"io/fs"
|
||||||
"io/ioutil"
|
|
||||||
"log"
|
"log"
|
||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
|
|
@ -58,7 +57,7 @@ func main() {
|
||||||
log.SetFlags(0)
|
log.SetFlags(0)
|
||||||
|
|
||||||
var err error
|
var err error
|
||||||
tmpdir, err = ioutil.TempDir("", "addmod-")
|
tmpdir, err = os.MkdirTemp("", "addmod-")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
@ -82,7 +81,7 @@ func main() {
|
||||||
|
|
||||||
exitCode := 0
|
exitCode := 0
|
||||||
for _, arg := range flag.Args() {
|
for _, arg := range flag.Args() {
|
||||||
if err := ioutil.WriteFile(filepath.Join(tmpdir, "go.mod"), []byte("module m\n"), 0666); err != nil {
|
if err := os.WriteFile(filepath.Join(tmpdir, "go.mod"), []byte("module m\n"), 0666); err != nil {
|
||||||
fatalf("%v", err)
|
fatalf("%v", err)
|
||||||
}
|
}
|
||||||
run(goCmd, "get", "-d", arg)
|
run(goCmd, "get", "-d", arg)
|
||||||
|
|
@ -98,13 +97,13 @@ func main() {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
path, vers, dir := f[0], f[1], f[2]
|
path, vers, dir := f[0], f[1], f[2]
|
||||||
mod, err := ioutil.ReadFile(filepath.Join(gopath, "pkg/mod/cache/download", path, "@v", vers+".mod"))
|
mod, err := os.ReadFile(filepath.Join(gopath, "pkg/mod/cache/download", path, "@v", vers+".mod"))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("%s: %v", arg, err)
|
log.Printf("%s: %v", arg, err)
|
||||||
exitCode = 1
|
exitCode = 1
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
info, err := ioutil.ReadFile(filepath.Join(gopath, "pkg/mod/cache/download", path, "@v", vers+".info"))
|
info, err := os.ReadFile(filepath.Join(gopath, "pkg/mod/cache/download", path, "@v", vers+".info"))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("%s: %v", arg, err)
|
log.Printf("%s: %v", arg, err)
|
||||||
exitCode = 1
|
exitCode = 1
|
||||||
|
|
@ -128,7 +127,7 @@ func main() {
|
||||||
}
|
}
|
||||||
name := info.Name()
|
name := info.Name()
|
||||||
if name == "go.mod" || strings.HasSuffix(name, ".go") {
|
if name == "go.mod" || strings.HasSuffix(name, ".go") {
|
||||||
data, err := ioutil.ReadFile(path)
|
data, err := os.ReadFile(path)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
@ -144,7 +143,7 @@ func main() {
|
||||||
|
|
||||||
data := txtar.Format(a)
|
data := txtar.Format(a)
|
||||||
target := filepath.Join("mod", strings.ReplaceAll(path, "/", "_")+"_"+vers+".txt")
|
target := filepath.Join("mod", strings.ReplaceAll(path, "/", "_")+"_"+vers+".txt")
|
||||||
if err := ioutil.WriteFile(target, data, 0666); err != nil {
|
if err := os.WriteFile(target, data, 0666); err != nil {
|
||||||
log.Printf("%s: %v", arg, err)
|
log.Printf("%s: %v", arg, err)
|
||||||
exitCode = 1
|
exitCode = 1
|
||||||
continue
|
continue
|
||||||
|
|
|
||||||
3
src/cmd/go/testdata/savedir.go
vendored
3
src/cmd/go/testdata/savedir.go
vendored
|
|
@ -18,7 +18,6 @@ import (
|
||||||
"flag"
|
"flag"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/fs"
|
"io/fs"
|
||||||
"io/ioutil"
|
|
||||||
"log"
|
"log"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
|
@ -63,7 +62,7 @@ func main() {
|
||||||
if !info.Type().IsRegular() {
|
if !info.Type().IsRegular() {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
data, err := ioutil.ReadFile(path)
|
data, err := os.ReadFile(path)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -81,7 +81,6 @@ package main
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
|
||||||
"os"
|
"os"
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
@ -100,7 +99,7 @@ func truncateLike(t, p time.Time) time.Time {
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
var t1 time.Time
|
var t1 time.Time
|
||||||
b1, err := ioutil.ReadFile(os.Args[1])
|
b1, err := os.ReadFile(os.Args[1])
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Fprintln(os.Stderr, err)
|
fmt.Fprintln(os.Stderr, err)
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
|
|
@ -111,7 +110,7 @@ func main() {
|
||||||
}
|
}
|
||||||
|
|
||||||
var t2 time.Time
|
var t2 time.Time
|
||||||
b2, err := ioutil.ReadFile(os.Args[2])
|
b2, err := os.ReadFile(os.Args[2])
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Fprintln(os.Stderr, err)
|
fmt.Fprintln(os.Stderr, err)
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
|
|
|
||||||
|
|
@ -121,7 +121,6 @@ package main
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
|
||||||
"log"
|
"log"
|
||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
|
|
@ -131,7 +130,7 @@ import (
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
exe := os.Args[1]
|
exe := os.Args[1]
|
||||||
data, err := ioutil.ReadFile(exe)
|
data, err := os.ReadFile(exe)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
5
src/cmd/go/testdata/script/cover_error.txt
vendored
5
src/cmd/go/testdata/script/cover_error.txt
vendored
|
|
@ -54,7 +54,6 @@ func Test(t *testing.T) {}
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"io/ioutil"
|
|
||||||
"log"
|
"log"
|
||||||
"os"
|
"os"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
@ -62,13 +61,13 @@ import (
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
log.SetFlags(0)
|
log.SetFlags(0)
|
||||||
b, err := ioutil.ReadFile(os.Args[1])
|
b, err := os.ReadFile(os.Args[1])
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
s := strings.ReplaceAll(string(b), "p.go:4:2:", "p.go:4:")
|
s := strings.ReplaceAll(string(b), "p.go:4:2:", "p.go:4:")
|
||||||
s = strings.ReplaceAll(s, "p1.go:6:2:", "p1.go:6:")
|
s = strings.ReplaceAll(s, "p1.go:6:2:", "p1.go:6:")
|
||||||
ioutil.WriteFile(os.Args[1], []byte(s), 0644)
|
os.WriteFile(os.Args[1], []byte(s), 0644)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -45,7 +45,6 @@ package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"io/ioutil"
|
|
||||||
"log"
|
"log"
|
||||||
"os"
|
"os"
|
||||||
)
|
)
|
||||||
|
|
@ -57,11 +56,11 @@ func main() {
|
||||||
|
|
||||||
base := []byte(os.Args[1])
|
base := []byte(os.Args[1])
|
||||||
path := os.Args[2]
|
path := os.Args[2]
|
||||||
data, err := ioutil.ReadFile(path)
|
data, err := os.ReadFile(path)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
err = ioutil.WriteFile(path, bytes.ReplaceAll(data, base, append(base, "XXX"...)), 0644)
|
err = os.WriteFile(path, bytes.ReplaceAll(data, base, append(base, "XXX"...)), 0644)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -25,7 +25,6 @@ package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
|
||||||
"log"
|
"log"
|
||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
|
|
@ -45,7 +44,7 @@ func main() {
|
||||||
// don't need to clean the cache or synchronize closing files after each
|
// don't need to clean the cache or synchronize closing files after each
|
||||||
// iteration.
|
// iteration.
|
||||||
func run() (err error) {
|
func run() (err error) {
|
||||||
tmpDir, err := ioutil.TempDir("", "")
|
tmpDir, err := os.MkdirTemp("", "")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
|
||||||
3
src/cmd/go/testdata/script/mod_modinfo.txt
vendored
3
src/cmd/go/testdata/script/mod_modinfo.txt
vendored
|
|
@ -69,7 +69,6 @@ package main
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"encoding/hex"
|
"encoding/hex"
|
||||||
"io/ioutil"
|
|
||||||
"log"
|
"log"
|
||||||
"os"
|
"os"
|
||||||
|
|
||||||
|
|
@ -77,7 +76,7 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
b, err := ioutil.ReadFile(os.Args[0])
|
b, err := os.ReadFile(os.Args[0])
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -51,26 +51,25 @@ bar
|
||||||
package foo_test
|
package foo_test
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"io/ioutil"
|
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"testing"
|
"testing"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestWriteTmp(t *testing.T) {
|
func TestWriteTmp(t *testing.T) {
|
||||||
dir, err := ioutil.TempDir("", "")
|
dir, err := os.MkdirTemp("", "")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
defer os.RemoveAll(dir)
|
defer os.RemoveAll(dir)
|
||||||
err = ioutil.WriteFile(filepath.Join(dir, "x"), nil, 0666)
|
err = os.WriteFile(filepath.Join(dir, "x"), nil, 0666)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestReadTestdata(t *testing.T) {
|
func TestReadTestdata(t *testing.T) {
|
||||||
_, err := ioutil.ReadFile("testdata/foo.txt")
|
_, err := os.ReadFile("testdata/foo.txt")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
[short] skip
|
[short] skip
|
||||||
|
|
||||||
# Ensure that the target of 'go build -o' can be an existing, empty file so that
|
# Ensure that the target of 'go build -o' can be an existing, empty file so that
|
||||||
# its name can be reserved using ioutil.TempFile or the 'mktemp` command.
|
# its name can be reserved using os.CreateTemp or the 'mktemp` command.
|
||||||
|
|
||||||
go build -o empty-file$GOEXE main.go
|
go build -o empty-file$GOEXE main.go
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -12,7 +12,6 @@ package x
|
||||||
import (
|
import (
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"io/ioutil"
|
|
||||||
"regexp"
|
"regexp"
|
||||||
"testing"
|
"testing"
|
||||||
)
|
)
|
||||||
|
|
@ -23,7 +22,7 @@ func Test(t *testing.T) {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
testmainPath := filepath.Join(filepath.Dir(exePath), "_testmain.go")
|
testmainPath := filepath.Join(filepath.Dir(exePath), "_testmain.go")
|
||||||
source, err := ioutil.ReadFile(testmainPath)
|
source, err := os.ReadFile(testmainPath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -29,7 +29,6 @@ go 1.16
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"io/ioutil"
|
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
|
|
@ -37,7 +36,7 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
b, err := ioutil.ReadFile(os.Args[1])
|
b, err := os.ReadFile(os.Args[1])
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Fprintln(os.Stderr, err)
|
fmt.Fprintln(os.Stderr, err)
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
|
|
@ -59,7 +58,6 @@ package main
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
|
||||||
"os"
|
"os"
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
@ -67,7 +65,7 @@ import (
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
var t1 time.Time
|
var t1 time.Time
|
||||||
b1, err := ioutil.ReadFile(os.Args[1])
|
b1, err := os.ReadFile(os.Args[1])
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Fprintln(os.Stderr, err)
|
fmt.Fprintln(os.Stderr, err)
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
|
|
@ -78,7 +76,7 @@ func main() {
|
||||||
}
|
}
|
||||||
|
|
||||||
var t2 time.Time
|
var t2 time.Time
|
||||||
b2, err := ioutil.ReadFile(os.Args[2])
|
b2, err := os.ReadFile(os.Args[2])
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Fprintln(os.Stderr, err)
|
fmt.Fprintln(os.Stderr, err)
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
|
|
|
||||||
|
|
@ -15,7 +15,6 @@ import (
|
||||||
"go/token"
|
"go/token"
|
||||||
"io"
|
"io"
|
||||||
"io/fs"
|
"io/fs"
|
||||||
"io/ioutil"
|
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"runtime"
|
"runtime"
|
||||||
|
|
@ -137,7 +136,7 @@ func processFile(filename string, in io.Reader, out io.Writer, stdin bool) error
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
err = ioutil.WriteFile(filename, res, perm)
|
err = os.WriteFile(filename, res, perm)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
os.Rename(bakname, filename)
|
os.Rename(bakname, filename)
|
||||||
return err
|
return err
|
||||||
|
|
@ -278,7 +277,7 @@ const chmodSupported = runtime.GOOS != "windows"
|
||||||
// the chosen file name.
|
// the chosen file name.
|
||||||
func backupFile(filename string, data []byte, perm fs.FileMode) (string, error) {
|
func backupFile(filename string, data []byte, perm fs.FileMode) (string, error) {
|
||||||
// create backup file
|
// create backup file
|
||||||
f, err := ioutil.TempFile(filepath.Dir(filename), filepath.Base(filename))
|
f, err := os.CreateTemp(filepath.Dir(filename), filepath.Base(filename))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -7,7 +7,6 @@ package main
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"flag"
|
"flag"
|
||||||
"io/ioutil"
|
|
||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
|
@ -93,7 +92,7 @@ func runTest(t *testing.T, in, out string) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
expected, err := ioutil.ReadFile(out)
|
expected, err := os.ReadFile(out)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Error(err)
|
t.Error(err)
|
||||||
return
|
return
|
||||||
|
|
@ -102,7 +101,7 @@ func runTest(t *testing.T, in, out string) {
|
||||||
if got := buf.Bytes(); !bytes.Equal(got, expected) {
|
if got := buf.Bytes(); !bytes.Equal(got, expected) {
|
||||||
if *update {
|
if *update {
|
||||||
if in != out {
|
if in != out {
|
||||||
if err := ioutil.WriteFile(out, got, 0666); err != nil {
|
if err := os.WriteFile(out, got, 0666); err != nil {
|
||||||
t.Error(err)
|
t.Error(err)
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
|
|
@ -116,7 +115,7 @@ func runTest(t *testing.T, in, out string) {
|
||||||
if err == nil {
|
if err == nil {
|
||||||
t.Errorf("%s", d)
|
t.Errorf("%s", d)
|
||||||
}
|
}
|
||||||
if err := ioutil.WriteFile(in+".gofmt", got, 0666); err != nil {
|
if err := os.WriteFile(in+".gofmt", got, 0666); err != nil {
|
||||||
t.Error(err)
|
t.Error(err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -157,7 +156,7 @@ func TestCRLF(t *testing.T) {
|
||||||
const input = "testdata/crlf.input" // must contain CR/LF's
|
const input = "testdata/crlf.input" // must contain CR/LF's
|
||||||
const golden = "testdata/crlf.golden" // must not contain any CR's
|
const golden = "testdata/crlf.golden" // must not contain any CR's
|
||||||
|
|
||||||
data, err := ioutil.ReadFile(input)
|
data, err := os.ReadFile(input)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Error(err)
|
t.Error(err)
|
||||||
}
|
}
|
||||||
|
|
@ -165,7 +164,7 @@ func TestCRLF(t *testing.T) {
|
||||||
t.Errorf("%s contains no CR/LF's", input)
|
t.Errorf("%s contains no CR/LF's", input)
|
||||||
}
|
}
|
||||||
|
|
||||||
data, err = ioutil.ReadFile(golden)
|
data, err = os.ReadFile(golden)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Error(err)
|
t.Error(err)
|
||||||
}
|
}
|
||||||
|
|
@ -175,7 +174,7 @@ func TestCRLF(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestBackupFile(t *testing.T) {
|
func TestBackupFile(t *testing.T) {
|
||||||
dir, err := ioutil.TempDir("", "gofmt_test")
|
dir, err := os.MkdirTemp("", "gofmt_test")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -8,7 +8,6 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"internal/obscuretestdata"
|
"internal/obscuretestdata"
|
||||||
"internal/testenv"
|
"internal/testenv"
|
||||||
"io/ioutil"
|
|
||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
|
@ -31,7 +30,7 @@ func testMain(m *testing.M) int {
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
tmpDir, err := ioutil.TempDir("", "TestNM")
|
tmpDir, err := os.MkdirTemp("", "TestNM")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println("TempDir failed:", err)
|
fmt.Println("TempDir failed:", err)
|
||||||
return 2
|
return 2
|
||||||
|
|
@ -88,7 +87,7 @@ func TestNonGoExecs(t *testing.T) {
|
||||||
|
|
||||||
func testGoExec(t *testing.T, iscgo, isexternallinker bool) {
|
func testGoExec(t *testing.T, iscgo, isexternallinker bool) {
|
||||||
t.Parallel()
|
t.Parallel()
|
||||||
tmpdir, err := ioutil.TempDir("", "TestGoExec")
|
tmpdir, err := os.MkdirTemp("", "TestGoExec")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
@ -222,7 +221,7 @@ func TestGoExec(t *testing.T) {
|
||||||
|
|
||||||
func testGoLib(t *testing.T, iscgo bool) {
|
func testGoLib(t *testing.T, iscgo bool) {
|
||||||
t.Parallel()
|
t.Parallel()
|
||||||
tmpdir, err := ioutil.TempDir("", "TestGoLib")
|
tmpdir, err := os.MkdirTemp("", "TestGoLib")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
@ -245,7 +244,7 @@ func testGoLib(t *testing.T, iscgo bool) {
|
||||||
err = e
|
err = e
|
||||||
}
|
}
|
||||||
if err == nil {
|
if err == nil {
|
||||||
err = ioutil.WriteFile(filepath.Join(libpath, "go.mod"), []byte("module mylib\n"), 0666)
|
err = os.WriteFile(filepath.Join(libpath, "go.mod"), []byte("module mylib\n"), 0666)
|
||||||
}
|
}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
|
|
|
||||||
|
|
@ -10,7 +10,6 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"go/build"
|
"go/build"
|
||||||
"internal/testenv"
|
"internal/testenv"
|
||||||
"io/ioutil"
|
|
||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
|
@ -39,7 +38,7 @@ func TestMain(m *testing.M) {
|
||||||
|
|
||||||
func buildObjdump() error {
|
func buildObjdump() error {
|
||||||
var err error
|
var err error
|
||||||
tmp, err = ioutil.TempDir("", "TestObjDump")
|
tmp, err = os.MkdirTemp("", "TestObjDump")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("TempDir failed: %v", err)
|
return fmt.Errorf("TempDir failed: %v", err)
|
||||||
}
|
}
|
||||||
|
|
@ -320,7 +319,7 @@ func TestGoobjFileNumber(t *testing.T) {
|
||||||
|
|
||||||
t.Parallel()
|
t.Parallel()
|
||||||
|
|
||||||
tmpdir, err := ioutil.TempDir("", "TestGoobjFileNumber")
|
tmpdir, err := os.MkdirTemp("", "TestGoobjFileNumber")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -12,7 +12,6 @@ import (
|
||||||
"internal/testenv"
|
"internal/testenv"
|
||||||
"io"
|
"io"
|
||||||
"io/fs"
|
"io/fs"
|
||||||
"io/ioutil"
|
|
||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
|
@ -22,7 +21,7 @@ import (
|
||||||
|
|
||||||
// tmpDir creates a temporary directory and returns its name.
|
// tmpDir creates a temporary directory and returns its name.
|
||||||
func tmpDir(t *testing.T) string {
|
func tmpDir(t *testing.T) string {
|
||||||
name, err := ioutil.TempDir("", "pack")
|
name, err := os.MkdirTemp("", "pack")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
@ -158,7 +157,7 @@ func TestExtract(t *testing.T) {
|
||||||
ar = openArchive(name, os.O_RDONLY, []string{goodbyeFile.name})
|
ar = openArchive(name, os.O_RDONLY, []string{goodbyeFile.name})
|
||||||
ar.scan(ar.extractContents)
|
ar.scan(ar.extractContents)
|
||||||
ar.a.File().Close()
|
ar.a.File().Close()
|
||||||
data, err := ioutil.ReadFile(goodbyeFile.name)
|
data, err := os.ReadFile(goodbyeFile.name)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
@ -183,7 +182,7 @@ func TestHello(t *testing.T) {
|
||||||
println("hello world")
|
println("hello world")
|
||||||
}
|
}
|
||||||
`
|
`
|
||||||
err := ioutil.WriteFile(hello, []byte(prog), 0666)
|
err := os.WriteFile(hello, []byte(prog), 0666)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
@ -251,7 +250,7 @@ func TestLargeDefs(t *testing.T) {
|
||||||
println("ok")
|
println("ok")
|
||||||
}
|
}
|
||||||
`
|
`
|
||||||
err = ioutil.WriteFile(main, []byte(prog), 0666)
|
err = os.WriteFile(main, []byte(prog), 0666)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
@ -281,13 +280,13 @@ func TestIssue21703(t *testing.T) {
|
||||||
defer os.RemoveAll(dir)
|
defer os.RemoveAll(dir)
|
||||||
|
|
||||||
const aSrc = `package a; const X = "\n!\n"`
|
const aSrc = `package a; const X = "\n!\n"`
|
||||||
err := ioutil.WriteFile(filepath.Join(dir, "a.go"), []byte(aSrc), 0666)
|
err := os.WriteFile(filepath.Join(dir, "a.go"), []byte(aSrc), 0666)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
const bSrc = `package b; import _ "a"`
|
const bSrc = `package b; import _ "a"`
|
||||||
err = ioutil.WriteFile(filepath.Join(dir, "b.go"), []byte(bSrc), 0666)
|
err = os.WriteFile(filepath.Join(dir, "b.go"), []byte(bSrc), 0666)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -12,7 +12,7 @@ import (
|
||||||
"flag"
|
"flag"
|
||||||
"fmt"
|
"fmt"
|
||||||
traceparser "internal/trace"
|
traceparser "internal/trace"
|
||||||
"io/ioutil"
|
"os"
|
||||||
"reflect"
|
"reflect"
|
||||||
"runtime/debug"
|
"runtime/debug"
|
||||||
"runtime/trace"
|
"runtime/trace"
|
||||||
|
|
@ -386,7 +386,7 @@ func saveTrace(buf *bytes.Buffer, name string) {
|
||||||
if !*saveTraces {
|
if !*saveTraces {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if err := ioutil.WriteFile(name+".trace", buf.Bytes(), 0600); err != nil {
|
if err := os.WriteFile(name+".trace", buf.Bytes(), 0600); err != nil {
|
||||||
panic(fmt.Errorf("failed to write trace file: %v", err))
|
panic(fmt.Errorf("failed to write trace file: %v", err))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -11,7 +11,6 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"internal/trace"
|
"internal/trace"
|
||||||
"io"
|
"io"
|
||||||
"io/ioutil"
|
|
||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
|
|
@ -294,7 +293,7 @@ func serveSVGProfile(prof func(w io.Writer, r *http.Request) error) http.Handler
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
blockf, err := ioutil.TempFile("", "block")
|
blockf, err := os.CreateTemp("", "block")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
http.Error(w, fmt.Sprintf("failed to create temp file: %v", err), http.StatusInternalServerError)
|
http.Error(w, fmt.Sprintf("failed to create temp file: %v", err), http.StatusInternalServerError)
|
||||||
return
|
return
|
||||||
|
|
|
||||||
|
|
@ -9,7 +9,6 @@ import (
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"internal/testenv"
|
"internal/testenv"
|
||||||
"io/ioutil"
|
|
||||||
"log"
|
"log"
|
||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
|
|
@ -32,7 +31,7 @@ func TestMain(m *testing.M) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func testMain(m *testing.M) int {
|
func testMain(m *testing.M) int {
|
||||||
dir, err := ioutil.TempDir("", "vet_test")
|
dir, err := os.MkdirTemp("", "vet_test")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Fprintln(os.Stderr, err)
|
fmt.Fprintln(os.Stderr, err)
|
||||||
return 1
|
return 1
|
||||||
|
|
@ -345,7 +344,7 @@ var (
|
||||||
func wantedErrors(file, short string) (errs []wantedError) {
|
func wantedErrors(file, short string) (errs []wantedError) {
|
||||||
cache := make(map[string]*regexp.Regexp)
|
cache := make(map[string]*regexp.Regexp)
|
||||||
|
|
||||||
src, err := ioutil.ReadFile(file)
|
src, err := os.ReadFile(file)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -9,7 +9,7 @@ import (
|
||||||
"encoding/hex"
|
"encoding/hex"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"io/ioutil"
|
"os"
|
||||||
"testing"
|
"testing"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
@ -22,7 +22,7 @@ func mustDecodeHex(s string) []byte {
|
||||||
}
|
}
|
||||||
|
|
||||||
func mustLoadFile(f string) []byte {
|
func mustLoadFile(f string) []byte {
|
||||||
b, err := ioutil.ReadFile(f)
|
b, err := os.ReadFile(f)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -10,8 +10,8 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"internal/testenv"
|
"internal/testenv"
|
||||||
"io"
|
"io"
|
||||||
"io/ioutil"
|
|
||||||
"math/rand"
|
"math/rand"
|
||||||
|
"os"
|
||||||
"reflect"
|
"reflect"
|
||||||
"runtime/debug"
|
"runtime/debug"
|
||||||
"sync"
|
"sync"
|
||||||
|
|
@ -387,7 +387,7 @@ func TestDeflateInflateString(t *testing.T) {
|
||||||
t.Skip("skipping in short mode")
|
t.Skip("skipping in short mode")
|
||||||
}
|
}
|
||||||
for _, test := range deflateInflateStringTests {
|
for _, test := range deflateInflateStringTests {
|
||||||
gold, err := ioutil.ReadFile(test.filename)
|
gold, err := os.ReadFile(test.filename)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Error(err)
|
t.Error(err)
|
||||||
}
|
}
|
||||||
|
|
@ -685,7 +685,7 @@ func (w *failWriter) Write(b []byte) (int, error) {
|
||||||
|
|
||||||
func TestWriterPersistentError(t *testing.T) {
|
func TestWriterPersistentError(t *testing.T) {
|
||||||
t.Parallel()
|
t.Parallel()
|
||||||
d, err := ioutil.ReadFile("../../testdata/Isaac.Newton-Opticks.txt")
|
d, err := os.ReadFile("../../testdata/Isaac.Newton-Opticks.txt")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("ReadFile: %v", err)
|
t.Fatalf("ReadFile: %v", err)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -8,7 +8,6 @@ import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"flag"
|
"flag"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
@ -38,7 +37,7 @@ func TestBlockHuff(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func testBlockHuff(t *testing.T, in, out string) {
|
func testBlockHuff(t *testing.T, in, out string) {
|
||||||
all, err := ioutil.ReadFile(in)
|
all, err := os.ReadFile(in)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Error(err)
|
t.Error(err)
|
||||||
return
|
return
|
||||||
|
|
@ -49,7 +48,7 @@ func testBlockHuff(t *testing.T, in, out string) {
|
||||||
bw.flush()
|
bw.flush()
|
||||||
got := buf.Bytes()
|
got := buf.Bytes()
|
||||||
|
|
||||||
want, err := ioutil.ReadFile(out)
|
want, err := os.ReadFile(out)
|
||||||
if err != nil && !*update {
|
if err != nil && !*update {
|
||||||
t.Error(err)
|
t.Error(err)
|
||||||
return
|
return
|
||||||
|
|
@ -60,7 +59,7 @@ func testBlockHuff(t *testing.T, in, out string) {
|
||||||
if *update {
|
if *update {
|
||||||
if in != out {
|
if in != out {
|
||||||
t.Logf("Updating %q", out)
|
t.Logf("Updating %q", out)
|
||||||
if err := ioutil.WriteFile(out, got, 0666); err != nil {
|
if err := os.WriteFile(out, got, 0666); err != nil {
|
||||||
t.Error(err)
|
t.Error(err)
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
|
|
@ -70,7 +69,7 @@ func testBlockHuff(t *testing.T, in, out string) {
|
||||||
}
|
}
|
||||||
|
|
||||||
t.Errorf("%q != %q (see %q)", in, out, in+".got")
|
t.Errorf("%q != %q (see %q)", in, out, in+".got")
|
||||||
if err := ioutil.WriteFile(in+".got", got, 0666); err != nil {
|
if err := os.WriteFile(in+".got", got, 0666); err != nil {
|
||||||
t.Error(err)
|
t.Error(err)
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
|
|
@ -85,7 +84,7 @@ func testBlockHuff(t *testing.T, in, out string) {
|
||||||
got = buf.Bytes()
|
got = buf.Bytes()
|
||||||
if !bytes.Equal(got, want) {
|
if !bytes.Equal(got, want) {
|
||||||
t.Errorf("after reset %q != %q (see %q)", in, out, in+".reset.got")
|
t.Errorf("after reset %q != %q (see %q)", in, out, in+".reset.got")
|
||||||
if err := ioutil.WriteFile(in+".reset.got", got, 0666); err != nil {
|
if err := os.WriteFile(in+".reset.got", got, 0666); err != nil {
|
||||||
t.Error(err)
|
t.Error(err)
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
|
|
@ -186,7 +185,7 @@ func testBlock(t *testing.T, test huffTest, ttype string) {
|
||||||
if *update {
|
if *update {
|
||||||
if test.input != "" {
|
if test.input != "" {
|
||||||
t.Logf("Updating %q", test.want)
|
t.Logf("Updating %q", test.want)
|
||||||
input, err := ioutil.ReadFile(test.input)
|
input, err := os.ReadFile(test.input)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Error(err)
|
t.Error(err)
|
||||||
return
|
return
|
||||||
|
|
@ -216,12 +215,12 @@ func testBlock(t *testing.T, test huffTest, ttype string) {
|
||||||
|
|
||||||
if test.input != "" {
|
if test.input != "" {
|
||||||
t.Logf("Testing %q", test.want)
|
t.Logf("Testing %q", test.want)
|
||||||
input, err := ioutil.ReadFile(test.input)
|
input, err := os.ReadFile(test.input)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Error(err)
|
t.Error(err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
want, err := ioutil.ReadFile(test.want)
|
want, err := os.ReadFile(test.want)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Error(err)
|
t.Error(err)
|
||||||
return
|
return
|
||||||
|
|
@ -233,7 +232,7 @@ func testBlock(t *testing.T, test huffTest, ttype string) {
|
||||||
got := buf.Bytes()
|
got := buf.Bytes()
|
||||||
if !bytes.Equal(got, want) {
|
if !bytes.Equal(got, want) {
|
||||||
t.Errorf("writeBlock did not yield expected result for file %q with input. See %q", test.want, test.want+".got")
|
t.Errorf("writeBlock did not yield expected result for file %q with input. See %q", test.want, test.want+".got")
|
||||||
if err := ioutil.WriteFile(test.want+".got", got, 0666); err != nil {
|
if err := os.WriteFile(test.want+".got", got, 0666); err != nil {
|
||||||
t.Error(err)
|
t.Error(err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -247,7 +246,7 @@ func testBlock(t *testing.T, test huffTest, ttype string) {
|
||||||
got = buf.Bytes()
|
got = buf.Bytes()
|
||||||
if !bytes.Equal(got, want) {
|
if !bytes.Equal(got, want) {
|
||||||
t.Errorf("reset: writeBlock did not yield expected result for file %q with input. See %q", test.want, test.want+".reset.got")
|
t.Errorf("reset: writeBlock did not yield expected result for file %q with input. See %q", test.want, test.want+".reset.got")
|
||||||
if err := ioutil.WriteFile(test.want+".reset.got", got, 0666); err != nil {
|
if err := os.WriteFile(test.want+".reset.got", got, 0666); err != nil {
|
||||||
t.Error(err)
|
t.Error(err)
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
|
|
@ -256,7 +255,7 @@ func testBlock(t *testing.T, test huffTest, ttype string) {
|
||||||
testWriterEOF(t, "wb", test, true)
|
testWriterEOF(t, "wb", test, true)
|
||||||
}
|
}
|
||||||
t.Logf("Testing %q", test.wantNoInput)
|
t.Logf("Testing %q", test.wantNoInput)
|
||||||
wantNI, err := ioutil.ReadFile(test.wantNoInput)
|
wantNI, err := os.ReadFile(test.wantNoInput)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Error(err)
|
t.Error(err)
|
||||||
return
|
return
|
||||||
|
|
@ -268,7 +267,7 @@ func testBlock(t *testing.T, test huffTest, ttype string) {
|
||||||
got := buf.Bytes()
|
got := buf.Bytes()
|
||||||
if !bytes.Equal(got, wantNI) {
|
if !bytes.Equal(got, wantNI) {
|
||||||
t.Errorf("writeBlock did not yield expected result for file %q with input. See %q", test.wantNoInput, test.wantNoInput+".got")
|
t.Errorf("writeBlock did not yield expected result for file %q with input. See %q", test.wantNoInput, test.wantNoInput+".got")
|
||||||
if err := ioutil.WriteFile(test.want+".got", got, 0666); err != nil {
|
if err := os.WriteFile(test.want+".got", got, 0666); err != nil {
|
||||||
t.Error(err)
|
t.Error(err)
|
||||||
}
|
}
|
||||||
} else if got[0]&1 == 1 {
|
} else if got[0]&1 == 1 {
|
||||||
|
|
@ -286,7 +285,7 @@ func testBlock(t *testing.T, test huffTest, ttype string) {
|
||||||
got = buf.Bytes()
|
got = buf.Bytes()
|
||||||
if !bytes.Equal(got, wantNI) {
|
if !bytes.Equal(got, wantNI) {
|
||||||
t.Errorf("reset: writeBlock did not yield expected result for file %q without input. See %q", test.want, test.want+".reset.got")
|
t.Errorf("reset: writeBlock did not yield expected result for file %q without input. See %q", test.want, test.want+".reset.got")
|
||||||
if err := ioutil.WriteFile(test.want+".reset.got", got, 0666); err != nil {
|
if err := os.WriteFile(test.want+".reset.got", got, 0666); err != nil {
|
||||||
t.Error(err)
|
t.Error(err)
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
|
|
@ -325,7 +324,7 @@ func testWriterEOF(t *testing.T, ttype string, test huffTest, useInput bool) {
|
||||||
var input []byte
|
var input []byte
|
||||||
if useInput {
|
if useInput {
|
||||||
var err error
|
var err error
|
||||||
input, err = ioutil.ReadFile(test.input)
|
input, err = os.ReadFile(test.input)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Error(err)
|
t.Error(err)
|
||||||
return
|
return
|
||||||
|
|
|
||||||
|
|
@ -7,7 +7,7 @@ package flate
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"io"
|
"io"
|
||||||
"io/ioutil"
|
"os"
|
||||||
"runtime"
|
"runtime"
|
||||||
"strings"
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
@ -80,7 +80,7 @@ var sizes = []struct {
|
||||||
|
|
||||||
func doBench(b *testing.B, f func(b *testing.B, buf []byte, level, n int)) {
|
func doBench(b *testing.B, f func(b *testing.B, buf []byte, level, n int)) {
|
||||||
for _, suite := range suites {
|
for _, suite := range suites {
|
||||||
buf, err := ioutil.ReadFile(suite.file)
|
buf, err := os.ReadFile(suite.file)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
b.Fatal(err)
|
b.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -8,8 +8,8 @@ import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"io/ioutil"
|
|
||||||
"math"
|
"math"
|
||||||
|
"os"
|
||||||
"runtime"
|
"runtime"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
@ -218,7 +218,7 @@ func TestNoLongerSavingPriorExpansions(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func BenchmarkDecoder(b *testing.B) {
|
func BenchmarkDecoder(b *testing.B) {
|
||||||
buf, err := ioutil.ReadFile("../testdata/e.txt")
|
buf, err := os.ReadFile("../testdata/e.txt")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
b.Fatal(err)
|
b.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -8,7 +8,6 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"internal/testenv"
|
"internal/testenv"
|
||||||
"io"
|
"io"
|
||||||
"io/ioutil"
|
|
||||||
"math"
|
"math"
|
||||||
"os"
|
"os"
|
||||||
"runtime"
|
"runtime"
|
||||||
|
|
@ -125,7 +124,7 @@ func TestSmallLitWidth(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func BenchmarkEncoder(b *testing.B) {
|
func BenchmarkEncoder(b *testing.B) {
|
||||||
buf, err := ioutil.ReadFile("../testdata/e.txt")
|
buf, err := os.ReadFile("../testdata/e.txt")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
b.Fatal(err)
|
b.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -9,7 +9,6 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"internal/testenv"
|
"internal/testenv"
|
||||||
"io"
|
"io"
|
||||||
"io/ioutil"
|
|
||||||
"os"
|
"os"
|
||||||
"testing"
|
"testing"
|
||||||
)
|
)
|
||||||
|
|
@ -95,7 +94,7 @@ func testFileLevelDictReset(t *testing.T, fn string, level int, dict []byte) {
|
||||||
var b0 []byte
|
var b0 []byte
|
||||||
var err error
|
var err error
|
||||||
if fn != "" {
|
if fn != "" {
|
||||||
b0, err = ioutil.ReadFile(fn)
|
b0, err = os.ReadFile(fn)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("%s (level=%d): %v", fn, level, err)
|
t.Errorf("%s (level=%d): %v", fn, level, err)
|
||||||
return
|
return
|
||||||
|
|
|
||||||
|
|
@ -15,8 +15,8 @@ import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"flag"
|
"flag"
|
||||||
"go/format"
|
"go/format"
|
||||||
"io/ioutil"
|
|
||||||
"log"
|
"log"
|
||||||
|
"os"
|
||||||
"strings"
|
"strings"
|
||||||
"text/template"
|
"text/template"
|
||||||
)
|
)
|
||||||
|
|
@ -37,7 +37,7 @@ func main() {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
err = ioutil.WriteFile(*filename, data, 0644)
|
err = os.WriteFile(*filename, data, 0644)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -13,7 +13,6 @@ import (
|
||||||
"flag"
|
"flag"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"io/ioutil"
|
|
||||||
"net"
|
"net"
|
||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
|
|
@ -224,7 +223,7 @@ func parseTestData(r io.Reader) (flows [][]byte, err error) {
|
||||||
|
|
||||||
// tempFile creates a temp file containing contents and returns its path.
|
// tempFile creates a temp file containing contents and returns its path.
|
||||||
func tempFile(contents string) string {
|
func tempFile(contents string) string {
|
||||||
file, err := ioutil.TempFile("", "go-tls-test")
|
file, err := os.CreateTemp("", "go-tls-test")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic("failed to create temp file: " + err.Error())
|
panic("failed to create temp file: " + err.Error())
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -7,7 +7,6 @@ package tls
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"internal/testenv"
|
"internal/testenv"
|
||||||
"io/ioutil"
|
|
||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
|
@ -77,7 +76,7 @@ func main() { tls.Dial("", "", nil) }
|
||||||
exeFile := filepath.Join(tmpDir, "x.exe")
|
exeFile := filepath.Join(tmpDir, "x.exe")
|
||||||
for _, tt := range tests {
|
for _, tt := range tests {
|
||||||
t.Run(tt.name, func(t *testing.T) {
|
t.Run(tt.name, func(t *testing.T) {
|
||||||
if err := ioutil.WriteFile(goFile, []byte(tt.program), 0644); err != nil {
|
if err := os.WriteFile(goFile, []byte(tt.program), 0644); err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
os.Remove(exeFile)
|
os.Remove(exeFile)
|
||||||
|
|
|
||||||
|
|
@ -22,8 +22,8 @@ import (
|
||||||
"encoding/pem"
|
"encoding/pem"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
|
||||||
"net"
|
"net"
|
||||||
|
"os"
|
||||||
"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
@ -222,11 +222,11 @@ func (d *Dialer) DialContext(ctx context.Context, network, addr string) (net.Con
|
||||||
// form a certificate chain. On successful return, Certificate.Leaf will
|
// form a certificate chain. On successful return, Certificate.Leaf will
|
||||||
// be nil because the parsed form of the certificate is not retained.
|
// be nil because the parsed form of the certificate is not retained.
|
||||||
func LoadX509KeyPair(certFile, keyFile string) (Certificate, error) {
|
func LoadX509KeyPair(certFile, keyFile string) (Certificate, error) {
|
||||||
certPEMBlock, err := ioutil.ReadFile(certFile)
|
certPEMBlock, err := os.ReadFile(certFile)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return Certificate{}, err
|
return Certificate{}, err
|
||||||
}
|
}
|
||||||
keyPEMBlock, err := ioutil.ReadFile(keyFile)
|
keyPEMBlock, err := os.ReadFile(keyFile)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return Certificate{}, err
|
return Certificate{}, err
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -14,7 +14,6 @@ import (
|
||||||
"encoding/hex"
|
"encoding/hex"
|
||||||
"encoding/pem"
|
"encoding/pem"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
|
||||||
"math/big"
|
"math/big"
|
||||||
"net"
|
"net"
|
||||||
"net/url"
|
"net/url"
|
||||||
|
|
@ -2005,7 +2004,7 @@ func TestConstraintCases(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func writePEMsToTempFile(certs []*Certificate) *os.File {
|
func writePEMsToTempFile(certs []*Certificate) *os.File {
|
||||||
file, err := ioutil.TempFile("", "name_constraints_test")
|
file, err := os.CreateTemp("", "name_constraints_test")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic("cannot create tempfile")
|
panic("cannot create tempfile")
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -27,9 +27,9 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"go/format"
|
"go/format"
|
||||||
"io"
|
"io"
|
||||||
"io/ioutil"
|
|
||||||
"log"
|
"log"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"os"
|
||||||
"path"
|
"path"
|
||||||
"sort"
|
"sort"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
@ -155,7 +155,7 @@ func main() {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
if err := ioutil.WriteFile(*output, source, 0644); err != nil {
|
if err := os.WriteFile(*output, source, 0644); err != nil {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -7,7 +7,6 @@
|
||||||
package x509
|
package x509
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"io/ioutil"
|
|
||||||
"os"
|
"os"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
@ -24,7 +23,7 @@ func loadSystemRoots() (*CertPool, error) {
|
||||||
roots := NewCertPool()
|
roots := NewCertPool()
|
||||||
var bestErr error
|
var bestErr error
|
||||||
for _, file := range certFiles {
|
for _, file := range certFiles {
|
||||||
data, err := ioutil.ReadFile(file)
|
data, err := os.ReadFile(file)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
roots.AppendCertsFromPEM(data)
|
roots.AppendCertsFromPEM(data)
|
||||||
return roots, nil
|
return roots, nil
|
||||||
|
|
|
||||||
|
|
@ -40,7 +40,7 @@ func loadSystemRoots() (*CertPool, error) {
|
||||||
|
|
||||||
var firstErr error
|
var firstErr error
|
||||||
for _, file := range files {
|
for _, file := range files {
|
||||||
data, err := ioutil.ReadFile(file)
|
data, err := os.ReadFile(file)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
roots.AppendCertsFromPEM(data)
|
roots.AppendCertsFromPEM(data)
|
||||||
break
|
break
|
||||||
|
|
@ -68,7 +68,7 @@ func loadSystemRoots() (*CertPool, error) {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
for _, fi := range fis {
|
for _, fi := range fis {
|
||||||
data, err := ioutil.ReadFile(directory + "/" + fi.Name())
|
data, err := os.ReadFile(directory + "/" + fi.Name())
|
||||||
if err == nil {
|
if err == nil {
|
||||||
roots.AppendCertsFromPEM(data)
|
roots.AppendCertsFromPEM(data)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -9,7 +9,6 @@ package x509
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"reflect"
|
"reflect"
|
||||||
|
|
@ -147,7 +146,7 @@ func TestLoadSystemCertsLoadColonSeparatedDirs(t *testing.T) {
|
||||||
os.Setenv(certFileEnv, origFile)
|
os.Setenv(certFileEnv, origFile)
|
||||||
}()
|
}()
|
||||||
|
|
||||||
tmpDir, err := ioutil.TempDir(os.TempDir(), "x509-issue35325")
|
tmpDir, err := os.MkdirTemp(os.TempDir(), "x509-issue35325")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("Failed to create temporary directory: %v", err)
|
t.Fatalf("Failed to create temporary directory: %v", err)
|
||||||
}
|
}
|
||||||
|
|
@ -166,7 +165,7 @@ func TestLoadSystemCertsLoadColonSeparatedDirs(t *testing.T) {
|
||||||
t.Fatalf("Failed to create certificate dir: %v", err)
|
t.Fatalf("Failed to create certificate dir: %v", err)
|
||||||
}
|
}
|
||||||
certOutFile := filepath.Join(certDir, "cert.crt")
|
certOutFile := filepath.Join(certDir, "cert.crt")
|
||||||
if err := ioutil.WriteFile(certOutFile, []byte(certPEM), 0655); err != nil {
|
if err := os.WriteFile(certOutFile, []byte(certPEM), 0655); err != nil {
|
||||||
t.Fatalf("Failed to write certificate to file: %v", err)
|
t.Fatalf("Failed to write certificate to file: %v", err)
|
||||||
}
|
}
|
||||||
certDirs = append(certDirs, certDir)
|
certDirs = append(certDirs, certDir)
|
||||||
|
|
|
||||||
Some files were not shown because too many files have changed in this diff Show more
Loading…
Add table
Add a link
Reference in a new issue