diff --git a/build.go b/build.go index 791ca9a41..2a480a546 100644 --- a/build.go +++ b/build.go @@ -20,7 +20,6 @@ import ( "flag" "fmt" "io" - "io/ioutil" "log" "os" "os/exec" @@ -723,7 +722,7 @@ func shouldBuildSyso(dir string) (string, error) { } jsonPath := filepath.Join(dir, "versioninfo.json") - err = ioutil.WriteFile(jsonPath, bs, 0644) + err = os.WriteFile(jsonPath, bs, 0644) if err != nil { return "", errors.New("failed to create " + jsonPath + ": " + err.Error()) } @@ -762,12 +761,12 @@ func shouldCleanupSyso(sysoFilePath string) { // exists. The permission bits are copied as well. If dst already exists and // the contents are identical to src the modification time is not updated. func copyFile(src, dst string, perm os.FileMode) error { - in, err := ioutil.ReadFile(src) + in, err := os.ReadFile(src) if err != nil { return err } - out, err := ioutil.ReadFile(dst) + out, err := os.ReadFile(dst) if err != nil { // The destination probably doesn't exist, we should create // it. @@ -783,7 +782,7 @@ func copyFile(src, dst string, perm os.FileMode) error { copy: os.MkdirAll(filepath.Dir(dst), 0777) - if err := ioutil.WriteFile(dst, in, perm); err != nil { + if err := os.WriteFile(dst, in, perm); err != nil { return err } @@ -958,7 +957,7 @@ func rmr(paths ...string) { } func getReleaseVersion() (string, error) { - bs, err := ioutil.ReadFile("RELEASE") + bs, err := os.ReadFile("RELEASE") if err != nil { return "", err } @@ -1290,7 +1289,7 @@ func zipFile(out string, files []archiveFile) { if strings.HasSuffix(f.dst, ".txt") { // Text file. Read it and convert line endings. - bs, err := ioutil.ReadAll(sf) + bs, err := io.ReadAll(sf) if err != nil { log.Fatal(err) } diff --git a/cmd/stcrashreceiver/main.go b/cmd/stcrashreceiver/main.go index 31ee52ae6..c6a187161 100644 --- a/cmd/stcrashreceiver/main.go +++ b/cmd/stcrashreceiver/main.go @@ -17,7 +17,6 @@ import ( "flag" "fmt" "io" - "io/ioutil" "log" "net/http" "os" @@ -58,7 +57,7 @@ func main() { func handleFailureFn(dsn, failureDir string) func(w http.ResponseWriter, req *http.Request) { return func(w http.ResponseWriter, req *http.Request) { lr := io.LimitReader(req.Body, maxRequestSize) - bs, err := ioutil.ReadAll(lr) + bs, err := io.ReadAll(lr) req.Body.Close() if err != nil { http.Error(w, err.Error(), 500) diff --git a/cmd/stcrashreceiver/sentry.go b/cmd/stcrashreceiver/sentry.go index 5aa8a7c28..e49eba888 100644 --- a/cmd/stcrashreceiver/sentry.go +++ b/cmd/stcrashreceiver/sentry.go @@ -9,7 +9,7 @@ package main import ( "bytes" "errors" - "io/ioutil" + "io" "regexp" "strings" "sync" @@ -93,7 +93,7 @@ func parseCrashReport(path string, report []byte) (*raven.Packet, error) { } r := bytes.NewReader(report) - ctx, err := stack.ParseDump(r, ioutil.Discard, false) + ctx, err := stack.ParseDump(r, io.Discard, false) if err != nil { return nil, err } diff --git a/cmd/stcrashreceiver/sentry_test.go b/cmd/stcrashreceiver/sentry_test.go index fbfd2c421..e052197c9 100644 --- a/cmd/stcrashreceiver/sentry_test.go +++ b/cmd/stcrashreceiver/sentry_test.go @@ -8,7 +8,7 @@ package main import ( "fmt" - "io/ioutil" + "os" "testing" ) @@ -59,7 +59,7 @@ func TestParseVersion(t *testing.T) { } func TestParseReport(t *testing.T) { - bs, err := ioutil.ReadFile("_testdata/panic.log") + bs, err := os.ReadFile("_testdata/panic.log") if err != nil { t.Fatal(err) } diff --git a/cmd/stcrashreceiver/sourcecodeloader.go b/cmd/stcrashreceiver/sourcecodeloader.go index 1da310d3c..e51d8335b 100644 --- a/cmd/stcrashreceiver/sourcecodeloader.go +++ b/cmd/stcrashreceiver/sourcecodeloader.go @@ -9,7 +9,7 @@ package main import ( "bytes" "fmt" - "io/ioutil" + "io" "net/http" "path/filepath" "strings" @@ -80,7 +80,7 @@ func (l *githubSourceCodeLoader) Load(filename string, line, context int) ([][]b fmt.Println("Loading source:", resp.Status) return nil, 0 } - data, err := ioutil.ReadAll(resp.Body) + data, err := io.ReadAll(resp.Body) _ = resp.Body.Close() if err != nil { fmt.Println("Loading source:", err.Error()) diff --git a/cmd/stcrashreceiver/stcrashreceiver.go b/cmd/stcrashreceiver/stcrashreceiver.go index 9a39296c1..f6f988f3e 100644 --- a/cmd/stcrashreceiver/stcrashreceiver.go +++ b/cmd/stcrashreceiver/stcrashreceiver.go @@ -10,7 +10,6 @@ import ( "bytes" "compress/gzip" "io" - "io/ioutil" "log" "net/http" "os" @@ -96,7 +95,7 @@ func (r *crashReceiver) servePut(reportID, fullPath string, w http.ResponseWrite // Read at most maxRequestSize of report data. log.Println("Receiving report", reportID) lr := io.LimitReader(req.Body, maxRequestSize) - bs, err := ioutil.ReadAll(lr) + bs, err := io.ReadAll(lr) if err != nil { log.Println("Reading report:", err) http.Error(w, "Internal server error", http.StatusInternalServerError) @@ -110,7 +109,7 @@ func (r *crashReceiver) servePut(reportID, fullPath string, w http.ResponseWrite gw.Close() // Create an output file with the compressed report - err = ioutil.WriteFile(fullPath, buf.Bytes(), 0644) + err = os.WriteFile(fullPath, buf.Bytes(), 0644) if err != nil { log.Println("Saving report:", err) http.Error(w, "Internal server error", http.StatusInternalServerError) diff --git a/cmd/stcrashreceiver/util.go b/cmd/stcrashreceiver/util.go index ac164a1c6..ecd0fde91 100644 --- a/cmd/stcrashreceiver/util.go +++ b/cmd/stcrashreceiver/util.go @@ -10,9 +10,9 @@ import ( "bytes" "compress/gzip" "fmt" - "io/ioutil" "net" "net/http" + "os" "path/filepath" "time" @@ -53,5 +53,5 @@ func compressAndWrite(bs []byte, fullPath string) error { gw.Close() // Create an output file with the compressed report - return ioutil.WriteFile(fullPath, buf.Bytes(), 0644) + return os.WriteFile(fullPath, buf.Bytes(), 0644) } diff --git a/cmd/strelaypoolsrv/main.go b/cmd/strelaypoolsrv/main.go index a409b3c68..a0364a81c 100644 --- a/cmd/strelaypoolsrv/main.go +++ b/cmd/strelaypoolsrv/main.go @@ -11,7 +11,6 @@ import ( "flag" "fmt" "io" - "io/ioutil" "log" "net" "net/http" @@ -560,7 +559,7 @@ func limit(addr string, cache *lru.Cache, lock sync.Mutex, intv time.Duration, b } func loadRelays(file string) []*relay { - content, err := ioutil.ReadFile(file) + content, err := os.ReadFile(file) if err != nil { log.Println("Failed to load relays: " + err.Error()) return nil @@ -598,11 +597,11 @@ func saveRelays(file string, relays []*relay) error { for _, relay := range relays { content += relay.uri.String() + "\n" } - return ioutil.WriteFile(file, []byte(content), 0777) + return os.WriteFile(file, []byte(content), 0777) } func createTestCertificate() tls.Certificate { - tmpDir, err := ioutil.TempDir("", "relaypoolsrv") + tmpDir, err := os.MkdirTemp("", "relaypoolsrv") if err != nil { log.Fatal(err) } diff --git a/cmd/strelaysrv/pool.go b/cmd/strelaysrv/pool.go index 9ddde16c5..8aa48c935 100644 --- a/cmd/strelaysrv/pool.go +++ b/cmd/strelaysrv/pool.go @@ -6,7 +6,7 @@ import ( "bytes" "crypto/tls" "encoding/json" - "io/ioutil" + "io" "log" "net/http" "net/url" @@ -56,7 +56,7 @@ func poolHandler(pool string, uri *url.URL, mapping mapping, ownCert tls.Certifi continue } - bs, err := ioutil.ReadAll(resp.Body) + bs, err := io.ReadAll(resp.Body) resp.Body.Close() if err != nil { log.Printf("Error joining pool %v: reading response: %v", pool, err) diff --git a/cmd/stsigtool/main.go b/cmd/stsigtool/main.go index 0217f17e8..ab4c46b3e 100644 --- a/cmd/stsigtool/main.go +++ b/cmd/stsigtool/main.go @@ -9,7 +9,6 @@ package main import ( "flag" "io" - "io/ioutil" "log" "os" @@ -69,7 +68,7 @@ func gen() { } func sign(keyname, dataname string) { - privkey, err := ioutil.ReadFile(keyname) + privkey, err := os.ReadFile(keyname) if err != nil { log.Fatal(err) } @@ -95,7 +94,7 @@ func sign(keyname, dataname string) { } func verifyWithFile(signame, dataname, keyname string) { - pubkey, err := ioutil.ReadFile(keyname) + pubkey, err := os.ReadFile(keyname) if err != nil { log.Fatal(err) } @@ -103,7 +102,7 @@ func verifyWithFile(signame, dataname, keyname string) { } func verifyWithKey(signame, dataname string, pubkey []byte) { - sig, err := ioutil.ReadFile(signame) + sig, err := os.ReadFile(signame) if err != nil { log.Fatal(err) } diff --git a/cmd/syncthing/cli/main.go b/cmd/syncthing/cli/main.go index 8e08b92ef..b6599c893 100644 --- a/cmd/syncthing/cli/main.go +++ b/cmd/syncthing/cli/main.go @@ -9,7 +9,7 @@ package cli import ( "bufio" "fmt" - "io/ioutil" + "io" "os" "strings" @@ -151,7 +151,7 @@ func parseFlags(c *preCli) error { } } // We don't want kong to print anything nor os.Exit (e.g. on -h) - parser, err := kong.New(c, kong.Writers(ioutil.Discard, ioutil.Discard), kong.Exit(func(int) {})) + parser, err := kong.New(c, kong.Writers(io.Discard, io.Discard), kong.Exit(func(int) {})) if err != nil { return err } diff --git a/cmd/syncthing/cli/utils.go b/cmd/syncthing/cli/utils.go index 17bde1437..c495458e1 100644 --- a/cmd/syncthing/cli/utils.go +++ b/cmd/syncthing/cli/utils.go @@ -10,7 +10,7 @@ import ( "encoding/json" "errors" "fmt" - "io/ioutil" + "io" "mime" "net/http" "os" @@ -23,7 +23,7 @@ import ( ) func responseToBArray(response *http.Response) ([]byte, error) { - bytes, err := ioutil.ReadAll(response.Body) + bytes, err := io.ReadAll(response.Body) if err != nil { return nil, err } diff --git a/cmd/syncthing/crash_reporting.go b/cmd/syncthing/crash_reporting.go index 828695f1a..27896ff8a 100644 --- a/cmd/syncthing/crash_reporting.go +++ b/cmd/syncthing/crash_reporting.go @@ -10,7 +10,6 @@ import ( "bytes" "context" "fmt" - "io/ioutil" "net/http" "os" "path/filepath" @@ -62,7 +61,7 @@ func uploadPanicLogs(ctx context.Context, urlBase, dir string) { // the log contents. A HEAD request is made to see if the log has already // been reported. If not, a PUT is made with the log contents. func uploadPanicLog(ctx context.Context, urlBase, file string) error { - data, err := ioutil.ReadFile(file) + data, err := os.ReadFile(file) if err != nil { return err } diff --git a/cmd/syncthing/decrypt/decrypt.go b/cmd/syncthing/decrypt/decrypt.go index 119583dbd..bb7651e72 100644 --- a/cmd/syncthing/decrypt/decrypt.go +++ b/cmd/syncthing/decrypt/decrypt.go @@ -12,8 +12,8 @@ import ( "encoding/json" "fmt" "io" - "io/ioutil" "log" + "os" "path/filepath" "github.com/syncthing/syncthing/lib/config" @@ -112,7 +112,7 @@ func (c *CLI) withContinue(err error) error { // error. func (c *CLI) getFolderID() (string, error) { tokenPath := filepath.Join(c.Path, c.TokenPath) - bs, err := ioutil.ReadFile(tokenPath) + bs, err := os.ReadFile(tokenPath) if err != nil { return "", fmt.Errorf("reading folder token: %w", err) } diff --git a/cmd/syncthing/main.go b/cmd/syncthing/main.go index 127fcc54f..3e3604d60 100644 --- a/cmd/syncthing/main.go +++ b/cmd/syncthing/main.go @@ -12,7 +12,6 @@ import ( "crypto/tls" "fmt" "io" - "io/ioutil" "log" "net/http" _ "net/http/pprof" // Need to import this to support STPROFILER. @@ -500,7 +499,7 @@ func upgradeViaRest() error { return err } if resp.StatusCode != 200 { - bs, err := ioutil.ReadAll(resp.Body) + bs, err := io.ReadAll(resp.Body) defer resp.Body.Close() if err != nil { return err diff --git a/cmd/syncthing/monitor_test.go b/cmd/syncthing/monitor_test.go index 345a9a06c..6ad8e4ee2 100644 --- a/cmd/syncthing/monitor_test.go +++ b/cmd/syncthing/monitor_test.go @@ -8,7 +8,6 @@ package main import ( "io" - "io/ioutil" "os" "path/filepath" "testing" @@ -18,7 +17,7 @@ import ( func TestRotatedFile(t *testing.T) { // Verify that log rotation happens. - dir, err := ioutil.TempDir("", "syncthing") + dir, err := os.MkdirTemp("", "syncthing") if err != nil { t.Fatal(err) } @@ -179,7 +178,7 @@ func TestAutoClosedFile(t *testing.T) { } // The file should have both writes in it. - bs, err := ioutil.ReadFile(file) + bs, err := os.ReadFile(file) if err != nil { t.Fatal(err) } @@ -199,7 +198,7 @@ func TestAutoClosedFile(t *testing.T) { } // It should now contain three writes, as the file is always opened for appending - bs, err = ioutil.ReadFile(file) + bs, err = os.ReadFile(file) if err != nil { t.Fatal(err) } diff --git a/cmd/ursrv/main.go b/cmd/ursrv/main.go index 6cbf44299..0d24ee1be 100644 --- a/cmd/ursrv/main.go +++ b/cmd/ursrv/main.go @@ -13,7 +13,6 @@ import ( "encoding/json" "html/template" "io" - "io/ioutil" "log" "net" "net/http" @@ -162,7 +161,7 @@ func main() { if err != nil { log.Fatalln("template:", err) } - bs, err := ioutil.ReadAll(fd) + bs, err := io.ReadAll(fd) if err != nil { log.Fatalln("template:", err) } @@ -324,7 +323,7 @@ func newDataHandler(db *sql.DB, w http.ResponseWriter, r *http.Request) { rep.Address = addr lr := &io.LimitedReader{R: r.Body, N: 40 * 1024} - bs, _ := ioutil.ReadAll(lr) + bs, _ := io.ReadAll(lr) if err := json.Unmarshal(bs, &rep); err != nil { log.Println("decode:", err) if debug { diff --git a/lib/api/api.go b/lib/api/api.go index 6ba4235f3..1e8c4747b 100644 --- a/lib/api/api.go +++ b/lib/api/api.go @@ -15,7 +15,6 @@ import ( "errors" "fmt" "io" - "io/ioutil" "log" "net" "net/http" @@ -382,7 +381,7 @@ func (s *service) Serve(ctx context.Context) error { ReadTimeout: 15 * time.Second, // Prevent the HTTP server from logging stuff on its own. The things we // care about we log ourselves from the handlers. - ErrorLog: log.New(ioutil.Discard, "", 0), + ErrorLog: log.New(io.Discard, "", 0), } l.Infoln("GUI and API listening on", listener.Addr()) @@ -1098,7 +1097,7 @@ func (s *service) getSystemError(w http.ResponseWriter, r *http.Request) { } func (s *service) postSystemError(w http.ResponseWriter, r *http.Request) { - bs, _ := ioutil.ReadAll(r.Body) + bs, _ := io.ReadAll(r.Body) r.Body.Close() l.Warnln(string(bs)) } @@ -1165,7 +1164,7 @@ func (s *service) getSupportBundle(w http.ResponseWriter, r *http.Request) { // Panic files if panicFiles, err := filepath.Glob(filepath.Join(locations.GetBaseDir(locations.ConfigBaseDir), "panic*")); err == nil { for _, f := range panicFiles { - if panicFile, err := ioutil.ReadFile(f); err != nil { + if panicFile, err := os.ReadFile(f); err != nil { l.Warnf("Support bundle: failed to load %s: %s", filepath.Base(f), err) } else { files = append(files, fileEntry{name: filepath.Base(f), data: panicFile}) @@ -1174,7 +1173,7 @@ func (s *service) getSupportBundle(w http.ResponseWriter, r *http.Request) { } // Archived log (default on Windows) - if logFile, err := ioutil.ReadFile(locations.Get(locations.LogFile)); err == nil { + if logFile, err := os.ReadFile(locations.Get(locations.LogFile)); err == nil { files = append(files, fileEntry{name: "log-ondisk.txt", data: logFile}) } @@ -1233,7 +1232,7 @@ func (s *service) getSupportBundle(w http.ResponseWriter, r *http.Request) { zipFilePath := filepath.Join(locations.GetBaseDir(locations.ConfigBaseDir), zipFileName) // Write buffer zip to local zip file (back up) - if err := ioutil.WriteFile(zipFilePath, zipFilesBuffer.Bytes(), 0600); err != nil { + if err := os.WriteFile(zipFilePath, zipFilesBuffer.Bytes(), 0600); err != nil { l.Warnln("Support bundle: support bundle zip could not be created:", err) } @@ -1323,7 +1322,7 @@ func (s *service) getDBIgnores(w http.ResponseWriter, r *http.Request) { func (s *service) postDBIgnores(w http.ResponseWriter, r *http.Request) { qs := r.URL.Query() - bs, err := ioutil.ReadAll(r.Body) + bs, err := io.ReadAll(r.Body) r.Body.Close() if err != nil { http.Error(w, err.Error(), 500) @@ -1614,7 +1613,7 @@ func (s *service) getFolderVersions(w http.ResponseWriter, r *http.Request) { func (s *service) postFolderVersionsRestore(w http.ResponseWriter, r *http.Request) { qs := r.URL.Query() - bs, err := ioutil.ReadAll(r.Body) + bs, err := io.ReadAll(r.Body) r.Body.Close() if err != nil { http.Error(w, err.Error(), 500) diff --git a/lib/api/api_test.go b/lib/api/api_test.go index f9ecc15c5..1bfe5df08 100644 --- a/lib/api/api_test.go +++ b/lib/api/api_test.go @@ -13,7 +13,6 @@ import ( "encoding/json" "fmt" "io" - "io/ioutil" "net" "net/http" "net/http/httptest" @@ -223,7 +222,7 @@ func expectURLToContain(t *testing.T, url, exp string) { return } - data, err := ioutil.ReadAll(res.Body) + data, err := io.ReadAll(res.Body) res.Body.Close() if err != nil { t.Error(err) @@ -508,7 +507,7 @@ func testHTTPRequest(t *testing.T, baseURL string, tc httpTestCase, apikey strin return } - data, err := ioutil.ReadAll(resp.Body) + data, err := io.ReadAll(resp.Body) if err != nil { t.Errorf("Unexpected error reading %s: %v", tc.URL, err) return @@ -1137,7 +1136,7 @@ func TestBrowse(t *testing.T) { pathSep := string(os.PathSeparator) - tmpDir, err := ioutil.TempDir("", "syncthing") + tmpDir, err := os.MkdirTemp("", "syncthing") if err != nil { t.Fatal(err) } @@ -1146,7 +1145,7 @@ func TestBrowse(t *testing.T) { if err := os.Mkdir(filepath.Join(tmpDir, "dir"), 0755); err != nil { t.Fatal(err) } - if err := ioutil.WriteFile(filepath.Join(tmpDir, "file"), []byte("hello"), 0644); err != nil { + if err := os.WriteFile(filepath.Join(tmpDir, "file"), []byte("hello"), 0644); err != nil { t.Fatal(err) } if err := os.Mkdir(filepath.Join(tmpDir, "MiXEDCase"), 0755); err != nil { @@ -1251,7 +1250,7 @@ func TestConfigChanges(t *testing.T) { APIKey: testAPIKey, }, } - tmpFile, err := ioutil.TempFile("", "syncthing-testConfig-") + tmpFile, err := os.CreateTemp("", "syncthing-testConfig-") if err != nil { panic(err) } @@ -1393,7 +1392,7 @@ func runningInContainer() bool { return false } - bs, err := ioutil.ReadFile("/proc/1/cgroup") + bs, err := os.ReadFile("/proc/1/cgroup") if err != nil { return false } diff --git a/lib/api/auto/auto_test.go b/lib/api/auto/auto_test.go index 2e997d5e3..db7e276f9 100644 --- a/lib/api/auto/auto_test.go +++ b/lib/api/auto/auto_test.go @@ -9,7 +9,7 @@ package auto_test import ( "bytes" "compress/gzip" - "io/ioutil" + "io" "strings" "testing" @@ -28,7 +28,7 @@ func TestAssets(t *testing.T) { var gr *gzip.Reader gr, _ = gzip.NewReader(strings.NewReader(idx.Content)) - html, _ := ioutil.ReadAll(gr) + html, _ := io.ReadAll(gr) if !bytes.Contains(html, []byte(" 0 { lr := io.LimitReader(f.rng, diff) - io.Copy(ioutil.Discard, lr) + io.Copy(io.Discard, lr) } f.offset = offs diff --git a/lib/fs/fakefs_test.go b/lib/fs/fakefs_test.go index 1b095f881..63cae9d40 100644 --- a/lib/fs/fakefs_test.go +++ b/lib/fs/fakefs_test.go @@ -10,7 +10,6 @@ import ( "bytes" "fmt" "io" - "io/ioutil" "os" "path" "path/filepath" @@ -88,7 +87,7 @@ func TestFakeFS(t *testing.T) { } // Read - bs0, err := ioutil.ReadAll(fd) + bs0, err := io.ReadAll(fd) if err != nil { t.Fatal(err) } @@ -101,7 +100,7 @@ func TestFakeFS(t *testing.T) { if err != nil { t.Fatal(err) } - bs1, err := ioutil.ReadAll(fd) + bs1, err := io.ReadAll(fd) if err != nil { t.Fatal(err) } @@ -139,7 +138,7 @@ func testFakeFSRead(t *testing.T, fs Filesystem) { // Read fd.Seek(0, io.SeekStart) - bs0, err := ioutil.ReadAll(fd) + bs0, err := io.ReadAll(fd) if err != nil { t.Fatal(err) } @@ -154,7 +153,7 @@ func testFakeFSRead(t *testing.T, fs Filesystem) { if n != len(buf0) { t.Fatal("short read") } - buf1, err := ioutil.ReadAll(fd) + buf1, err := io.ReadAll(fd) if err != nil { t.Fatal(err) } @@ -252,7 +251,7 @@ func TestFakeFSCaseInsensitive(t *testing.T) { func createTestDir(t *testing.T) (string, bool) { t.Helper() - testDir, err := ioutil.TempDir("", "") + testDir, err := os.MkdirTemp("", "") if err != nil { t.Fatalf("could not create temporary dir for testing: %s", err) } @@ -328,7 +327,7 @@ func testFakeFSCaseInsensitive(t *testing.T, fs Filesystem) { t.Fatal(err) } - bs2, err := ioutil.ReadAll(fd2) + bs2, err := io.ReadAll(fd2) if err != nil { t.Fatal(err) } diff --git a/lib/fs/filesystem_copy_range_test.go b/lib/fs/filesystem_copy_range_test.go index e2db04fb9..5831753df 100644 --- a/lib/fs/filesystem_copy_range_test.go +++ b/lib/fs/filesystem_copy_range_test.go @@ -9,7 +9,6 @@ package fs import ( "bytes" "io" - "io/ioutil" "math/rand" "os" "path/filepath" @@ -257,7 +256,7 @@ func TestCopyRange(tttt *testing.T) { paths = []string{""} } for _, path := range paths { - testPath, err := ioutil.TempDir(path, "") + testPath, err := os.MkdirTemp(path, "") if err != nil { tttt.Fatal(err) } @@ -273,7 +272,7 @@ func TestCopyRange(tttt *testing.T) { tt.Run(testCase.name, func(t *testing.T) { srcBuf := make([]byte, testCase.srcSize) dstBuf := make([]byte, testCase.dstSize) - td, err := ioutil.TempDir(testPath, "") + td, err := os.MkdirTemp(testPath, "") if err != nil { t.Fatal(err) } diff --git a/lib/fs/mtimefs_test.go b/lib/fs/mtimefs_test.go index 3f7dc6c07..bf14f514e 100644 --- a/lib/fs/mtimefs_test.go +++ b/lib/fs/mtimefs_test.go @@ -8,7 +8,6 @@ package fs import ( "errors" - "io/ioutil" "os" "path/filepath" "runtime" @@ -20,9 +19,9 @@ func TestMtimeFS(t *testing.T) { os.RemoveAll("testdata") defer os.RemoveAll("testdata") os.Mkdir("testdata", 0755) - ioutil.WriteFile("testdata/exists0", []byte("hello"), 0644) - ioutil.WriteFile("testdata/exists1", []byte("hello"), 0644) - ioutil.WriteFile("testdata/exists2", []byte("hello"), 0644) + os.WriteFile("testdata/exists0", []byte("hello"), 0644) + os.WriteFile("testdata/exists1", []byte("hello"), 0644) + os.WriteFile("testdata/exists2", []byte("hello"), 0644) // a random time with nanosecond precision testTime := time.Unix(1234567890, 123456789) @@ -83,7 +82,7 @@ func TestMtimeFS(t *testing.T) { } func TestMtimeFSWalk(t *testing.T) { - dir, err := ioutil.TempDir("", "") + dir, err := os.MkdirTemp("", "") if err != nil { t.Fatal(err) } @@ -93,7 +92,7 @@ func TestMtimeFSWalk(t *testing.T) { mtimefs := newMtimeFS(underlying, make(mapStore)) mtimefs.chtimes = failChtimes - if err := ioutil.WriteFile(filepath.Join(dir, "file"), []byte("hello"), 0644); err != nil { + if err := os.WriteFile(filepath.Join(dir, "file"), []byte("hello"), 0644); err != nil { t.Fatal(err) } @@ -137,7 +136,7 @@ func TestMtimeFSWalk(t *testing.T) { } func TestMtimeFSOpen(t *testing.T) { - dir, err := ioutil.TempDir("", "") + dir, err := os.MkdirTemp("", "") if err != nil { t.Fatal(err) } @@ -147,7 +146,7 @@ func TestMtimeFSOpen(t *testing.T) { mtimefs := newMtimeFS(underlying, make(mapStore)) mtimefs.chtimes = failChtimes - if err := ioutil.WriteFile(filepath.Join(dir, "file"), []byte("hello"), 0644); err != nil { + if err := os.WriteFile(filepath.Join(dir, "file"), []byte("hello"), 0644); err != nil { t.Fatal(err) } @@ -200,7 +199,7 @@ func TestMtimeFSInsensitive(t *testing.T) { os.RemoveAll("testdata") defer os.RemoveAll("testdata") os.Mkdir("testdata", 0755) - ioutil.WriteFile("testdata/FiLe", []byte("hello"), 0644) + os.WriteFile("testdata/FiLe", []byte("hello"), 0644) // a random time with nanosecond precision testTime := time.Unix(1234567890, 123456789) diff --git a/lib/ignore/ignore_test.go b/lib/ignore/ignore_test.go index d9564ec66..9781cbdfa 100644 --- a/lib/ignore/ignore_test.go +++ b/lib/ignore/ignore_test.go @@ -10,7 +10,6 @@ import ( "bytes" "fmt" "io" - "io/ioutil" "os" "path/filepath" "runtime" @@ -232,7 +231,7 @@ func TestCaseSensitivity(t *testing.T) { } func TestCaching(t *testing.T) { - dir, err := ioutil.TempDir("", "") + dir, err := os.MkdirTemp("", "") if err != nil { t.Fatal(err) } @@ -425,7 +424,7 @@ flamingo *.crow ` // Caches per file, hence write the patterns to a file. - dir, err := ioutil.TempDir("", "") + dir, err := os.MkdirTemp("", "") if err != nil { b.Fatal(err) } @@ -466,7 +465,7 @@ flamingo } func TestCacheReload(t *testing.T) { - dir, err := ioutil.TempDir("", "") + dir, err := os.MkdirTemp("", "") if err != nil { t.Fatal(err) } @@ -989,7 +988,7 @@ func TestIssue4689(t *testing.T) { } func TestIssue4901(t *testing.T) { - dir, err := ioutil.TempDir("", "") + dir, err := os.MkdirTemp("", "") if err != nil { t.Fatal(err) } @@ -1001,7 +1000,7 @@ func TestIssue4901(t *testing.T) { puppy ` - if err := ioutil.WriteFile(filepath.Join(dir, ".stignore"), []byte(stignore), 0777); err != nil { + if err := os.WriteFile(filepath.Join(dir, ".stignore"), []byte(stignore), 0777); err != nil { t.Fatalf(err.Error()) } @@ -1020,7 +1019,7 @@ func TestIssue4901(t *testing.T) { } } - if err := ioutil.WriteFile(filepath.Join(dir, "unicorn-lazor-death"), []byte(" "), 0777); err != nil { + if err := os.WriteFile(filepath.Join(dir, "unicorn-lazor-death"), []byte(" "), 0777); err != nil { t.Fatalf(err.Error()) } diff --git a/lib/logger/logger.go b/lib/logger/logger.go index cd3e3f237..731be426b 100644 --- a/lib/logger/logger.go +++ b/lib/logger/logger.go @@ -10,7 +10,6 @@ package logger import ( "fmt" "io" - "io/ioutil" "log" "os" "strings" @@ -75,7 +74,7 @@ func New() Logger { if os.Getenv("LOGGER_DISCARD") != "" { // Hack to completely disable logging, for example when running // benchmarks. - return newLogger(ioutil.Discard) + return newLogger(io.Discard) } return newLogger(controlStripper{os.Stdout}) } diff --git a/lib/logger/logger_test.go b/lib/logger/logger_test.go index 1937aa646..cc3b72e67 100644 --- a/lib/logger/logger_test.go +++ b/lib/logger/logger_test.go @@ -6,7 +6,7 @@ package logger import ( "bytes" "fmt" - "io/ioutil" + "io" "log" "strings" "testing" @@ -186,12 +186,12 @@ func TestControlStripper(t *testing.T) { } func BenchmarkLog(b *testing.B) { - l := newLogger(controlStripper{ioutil.Discard}) + l := newLogger(controlStripper{io.Discard}) benchmarkLogger(b, l) } func BenchmarkLogNoStripper(b *testing.B) { - l := newLogger(ioutil.Discard) + l := newLogger(io.Discard) benchmarkLogger(b, l) } diff --git a/lib/model/folder_sendrecv_test.go b/lib/model/folder_sendrecv_test.go index 06bf7d6d7..c3a764242 100644 --- a/lib/model/folder_sendrecv_test.go +++ b/lib/model/folder_sendrecv_test.go @@ -13,7 +13,6 @@ import ( "errors" "fmt" "io" - "io/ioutil" "os" "path/filepath" "runtime" @@ -680,8 +679,8 @@ func TestIssue3164(t *testing.T) { ignDir := filepath.Join("issue3164", "oktodelete") subDir := filepath.Join(ignDir, "foobar") must(t, ffs.MkdirAll(subDir, 0777)) - must(t, ioutil.WriteFile(filepath.Join(tmpDir, subDir, "file"), []byte("Hello"), 0644)) - must(t, ioutil.WriteFile(filepath.Join(tmpDir, ignDir, "file"), []byte("Hello"), 0644)) + must(t, os.WriteFile(filepath.Join(tmpDir, subDir, "file"), []byte("Hello"), 0644)) + must(t, os.WriteFile(filepath.Join(tmpDir, ignDir, "file"), []byte("Hello"), 0644)) file := protocol.FileInfo{ Name: "issue3164", } diff --git a/lib/model/model_test.go b/lib/model/model_test.go index 121bcdffe..78fa8e9f9 100644 --- a/lib/model/model_test.go +++ b/lib/model/model_test.go @@ -12,7 +12,6 @@ import ( "encoding/json" "fmt" "io" - "io/ioutil" "math/rand" "os" "path/filepath" @@ -2152,7 +2151,7 @@ func TestIssue2782(t *testing.T) { if err := os.MkdirAll(testDir+"/syncdir", 0755); err != nil { t.Skip(err) } - if err := ioutil.WriteFile(testDir+"/syncdir/file", []byte("hello, world\n"), 0644); err != nil { + if err := os.WriteFile(testDir+"/syncdir/file", []byte("hello, world\n"), 0644); err != nil { t.Skip(err) } if err := os.Symlink("syncdir", testDir+"/synclink"); err != nil { @@ -2763,7 +2762,7 @@ func TestVersionRestore(t *testing.T) { // In each file, we write the filename as the content // We verify that the content matches at the expected filenames // after the restore operation. - dir, err := ioutil.TempDir("", "") + dir, err := os.MkdirTemp("", "") must(t, err) defer os.RemoveAll(dir) @@ -2900,7 +2899,7 @@ func TestVersionRestore(t *testing.T) { } defer fd.Close() - content, err := ioutil.ReadAll(fd) + content, err := io.ReadAll(fd) if err != nil { t.Error(err) } @@ -2930,7 +2929,7 @@ func TestVersionRestore(t *testing.T) { must(t, err) defer fd.Close() - content, err := ioutil.ReadAll(fd) + content, err := io.ReadAll(fd) if err != nil { t.Error(err) } diff --git a/lib/model/requests_test.go b/lib/model/requests_test.go index 35df4fdd9..76868748a 100644 --- a/lib/model/requests_test.go +++ b/lib/model/requests_test.go @@ -10,7 +10,6 @@ import ( "bytes" "context" "errors" - "io/ioutil" "os" "path/filepath" "runtime" @@ -236,7 +235,7 @@ func TestRequestVersioningSymlinkAttack(t *testing.T) { // Create a temporary directory that we will use as target to see if // we can escape to it - tmpdir, err := ioutil.TempDir("", "syncthing-test") + tmpdir, err := os.MkdirTemp("", "syncthing-test") if err != nil { t.Fatal(err) } @@ -681,7 +680,7 @@ func TestRequestSymlinkWindows(t *testing.T) { } func equalContents(path string, contents []byte) error { - if bs, err := ioutil.ReadFile(path); err != nil { + if bs, err := os.ReadFile(path); err != nil { return err } else if !bytes.Equal(bs, contents) { return errors.New("incorrect data") diff --git a/lib/model/testutils_test.go b/lib/model/testutils_test.go index 4ee390f5d..a31e57fdd 100644 --- a/lib/model/testutils_test.go +++ b/lib/model/testutils_test.go @@ -8,7 +8,6 @@ package model import ( "context" - "io/ioutil" "os" "testing" "time" @@ -76,7 +75,7 @@ func init() { } func createTmpWrapper(cfg config.Configuration) (config.Wrapper, context.CancelFunc) { - tmpFile, err := ioutil.TempFile("", "syncthing-testConfig-") + tmpFile, err := os.CreateTemp("", "syncthing-testConfig-") if err != nil { panic(err) } @@ -215,7 +214,7 @@ func cleanupModelAndRemoveDir(m *testModel, dir string) { } func createTmpDir() string { - tmpDir, err := ioutil.TempDir("", "syncthing_testFolder-") + tmpDir, err := os.MkdirTemp("", "syncthing_testFolder-") if err != nil { panic("Failed to create temporary testing dir") } diff --git a/lib/nat/structs_test.go b/lib/nat/structs_test.go index 661a552f8..b43e52e08 100644 --- a/lib/nat/structs_test.go +++ b/lib/nat/structs_test.go @@ -7,7 +7,6 @@ package nat import ( - "io/ioutil" "net" "os" "testing" @@ -60,7 +59,7 @@ func TestMappingValidGateway(t *testing.T) { } func TestMappingClearAddresses(t *testing.T) { - tmpFile, err := ioutil.TempFile("", "syncthing-testConfig-") + tmpFile, err := os.CreateTemp("", "syncthing-testConfig-") if err != nil { t.Fatal(err) } diff --git a/lib/osutil/atomic.go b/lib/osutil/atomic.go index c2f6dd6e9..bf9730daf 100644 --- a/lib/osutil/atomic.go +++ b/lib/osutil/atomic.go @@ -43,7 +43,7 @@ func CreateAtomic(path string) (*AtomicWriter, error) { // permissions. func CreateAtomicFilesystem(filesystem fs.Filesystem, path string) (*AtomicWriter, error) { // The security of this depends on the tempfile having secure - // permissions, 0600, from the beginning. This is what ioutil.TempFile + // permissions, 0600, from the beginning. This is what os.CreateTemp // does. We have a test that verifies that that is the case, should this // ever change in the standard library in the future. fd, err := TempFile(filesystem, filepath.Dir(path), TempPrefix) diff --git a/lib/osutil/atomic_test.go b/lib/osutil/atomic_test.go index 70c5b90d6..c9737784a 100644 --- a/lib/osutil/atomic_test.go +++ b/lib/osutil/atomic_test.go @@ -8,7 +8,6 @@ package osutil import ( "bytes" - "io/ioutil" "os" "path/filepath" "testing" @@ -35,7 +34,7 @@ func TestCreateAtomicCreate(t *testing.T) { t.Fatal("written bytes", n, "!= 5") } - if _, err := ioutil.ReadFile("testdata/file"); err == nil { + if _, err := os.ReadFile("testdata/file"); err == nil { t.Fatal("file should not exist") } @@ -43,7 +42,7 @@ func TestCreateAtomicCreate(t *testing.T) { t.Fatal(err) } - bs, err := ioutil.ReadFile("testdata/file") + bs, err := os.ReadFile("testdata/file") if err != nil { t.Fatal(err) } @@ -62,7 +61,7 @@ func TestCreateAtomicReplaceReadOnly(t *testing.T) { func testCreateAtomicReplace(t *testing.T, oldPerms os.FileMode) { t.Helper() - testdir, err := ioutil.TempDir("", "syncthing") + testdir, err := os.MkdirTemp("", "syncthing") if err != nil { t.Fatal(err) } @@ -75,7 +74,7 @@ func testCreateAtomicReplace(t *testing.T, oldPerms os.FileMode) { t.Fatal(err) } - if err := ioutil.WriteFile(testfile, []byte("some old data"), oldPerms); err != nil { + if err := os.WriteFile(testfile, []byte("some old data"), oldPerms); err != nil { t.Fatal(err) } @@ -103,7 +102,7 @@ func testCreateAtomicReplace(t *testing.T, oldPerms os.FileMode) { t.Fatal(err) } - bs, err := ioutil.ReadFile(testfile) + bs, err := os.ReadFile(testfile) if err != nil { t.Fatal(err) } diff --git a/lib/osutil/atomic_unix_test.go b/lib/osutil/atomic_unix_test.go index ec4f8e68e..1d2e17da1 100644 --- a/lib/osutil/atomic_unix_test.go +++ b/lib/osutil/atomic_unix_test.go @@ -12,7 +12,6 @@ package osutil import ( - "io/ioutil" "os" "syscall" "testing" @@ -24,7 +23,7 @@ func TestTempFilePermissions(t *testing.T) { oldMask := syscall.Umask(0) defer syscall.Umask(oldMask) - fd, err := ioutil.TempFile("", "test") + fd, err := os.CreateTemp("", "test") if err != nil { t.Fatal(err) } diff --git a/lib/osutil/osutil_test.go b/lib/osutil/osutil_test.go index 772097e53..db1e608fd 100644 --- a/lib/osutil/osutil_test.go +++ b/lib/osutil/osutil_test.go @@ -7,7 +7,7 @@ package osutil_test import ( - "io/ioutil" + "io" "os" "path/filepath" "runtime" @@ -83,7 +83,7 @@ func TestIsDeleted(t *testing.T) { func TestRenameOrCopy(t *testing.T) { mustTempDir := func() string { t.Helper() - tmpDir, err := ioutil.TempDir("", "") + tmpDir, err := os.MkdirTemp("", "") if err != nil { t.Fatal(err) } @@ -131,7 +131,7 @@ func TestRenameOrCopy(t *testing.T) { if err != nil { t.Fatal(err) } - buf, err := ioutil.ReadAll(fd) + buf, err := io.ReadAll(fd) if err != nil { t.Fatal(err) } @@ -147,7 +147,7 @@ func TestRenameOrCopy(t *testing.T) { if fd, err := test.dst.Open("new"); err != nil { t.Fatal(err) } else { - if buf, err := ioutil.ReadAll(fd); err != nil { + if buf, err := io.ReadAll(fd); err != nil { t.Fatal(err) } else if string(buf) != content { t.Fatalf("expected %s got %s", content, string(buf)) diff --git a/lib/osutil/traversessymlink_test.go b/lib/osutil/traversessymlink_test.go index 5bf6e7b59..374c471fd 100644 --- a/lib/osutil/traversessymlink_test.go +++ b/lib/osutil/traversessymlink_test.go @@ -7,7 +7,6 @@ package osutil_test import ( - "io/ioutil" "os" "path/filepath" "runtime" @@ -18,7 +17,7 @@ import ( ) func TestTraversesSymlink(t *testing.T) { - tmpDir, err := ioutil.TempDir(".", ".test-TraversesSymlink-") + tmpDir, err := os.MkdirTemp(".", ".test-TraversesSymlink-") if err != nil { panic("Failed to create temporary testing dir") } @@ -71,7 +70,7 @@ func TestTraversesSymlink(t *testing.T) { } func TestIssue4875(t *testing.T) { - tmpDir, err := ioutil.TempDir("", ".test-Issue4875-") + tmpDir, err := os.MkdirTemp("", ".test-Issue4875-") if err != nil { panic("Failed to create temporary testing dir") } diff --git a/lib/protocol/protocol_test.go b/lib/protocol/protocol_test.go index 1c1d617f7..81a74bb9f 100644 --- a/lib/protocol/protocol_test.go +++ b/lib/protocol/protocol_test.go @@ -10,7 +10,7 @@ import ( "encoding/json" "errors" "io" - "io/ioutil" + "os" "runtime" "sync" "testing" @@ -432,8 +432,8 @@ func testMarshal(t *testing.T, prefix string, m1, m2 message) bool { bs1, _ := json.MarshalIndent(m1, "", " ") bs2, _ := json.MarshalIndent(m2, "", " ") if !bytes.Equal(bs1, bs2) { - ioutil.WriteFile(prefix+"-1.txt", bs1, 0644) - ioutil.WriteFile(prefix+"-2.txt", bs2, 0644) + os.WriteFile(prefix+"-1.txt", bs1, 0644) + os.WriteFile(prefix+"-2.txt", bs2, 0644) return false } diff --git a/lib/rc/rc.go b/lib/rc/rc.go index f21d0e31d..875ee849e 100644 --- a/lib/rc/rc.go +++ b/lib/rc/rc.go @@ -14,7 +14,6 @@ import ( "errors" "fmt" "io" - "io/ioutil" "log" "net/http" "net/url" @@ -393,7 +392,7 @@ func (p *Process) Model(folder string) (Model, error) { } func (p *Process) readResponse(resp *http.Response) ([]byte, error) { - bs, err := ioutil.ReadAll(resp.Body) + bs, err := io.ReadAll(resp.Body) resp.Body.Close() if err != nil { return bs, err diff --git a/lib/scanner/walk_test.go b/lib/scanner/walk_test.go index ba7e9a331..4edad2b47 100644 --- a/lib/scanner/walk_test.go +++ b/lib/scanner/walk_test.go @@ -13,7 +13,6 @@ import ( "errors" "fmt" "io" - "io/ioutil" "os" "path/filepath" "runtime" @@ -376,7 +375,7 @@ func TestWalkSymlinkWindows(t *testing.T) { func TestWalkRootSymlink(t *testing.T) { // Create a folder with a symlink in it - tmp, err := ioutil.TempDir("", "") + tmp, err := os.MkdirTemp("", "") if err != nil { t.Fatal(err) } @@ -709,7 +708,7 @@ func TestStopWalk(t *testing.T) { } func TestIssue4799(t *testing.T) { - tmp, err := ioutil.TempDir("", "") + tmp, err := os.MkdirTemp("", "") if err != nil { t.Fatal(err) } @@ -771,7 +770,7 @@ func TestRecurseInclude(t *testing.T) { } func TestIssue4841(t *testing.T) { - tmp, err := ioutil.TempDir("", "") + tmp, err := os.MkdirTemp("", "") if err != nil { t.Fatal(err) } diff --git a/lib/syncthing/syncthing_test.go b/lib/syncthing/syncthing_test.go index 8add69ee8..e9feedf44 100644 --- a/lib/syncthing/syncthing_test.go +++ b/lib/syncthing/syncthing_test.go @@ -7,7 +7,6 @@ package syncthing import ( - "io/ioutil" "os" "testing" "time" @@ -22,7 +21,7 @@ import ( func tempCfgFilename(t *testing.T) string { t.Helper() - f, err := ioutil.TempFile("", "syncthing-testConfig-") + f, err := os.CreateTemp("", "syncthing-testConfig-") if err != nil { t.Fatal(err) } diff --git a/lib/syncthing/utils.go b/lib/syncthing/utils.go index eecb56394..5f59af2b6 100644 --- a/lib/syncthing/utils.go +++ b/lib/syncthing/utils.go @@ -10,7 +10,6 @@ import ( "crypto/tls" "fmt" "io" - "io/ioutil" "os" "github.com/pkg/errors" @@ -133,12 +132,12 @@ func archiveAndSaveConfig(cfg config.Wrapper, originalVersion int) error { } func copyFile(src, dst string) error { - bs, err := ioutil.ReadFile(src) + bs, err := os.ReadFile(src) if err != nil { return err } - if err := ioutil.WriteFile(dst, bs, 0600); err != nil { + if err := os.WriteFile(dst, bs, 0600); err != nil { // Attempt to clean up os.Remove(dst) return err diff --git a/lib/upgrade/upgrade_supported.go b/lib/upgrade/upgrade_supported.go index 45eeaf426..80312a6fa 100644 --- a/lib/upgrade/upgrade_supported.go +++ b/lib/upgrade/upgrade_supported.go @@ -19,7 +19,6 @@ import ( "errors" "fmt" "io" - "io/ioutil" "net/http" "os" "path" @@ -284,7 +283,7 @@ func readTarGz(archiveName, dir string, r io.Reader) (string, error) { } func readZip(archiveName, dir string, r io.Reader) (string, error) { - body, err := ioutil.ReadAll(r) + body, err := io.ReadAll(r) if err != nil { return "", err } @@ -357,7 +356,7 @@ func archiveFileVisitor(dir string, tempFile *string, signature *[]byte, archive case "release.sig": l.Debugf("found signature %s", archivePath) - *signature, err = ioutil.ReadAll(io.LimitReader(filedata, maxSignatureSize)) + *signature, err = io.ReadAll(io.LimitReader(filedata, maxSignatureSize)) if err != nil { return err } @@ -407,7 +406,7 @@ func verifyUpgrade(archiveName, tempName string, sig []byte) error { func writeBinary(dir string, inFile io.Reader) (filename string, err error) { // Write the binary to a temporary file. - outFile, err := ioutil.TempFile(dir, "syncthing") + outFile, err := os.CreateTemp(dir, "syncthing") if err != nil { return "", err } diff --git a/lib/upnp/upnp.go b/lib/upnp/upnp.go index 72fc22fed..9cf3b5afb 100644 --- a/lib/upnp/upnp.go +++ b/lib/upnp/upnp.go @@ -38,7 +38,7 @@ import ( "context" "encoding/xml" "fmt" - "io/ioutil" + "io" "net" "net/http" "net/url" @@ -467,7 +467,7 @@ func soapRequest(ctx context.Context, url, service, function, message string) ([ return resp, err } - resp, _ = ioutil.ReadAll(r.Body) + resp, _ = io.ReadAll(r.Body) l.Debugf("SOAP Response: %s\n\n%s\n\n", r.Status, resp) r.Body.Close() diff --git a/lib/versioner/external_test.go b/lib/versioner/external_test.go index 5979d5e76..e4283fa3e 100644 --- a/lib/versioner/external_test.go +++ b/lib/versioner/external_test.go @@ -7,7 +7,6 @@ package versioner import ( - "io/ioutil" "os" "path/filepath" "runtime" @@ -85,7 +84,7 @@ func prepForRemoval(t *testing.T, file string) { if err := os.MkdirAll(filepath.Dir(file), 0755); err != nil { t.Fatal(err) } - if err := ioutil.WriteFile(file, []byte("hello\n"), 0644); err != nil { + if err := os.WriteFile(file, []byte("hello\n"), 0644); err != nil { t.Fatal(err) } } diff --git a/lib/versioner/simple_test.go b/lib/versioner/simple_test.go index 219492138..12dc2c81a 100644 --- a/lib/versioner/simple_test.go +++ b/lib/versioner/simple_test.go @@ -7,8 +7,8 @@ package versioner import ( - "io/ioutil" "math" + "os" "path/filepath" "testing" "time" @@ -55,7 +55,7 @@ func TestSimpleVersioningVersionCount(t *testing.T) { t.Skip("Test takes some time, skipping.") } - dir, err := ioutil.TempDir("", "") + dir, err := os.MkdirTemp("", "") //defer os.RemoveAll(dir) if err != nil { t.Error(err) diff --git a/lib/versioner/staggered_test.go b/lib/versioner/staggered_test.go index fbf78d4df..360c29ceb 100644 --- a/lib/versioner/staggered_test.go +++ b/lib/versioner/staggered_test.go @@ -7,7 +7,7 @@ package versioner import ( - "io/ioutil" + "os" "path/filepath" "sort" "strconv" @@ -133,11 +133,11 @@ func TestCreateVersionPath(t *testing.T) { ) // Create a test dir and file - tmpDir, err := ioutil.TempDir("", "") + tmpDir, err := os.MkdirTemp("", "") if err != nil { t.Fatal(err) } - if err := ioutil.WriteFile(filepath.Join(tmpDir, archiveFile), []byte("sup"), 0644); err != nil { + if err := os.WriteFile(filepath.Join(tmpDir, archiveFile), []byte("sup"), 0644); err != nil { t.Fatal(err) } diff --git a/lib/versioner/trashcan_test.go b/lib/versioner/trashcan_test.go index eb59f0954..891c64ecf 100644 --- a/lib/versioner/trashcan_test.go +++ b/lib/versioner/trashcan_test.go @@ -7,7 +7,8 @@ package versioner import ( - "io/ioutil" + "io" + "os" "testing" "time" @@ -19,12 +20,12 @@ func TestTrashcanArchiveRestoreSwitcharoo(t *testing.T) { // This tests that trashcan versioner restoration correctly archives existing file, because trashcan versioner // files are untagged, archiving existing file to replace with a restored version technically should collide in // in names. - tmpDir1, err := ioutil.TempDir("", "") + tmpDir1, err := os.MkdirTemp("", "") if err != nil { t.Fatal(err) } - tmpDir2, err := ioutil.TempDir("", "") + tmpDir2, err := os.MkdirTemp("", "") if err != nil { t.Fatal(err) } @@ -105,7 +106,7 @@ func readFile(t *testing.T, filesystem fs.Filesystem, name string) string { t.Fatal(err) } defer fd.Close() - buf, err := ioutil.ReadAll(fd) + buf, err := io.ReadAll(fd) if err != nil { t.Fatal(err) } diff --git a/lib/versioner/versioner_test.go b/lib/versioner/versioner_test.go index 4dfaaf322..4ba73c36c 100644 --- a/lib/versioner/versioner_test.go +++ b/lib/versioner/versioner_test.go @@ -9,7 +9,6 @@ package versioner import ( "context" "fmt" - "io/ioutil" "os" "path/filepath" "testing" @@ -56,7 +55,7 @@ func TestVersionerCleanOut(t *testing.T) { oldTime := time.Now().Add(-8 * 24 * time.Hour) for file, shouldRemove := range testcases { os.MkdirAll(filepath.Dir(file), 0777) - if err := ioutil.WriteFile(file, []byte("data"), 0644); err != nil { + if err := os.WriteFile(file, []byte("data"), 0644); err != nil { t.Fatal(err) } if shouldRemove { diff --git a/lib/weakhash/weakhash_test.go b/lib/weakhash/weakhash_test.go index 0d9ca91c2..78c2d3906 100644 --- a/lib/weakhash/weakhash_test.go +++ b/lib/weakhash/weakhash_test.go @@ -13,7 +13,6 @@ import ( "bytes" "context" "io" - "io/ioutil" "os" "reflect" "testing" @@ -22,7 +21,7 @@ import ( var payload = []byte("abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz") func TestFinder(t *testing.T) { - f, err := ioutil.TempFile("", "") + f, err := os.CreateTemp("", "") if err != nil { t.Error(err) } diff --git a/script/authors.go b/script/authors.go index 3068aebd5..37fa76bbe 100644 --- a/script/authors.go +++ b/script/authors.go @@ -15,7 +15,7 @@ package main import ( "bytes" "fmt" - "io/ioutil" + "io" "log" "math" "os" @@ -108,7 +108,7 @@ func main() { bs := readAll(htmlFile) bs = authorsRe.ReplaceAll(bs, []byte("id=\"contributor-list\">\n"+replacement+"\n ")) - if err := ioutil.WriteFile(htmlFile, bs, 0644); err != nil { + if err := os.WriteFile(htmlFile, bs, 0644); err != nil { log.Fatal(err) } @@ -173,7 +173,7 @@ func readAll(path string) []byte { } defer fd.Close() - bs, err := ioutil.ReadAll(fd) + bs, err := io.ReadAll(fd) if err != nil { log.Fatal(err) } diff --git a/script/commit-msg.go b/script/commit-msg.go index c5e178dea..fa1a13d16 100644 --- a/script/commit-msg.go +++ b/script/commit-msg.go @@ -12,7 +12,6 @@ package main import ( "bytes" "fmt" - "io/ioutil" "os" "path/filepath" "regexp" @@ -31,7 +30,7 @@ func main() { os.Exit(exitError) } - bs, err := ioutil.ReadFile(os.Args[1]) + bs, err := os.ReadFile(os.Args[1]) if err != nil { fmt.Println("Reading input:", err) os.Exit(exitError) diff --git a/script/genassets.go b/script/genassets.go index 71f965ab9..4d1b636f6 100644 --- a/script/genassets.go +++ b/script/genassets.go @@ -16,7 +16,6 @@ import ( "fmt" "go/format" "io" - "io/ioutil" "os" "path/filepath" "strconv" @@ -74,7 +73,7 @@ func walkerFor(basePath string) filepath.WalkFunc { } if info.Mode().IsRegular() { - data, err := ioutil.ReadFile(name) + data, err := os.ReadFile(name) if err != nil { return err } diff --git a/script/prune_mocks.go b/script/prune_mocks.go index ba9241027..ab56c3e08 100644 --- a/script/prune_mocks.go +++ b/script/prune_mocks.go @@ -12,7 +12,6 @@ package main import ( "bufio" "flag" - "io/ioutil" "log" "os" "os/exec" @@ -51,7 +50,7 @@ func pruneInterfaceCheck(path string, size int64) error { } defer fd.Close() - tmp, err := ioutil.TempFile(".", "") + tmp, err := os.CreateTemp(".", "") if err != nil { return err } diff --git a/script/transifexdl.go b/script/transifexdl.go index 321bdab6f..abb5291cf 100644 --- a/script/transifexdl.go +++ b/script/transifexdl.go @@ -12,7 +12,7 @@ package main import ( "encoding/json" "fmt" - "io/ioutil" + "io" "log" "net/http" "os" @@ -140,7 +140,7 @@ func loadValidLangs() []string { log.Fatal(err) } defer fd.Close() - bs, err := ioutil.ReadAll(fd) + bs, err := io.ReadAll(fd) if err != nil { log.Fatal(err) } diff --git a/test/conflict_test.go b/test/conflict_test.go index c163dbb56..de93fe354 100644 --- a/test/conflict_test.go +++ b/test/conflict_test.go @@ -11,7 +11,6 @@ package integration import ( "bytes" - "io/ioutil" "log" "os" "path/filepath" @@ -189,7 +188,7 @@ func TestConflictsDefault(t *testing.T) { if len(files) != 1 { t.Errorf("Expected 1 conflicted files instead of %d", len(files)) } - bs, err := ioutil.ReadFile("s1/testfile.txt") + bs, err := os.ReadFile("s1/testfile.txt") if err != nil { t.Error("reading file:", err) } @@ -216,26 +215,26 @@ func TestConflictsInitialMerge(t *testing.T) { // File 1 is a conflict - err = ioutil.WriteFile("s1/file1", []byte("hello\n"), 0644) + err = os.WriteFile("s1/file1", []byte("hello\n"), 0644) if err != nil { t.Fatal(err) } - err = ioutil.WriteFile("s2/file1", []byte("goodbye\n"), 0644) + err = os.WriteFile("s2/file1", []byte("goodbye\n"), 0644) if err != nil { t.Fatal(err) } // File 2 exists on s1 only - err = ioutil.WriteFile("s1/file2", []byte("hello\n"), 0644) + err = os.WriteFile("s1/file2", []byte("hello\n"), 0644) if err != nil { t.Fatal(err) } // File 3 exists on s2 only - err = ioutil.WriteFile("s2/file3", []byte("goodbye\n"), 0644) + err = os.WriteFile("s2/file3", []byte("goodbye\n"), 0644) if err != nil { t.Fatal(err) } @@ -315,15 +314,15 @@ func TestConflictsIndexReset(t *testing.T) { // Three files on s1 - err = ioutil.WriteFile("s1/file1", []byte("hello\n"), 0644) + err = os.WriteFile("s1/file1", []byte("hello\n"), 0644) if err != nil { t.Fatal(err) } - err = ioutil.WriteFile("s1/file2", []byte("hello\n"), 0644) + err = os.WriteFile("s1/file2", []byte("hello\n"), 0644) if err != nil { t.Fatal(err) } - err = ioutil.WriteFile("s2/file3", []byte("hello\n"), 0644) + err = os.WriteFile("s2/file3", []byte("hello\n"), 0644) if err != nil { t.Fatal(err) } @@ -371,7 +370,7 @@ func TestConflictsIndexReset(t *testing.T) { // locally after we rest the index, unless we have a fix for that. for i := 0; i < 5; i++ { - err = ioutil.WriteFile("s2/file2", []byte("hello1\n"), 0644) + err = os.WriteFile("s2/file2", []byte("hello1\n"), 0644) if err != nil { t.Fatal(err) } @@ -393,7 +392,7 @@ func TestConflictsIndexReset(t *testing.T) { // s1/file1 (remote) changes while receiver is down - err = ioutil.WriteFile("s1/file1", []byte("goodbye\n"), 0644) + err = os.WriteFile("s1/file1", []byte("goodbye\n"), 0644) if err != nil { t.Fatal(err) } @@ -406,7 +405,7 @@ func TestConflictsIndexReset(t *testing.T) { // s2/file2 (local) changes while receiver is down - err = ioutil.WriteFile("s2/file2", []byte("goodbye\n"), 0644) + err = os.WriteFile("s2/file2", []byte("goodbye\n"), 0644) if err != nil { t.Fatal(err) } @@ -468,22 +467,22 @@ func TestConflictsSameContent(t *testing.T) { // Two files on s1 - err = ioutil.WriteFile("s1/file1", []byte("hello\n"), 0644) + err = os.WriteFile("s1/file1", []byte("hello\n"), 0644) if err != nil { t.Fatal(err) } - err = ioutil.WriteFile("s1/file2", []byte("hello\n"), 0644) + err = os.WriteFile("s1/file2", []byte("hello\n"), 0644) if err != nil { t.Fatal(err) } // Two files on s2, content differs in file1 only, timestamps differ on both. - err = ioutil.WriteFile("s2/file1", []byte("goodbye\n"), 0644) + err = os.WriteFile("s2/file1", []byte("goodbye\n"), 0644) if err != nil { t.Fatal(err) } - err = ioutil.WriteFile("s2/file2", []byte("hello\n"), 0644) + err = os.WriteFile("s2/file2", []byte("hello\n"), 0644) if err != nil { t.Fatal(err) } diff --git a/test/delay_scan_test.go b/test/delay_scan_test.go index 8b451c982..1cb90e2c1 100644 --- a/test/delay_scan_test.go +++ b/test/delay_scan_test.go @@ -10,8 +10,8 @@ package integration import ( - "io/ioutil" "log" + "os" "sync" "testing" "time" @@ -31,7 +31,7 @@ func TestRescanWithDelay(t *testing.T) { } log.Println("Generating .stignore...") - err = ioutil.WriteFile("s1/.stignore", []byte("some ignore data\n"), 0644) + err = os.WriteFile("s1/.stignore", []byte("some ignore data\n"), 0644) if err != nil { t.Fatal(err) } diff --git a/test/http_test.go b/test/http_test.go index a00bdb7d2..4541c75b4 100644 --- a/test/http_test.go +++ b/test/http_test.go @@ -11,8 +11,9 @@ package integration import ( "bytes" - "io/ioutil" + "io" "net/http" + "os" "strings" "testing" @@ -33,7 +34,7 @@ func TestHTTPGetIndex(t *testing.T) { if res.StatusCode != 200 { t.Errorf("Status %d != 200", res.StatusCode) } - bs, err := ioutil.ReadAll(res.Body) + bs, err := io.ReadAll(res.Body) if err != nil { t.Fatal(err) } @@ -57,7 +58,7 @@ func TestHTTPGetIndex(t *testing.T) { if res.StatusCode != 200 { t.Errorf("Status %d != 200", res.StatusCode) } - bs, err = ioutil.ReadAll(res.Body) + bs, err = io.ReadAll(res.Body) if err != nil { t.Fatal(err) } @@ -222,7 +223,7 @@ func setupAPIBench() *rc.Process { panic(err) } - err = ioutil.WriteFile("s1/knownfile", []byte("somedatahere"), 0644) + err = os.WriteFile("s1/knownfile", []byte("somedatahere"), 0644) if err != nil { panic(err) } diff --git a/test/ignore_test.go b/test/ignore_test.go index 5022026c0..abc2faab4 100644 --- a/test/ignore_test.go +++ b/test/ignore_test.go @@ -10,7 +10,6 @@ package integration import ( - "io/ioutil" "log" "os" "path/filepath" @@ -67,7 +66,7 @@ func TestIgnores(t *testing.T) { // Add some of them to an ignore file - err = ioutil.WriteFile("s1/.stignore", + err = os.WriteFile("s1/.stignore", []byte("f1*\nf2\nd1*\nd2\ns1*\ns2\n(?i)*.txt"), // [fds][34] only non-ignored items 0644) if err != nil { @@ -92,7 +91,7 @@ func TestIgnores(t *testing.T) { // Change the pattern to include some of the files and dirs previously ignored time.Sleep(1100 * time.Millisecond) - err = ioutil.WriteFile("s1/.stignore", []byte("f2\nd2\ns2\n"), 0644) + err = os.WriteFile("s1/.stignore", []byte("f2\nd2\ns2\n"), 0644) // Rescan and verify that we see them diff --git a/test/override_test.go b/test/override_test.go index b2fa14f11..5851dfbe0 100644 --- a/test/override_test.go +++ b/test/override_test.go @@ -10,7 +10,7 @@ package integration import ( - "io/ioutil" + "io" "log" "os" "strings" @@ -127,7 +127,7 @@ func TestOverride(t *testing.T) { if err != nil { t.Fatal(err) } - bs, err := ioutil.ReadAll(fd) + bs, err := io.ReadAll(fd) if err != nil { t.Fatal(err) } @@ -141,7 +141,7 @@ func TestOverride(t *testing.T) { if err != nil { t.Fatal(err) } - bs, err = ioutil.ReadAll(fd) + bs, err = io.ReadAll(fd) if err != nil { t.Fatal(err) } @@ -295,7 +295,7 @@ func TestOverrideIgnores(t *testing.T) { if err != nil { t.Fatal(err) } - bs, err := ioutil.ReadAll(fd) + bs, err := io.ReadAll(fd) if err != nil { t.Fatal(err) } @@ -309,7 +309,7 @@ func TestOverrideIgnores(t *testing.T) { if err != nil { t.Fatal(err) } - bs, err = ioutil.ReadAll(fd) + bs, err = io.ReadAll(fd) if err != nil { t.Fatal(err) } @@ -337,7 +337,7 @@ func TestOverrideIgnores(t *testing.T) { if err != nil { t.Fatal(err) } - bs, err = ioutil.ReadAll(fd) + bs, err = io.ReadAll(fd) if err != nil { t.Fatal(err) } @@ -388,7 +388,7 @@ func TestOverrideIgnores(t *testing.T) { if err != nil { t.Fatal(err) } - bs, err = ioutil.ReadAll(fd) + bs, err = io.ReadAll(fd) if err != nil { t.Fatal(err) } @@ -423,7 +423,7 @@ func TestOverrideIgnores(t *testing.T) { if err != nil { t.Fatal(err) } - bs, err = ioutil.ReadAll(fd) + bs, err = io.ReadAll(fd) if err != nil { t.Fatal(err) } diff --git a/test/parallell_scan_test.go b/test/parallell_scan_test.go index e3f35f2b7..13a07d5b6 100644 --- a/test/parallell_scan_test.go +++ b/test/parallell_scan_test.go @@ -10,8 +10,8 @@ package integration import ( - "io/ioutil" "log" + "os" "sync" "testing" "time" @@ -31,7 +31,7 @@ func TestRescanInParallel(t *testing.T) { } log.Println("Generating .stignore...") - err = ioutil.WriteFile("s1/.stignore", []byte("some ignore data\n"), 0644) + err = os.WriteFile("s1/.stignore", []byte("some ignore data\n"), 0644) if err != nil { t.Fatal(err) } diff --git a/test/reset_test.go b/test/reset_test.go index 1e781c7e3..35d471571 100644 --- a/test/reset_test.go +++ b/test/reset_test.go @@ -13,7 +13,6 @@ import ( "bytes" "fmt" "io" - "io/ioutil" "log" "os" "path/filepath" @@ -147,7 +146,7 @@ func createFiles(t *testing.T) int { const n = 8 for i := 0; i < n; i++ { file := fmt.Sprintf("f%d", i) - if err := ioutil.WriteFile(filepath.Join("s1", file), []byte("data"), 0644); err != nil { + if err := os.WriteFile(filepath.Join("s1", file), []byte("data"), 0644); err != nil { t.Fatal(err) } } diff --git a/test/util.go b/test/util.go index 8f69dacda..99a0f7386 100644 --- a/test/util.go +++ b/test/util.go @@ -14,7 +14,6 @@ import ( "errors" "fmt" "io" - "io/ioutil" "log" "math/rand" "os" @@ -206,7 +205,7 @@ func alterFiles(dir string) error { return err } d1 := []byte("I used to be a dir: " + path) - err := ioutil.WriteFile(path, d1, 0644) + err := os.WriteFile(path, d1, 0644) if err != nil { return err } @@ -551,7 +550,7 @@ func startInstance(t *testing.T, i int) *rc.Process { } func symlinksSupported() bool { - tmp, err := ioutil.TempDir("", "symlink-test") + tmp, err := os.MkdirTemp("", "symlink-test") if err != nil { return false }