all: Remove usage of deprecated io/ioutil (#7971)

As of Go 1.16 io/ioutil is deprecated. This replaces usage with the
corresponding functions in package os and package io.
This commit is contained in:
Jakob Borg 2021-11-22 08:59:47 +01:00 committed by GitHub
parent bf89bffb0b
commit 4b750b6dc3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
71 changed files with 190 additions and 235 deletions

View File

@ -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)
}

View File

@ -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)

View File

@ -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
}

View File

@ -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)
}

View File

@ -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())

View File

@ -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)

View File

@ -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)
}

View File

@ -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)
}

View File

@ -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)

View File

@ -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)
}

View File

@ -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
}

View File

@ -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
}

View File

@ -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
}

View File

@ -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)
}

View File

@ -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

View File

@ -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)
}

View File

@ -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 {

View File

@ -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)

View File

@ -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
}

View File

@ -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("<html")) {
t.Fatal("No html in index.html")

View File

@ -9,7 +9,6 @@ package api
import (
"encoding/json"
"io"
"io/ioutil"
"net/http"
"github.com/julienschmidt/httprouter"
@ -407,7 +406,7 @@ func (c *configMuxBuilder) adjustLDAP(w http.ResponseWriter, r *http.Request, ld
// Unmarshals the content of the given body and stores it in to (i.e. to must be a pointer).
func unmarshalTo(body io.ReadCloser, to interface{}) error {
bs, err := ioutil.ReadAll(body)
bs, err := io.ReadAll(body)
body.Close()
if err != nil {
return err

View File

@ -10,7 +10,6 @@ import (
"bytes"
"compress/gzip"
"io"
"io/ioutil"
"net/http"
"net/http/httptest"
"strconv"
@ -31,7 +30,7 @@ func compress(s string) string {
func decompress(p []byte) (out []byte) {
r, err := gzip.NewReader(bytes.NewBuffer(p))
if err == nil {
out, err = ioutil.ReadAll(r)
out, err = io.ReadAll(r)
}
if err != nil {
panic(err)
@ -81,7 +80,7 @@ func testServe(t *testing.T, gzip bool) {
t.Errorf("unexpected ETag %q", etag)
}
body, _ := ioutil.ReadAll(res.Body)
body, _ := io.ReadAll(res.Body)
// Content-Length is the number of bytes in the encoded (compressed) body
// (https://stackoverflow.com/a/3819303).

View File

@ -12,7 +12,6 @@ import (
"encoding/xml"
"fmt"
"io"
"io/ioutil"
"net"
"net/url"
"os"
@ -163,7 +162,7 @@ func ReadXML(r io.Reader, myID protocol.DeviceID) (Configuration, int, error) {
}
func ReadJSON(r io.Reader, myID protocol.DeviceID) (Configuration, error) {
bs, err := ioutil.ReadAll(r)
bs, err := io.ReadAll(r)
if err != nil {
return Configuration{}, err
}

View File

@ -13,7 +13,6 @@ import (
"encoding/xml"
"fmt"
"io"
"io/ioutil"
"os"
"path/filepath"
"reflect"
@ -502,7 +501,7 @@ func TestFolderPath(t *testing.T) {
}
func TestFolderCheckPath(t *testing.T) {
n, err := ioutil.TempDir("", "")
n, err := os.MkdirTemp("", "")
if err != nil {
t.Fatal(err)
}
@ -643,8 +642,8 @@ func TestCopy(t *testing.T) {
t.Error("Config should have changed")
}
if !bytes.Equal(bsOrig, bsCopy) {
// ioutil.WriteFile("a", bsOrig, 0644)
// ioutil.WriteFile("b", bsCopy, 0644)
// os.WriteFile("a", bsOrig, 0644)
// os.WriteFile("b", bsCopy, 0644)
t.Error("Copy should be unchanged")
}
}
@ -1266,7 +1265,7 @@ func copyToTmp(path string) (string, error) {
return "", err
}
defer orig.Close()
temp, err := ioutil.TempFile("", "syncthing-configTest-")
temp, err := os.CreateTemp("", "syncthing-configTest-")
if err != nil {
return "", err
}

View File

@ -14,7 +14,6 @@ import (
"errors"
"fmt"
"io"
"io/ioutil"
"net/http"
"net/url"
"strconv"
@ -173,7 +172,7 @@ func (c *globalClient) Lookup(ctx context.Context, device protocol.DeviceID) (ad
return nil, err
}
bs, err := ioutil.ReadAll(resp.Body)
bs, err := io.ReadAll(resp.Body)
if err != nil {
return nil, err
}

View File

@ -9,7 +9,7 @@ package discover
import (
"context"
"crypto/tls"
"io/ioutil"
"io"
"net"
"net/http"
"strings"
@ -232,7 +232,7 @@ func (s *fakeDiscoveryServer) handler(w http.ResponseWriter, r *http.Request) {
}
if r.Method == "POST" {
s.announce, _ = ioutil.ReadAll(r.Body)
s.announce, _ = io.ReadAll(r.Body)
w.WriteHeader(204)
} else {
w.Header().Set("Content-Type", "application/json")

View File

@ -7,7 +7,6 @@
package fs
import (
"io/ioutil"
"os"
"path/filepath"
"runtime"
@ -21,7 +20,7 @@ import (
func setup(t *testing.T) (*BasicFilesystem, string) {
t.Helper()
dir, err := ioutil.TempDir("", "")
dir, err := os.MkdirTemp("", "")
if err != nil {
t.Fatal(err)
}

View File

@ -13,7 +13,6 @@ import (
"context"
"errors"
"fmt"
"io/ioutil"
"os"
"path/filepath"
"runtime"
@ -530,7 +529,7 @@ func renameTestFile(name string, old string, new string) {
func modifyTestFile(name string, file string, content string) {
joined := filepath.Join(testDirAbs, name, file)
err := ioutil.WriteFile(joined, []byte(content), 0755)
err := os.WriteFile(joined, []byte(content), 0755)
if err != nil {
panic(fmt.Sprintf("Failed to modify test file %s: %s", joined, err))
}

View File

@ -12,7 +12,6 @@ import (
"fmt"
"hash/fnv"
"io"
"io/ioutil"
"math/rand"
"net/url"
"os"
@ -787,7 +786,7 @@ func (f *fakeFile) readShortAt(p []byte, offs int64) (int, error) {
diff := offs - minOffs
if diff > 0 {
lr := io.LimitReader(f.rng, diff)
io.Copy(ioutil.Discard, lr)
io.Copy(io.Discard, lr)
}
f.offset = offs

View File

@ -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)
}

View File

@ -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)
}

View File

@ -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)

View File

@ -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())
}

View File

@ -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})
}

View File

@ -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)
}

View File

@ -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",
}

View File

@ -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)
}

View File

@ -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")

View File

@ -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")
}

View File

@ -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)
}

View File

@ -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)

View File

@ -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)
}

View File

@ -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)
}

View File

@ -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))

View File

@ -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")
}

View File

@ -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
}

View File

@ -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

View File

@ -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)
}

View File

@ -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)
}

View File

@ -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

View File

@ -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
}

View File

@ -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()

View File

@ -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)
}
}

View File

@ -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)

View File

@ -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)
}

View File

@ -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)
}

View File

@ -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 {

View File

@ -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)
}

View File

@ -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 </div>"))
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)
}

View File

@ -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)

View File

@ -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
}

View File

@ -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
}

View File

@ -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)
}

View File

@ -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)
}

View File

@ -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)
}

View File

@ -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)
}

View File

@ -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

View File

@ -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)
}

View File

@ -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)
}

View File

@ -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)
}
}

View File

@ -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
}