Replace most usages of ioutil with the underlying function

The ioutil functions are deprecated since Go 1.17 and only wrap another
library function. Thus directly call the underlying function.

This commit only mechanically replaces the function calls.
This commit is contained in:
Michael Eischer 2022-12-02 19:36:43 +01:00
parent 2d5e28e777
commit ff7ef5007e
57 changed files with 119 additions and 159 deletions

View file

@ -43,7 +43,6 @@ package main
import ( import (
"fmt" "fmt"
"io" "io"
"io/ioutil"
"os" "os"
"os/exec" "os/exec"
"path/filepath" "path/filepath"
@ -179,7 +178,7 @@ func test(cwd string, env map[string]string, args ...string) error {
// getVersion returns the version string from the file VERSION in the current // getVersion returns the version string from the file VERSION in the current
// directory. // directory.
func getVersionFromFile() string { func getVersionFromFile() string {
buf, err := ioutil.ReadFile("VERSION") buf, err := os.ReadFile("VERSION")
if err != nil { if err != nil {
verbosePrintf("error reading file VERSION: %v\n", err) verbosePrintf("error reading file VERSION: %v\n", err)
return "" return ""

View file

@ -6,7 +6,6 @@ import (
"context" "context"
"fmt" "fmt"
"io" "io"
"io/ioutil"
"os" "os"
"path" "path"
"path/filepath" "path/filepath"
@ -185,7 +184,7 @@ func readLines(filename string) ([]string, error) {
) )
if filename == "-" { if filename == "-" {
data, err = ioutil.ReadAll(os.Stdin) data, err = io.ReadAll(os.Stdin)
} else { } else {
data, err = textfile.Read(filename) data, err = textfile.Read(filename)
} }

View file

@ -2,8 +2,8 @@ package main
import ( import (
"context" "context"
"io/ioutil"
"math/rand" "math/rand"
"os"
"strconv" "strconv"
"strings" "strings"
"sync" "sync"
@ -171,7 +171,7 @@ func prepareCheckCache(opts CheckOptions, gopts *GlobalOptions) (cleanup func())
} }
// use a cache in a temporary directory // use a cache in a temporary directory
tempdir, err := ioutil.TempDir(cachedir, "restic-check-cache-") tempdir, err := os.MkdirTemp(cachedir, "restic-check-cache-")
if err != nil { if err != nil {
// if an error occurs, don't use any cache // if an error occurs, don't use any cache
Warnf("unable to create temporary directory for cache during check, disabling cache: %v\n", err) Warnf("unable to create temporary directory for cache during check, disabling cache: %v\n", err)

View file

@ -3,7 +3,6 @@ package main
import ( import (
"context" "context"
"encoding/json" "encoding/json"
"io/ioutil"
"os" "os"
"strings" "strings"
"sync" "sync"
@ -255,7 +254,7 @@ func runKey(ctx context.Context, gopts GlobalOptions, args []string) error {
} }
func loadPasswordFromFile(pwdFile string) (string, error) { func loadPasswordFromFile(pwdFile string) (string, error) {
s, err := ioutil.ReadFile(pwdFile) s, err := os.ReadFile(pwdFile)
if os.IsNotExist(err) { if os.IsNotExist(err) {
return "", errors.Fatalf("%s does not exist", pwdFile) return "", errors.Fatalf("%s does not exist", pwdFile)
} }

View file

@ -1,7 +1,6 @@
package main package main
import ( import (
"io/ioutil"
"os" "os"
"path/filepath" "path/filepath"
"testing" "testing"
@ -89,13 +88,13 @@ func TestIsExcludedByFile(t *testing.T) {
defer cleanup() defer cleanup()
foo := filepath.Join(tempDir, "foo") foo := filepath.Join(tempDir, "foo")
err := ioutil.WriteFile(foo, []byte("foo"), 0666) err := os.WriteFile(foo, []byte("foo"), 0666)
if err != nil { if err != nil {
t.Fatalf("could not write file: %v", err) t.Fatalf("could not write file: %v", err)
} }
if tc.tagFile != "" { if tc.tagFile != "" {
tagFile := filepath.Join(tempDir, tc.tagFile) tagFile := filepath.Join(tempDir, tc.tagFile)
err = ioutil.WriteFile(tagFile, []byte(tc.content), 0666) err = os.WriteFile(tagFile, []byte(tc.content), 0666)
if err != nil { if err != nil {
t.Fatalf("could not write tagfile: %v", err) t.Fatalf("could not write tagfile: %v", err)
} }
@ -150,7 +149,7 @@ func TestMultipleIsExcludedByFile(t *testing.T) {
// create directories first, then the file // create directories first, then the file
p := filepath.Join(tempDir, filepath.FromSlash(f.path)) p := filepath.Join(tempDir, filepath.FromSlash(f.path))
errs = append(errs, os.MkdirAll(filepath.Dir(p), 0700)) errs = append(errs, os.MkdirAll(filepath.Dir(p), 0700))
errs = append(errs, ioutil.WriteFile(p, []byte(f.path), 0600)) errs = append(errs, os.WriteFile(p, []byte(f.path), 0600))
} }
test.OKs(t, errs) // see if anything went wrong during the creation test.OKs(t, errs) // see if anything went wrong during the creation

View file

@ -1,7 +1,7 @@
package main package main
import ( import (
"io/ioutil" "io"
"testing" "testing"
) )
@ -10,7 +10,7 @@ import (
func TestFlags(t *testing.T) { func TestFlags(t *testing.T) {
for _, cmd := range cmdRoot.Commands() { for _, cmd := range cmdRoot.Commands() {
t.Run(cmd.Name(), func(t *testing.T) { t.Run(cmd.Name(), func(t *testing.T) {
cmd.Flags().SetOutput(ioutil.Discard) cmd.Flags().SetOutput(io.Discard)
err := cmd.ParseFlags([]string{"--help"}) err := cmd.ParseFlags([]string{"--help"})
if err.Error() == "pflag: help requested" { if err.Error() == "pflag: help requested" {
err = nil err = nil

View file

@ -2,7 +2,7 @@ package main
import ( import (
"bytes" "bytes"
"io/ioutil" "os"
"path/filepath" "path/filepath"
"testing" "testing"
@ -43,7 +43,7 @@ func TestReadRepo(t *testing.T) {
// test --repository-file option // test --repository-file option
foo := filepath.Join(tempDir, "foo") foo := filepath.Join(tempDir, "foo")
err = ioutil.WriteFile(foo, []byte(tempDir+"\n"), 0666) err = os.WriteFile(foo, []byte(tempDir+"\n"), 0666)
rtest.OK(t, err) rtest.OK(t, err)
var opts2 GlobalOptions var opts2 GlobalOptions

View file

@ -1,7 +1,7 @@
package main package main
import ( import (
"io/ioutil" "os"
"path/filepath" "path/filepath"
"testing" "testing"
@ -39,7 +39,7 @@ func TestBackupFailsWhenUsingInvalidPatternsFromFile(t *testing.T) {
// Create an exclude file with some invalid patterns // Create an exclude file with some invalid patterns
excludeFile := env.base + "/excludefile" excludeFile := env.base + "/excludefile"
fileErr := ioutil.WriteFile(excludeFile, []byte("*.go\n*[._]log[.-][0-9]\n!*[._]log[.-][0-9]"), 0644) fileErr := os.WriteFile(excludeFile, []byte("*.go\n*[._]log[.-][0-9]\n!*[._]log[.-][0-9]"), 0644)
if fileErr != nil { if fileErr != nil {
t.Fatalf("Could not write exclude file: %v", fileErr) t.Fatalf("Could not write exclude file: %v", fileErr)
} }

View file

@ -3,7 +3,6 @@ package main
import ( import (
"bytes" "bytes"
"fmt" "fmt"
"io/ioutil"
"os" "os"
"path/filepath" "path/filepath"
"runtime" "runtime"
@ -174,7 +173,7 @@ func withTestEnvironment(t testing.TB) (env *testEnvironment, cleanup func()) {
restic.TestDisableCheckPolynomial(t) restic.TestDisableCheckPolynomial(t)
retry.TestFastRetries(t) retry.TestFastRetries(t)
tempdir, err := ioutil.TempDir(rtest.TestTempDir, "restic-test-") tempdir, err := os.MkdirTemp(rtest.TestTempDir, "restic-test-")
rtest.OK(t, err) rtest.OK(t, err)
env = &testEnvironment{ env = &testEnvironment{

View file

@ -8,7 +8,6 @@ import (
"encoding/json" "encoding/json"
"fmt" "fmt"
"io" "io"
"io/ioutil"
mrand "math/rand" mrand "math/rand"
"os" "os"
"path/filepath" "path/filepath"
@ -65,7 +64,7 @@ func testRunBackupAssumeFailure(t testing.TB, dir string, target []string, opts
term := termstatus.New(gopts.stdout, gopts.stderr, gopts.Quiet) term := termstatus.New(gopts.stdout, gopts.stderr, gopts.Quiet)
wg.Go(func() error { term.Run(ctx); return nil }) wg.Go(func() error { term.Run(ctx); return nil })
gopts.stdout = ioutil.Discard gopts.stdout = io.Discard
t.Logf("backing up %v in %v", target, dir) t.Logf("backing up %v in %v", target, dir)
if dir != "" { if dir != "" {
cleanup := rtest.Chdir(t, dir) cleanup := rtest.Chdir(t, dir)
@ -183,7 +182,7 @@ func testRunDiffOutput(gopts GlobalOptions, firstSnapshotID string, secondSnapsh
} }
func testRunRebuildIndex(t testing.TB, gopts GlobalOptions) { func testRunRebuildIndex(t testing.TB, gopts GlobalOptions) {
globalOptions.stdout = ioutil.Discard globalOptions.stdout = io.Discard
defer func() { defer func() {
globalOptions.stdout = os.Stdout globalOptions.stdout = os.Stdout
}() }()
@ -419,7 +418,7 @@ func TestBackupNonExistingFile(t *testing.T) {
defer cleanup() defer cleanup()
testSetupBackupData(t, env) testSetupBackupData(t, env)
globalOptions.stderr = ioutil.Discard globalOptions.stderr = io.Discard
defer func() { defer func() {
globalOptions.stderr = os.Stderr globalOptions.stderr = os.Stderr
}() }()
@ -641,7 +640,7 @@ func TestBackupErrors(t *testing.T) {
}() }()
opts := BackupOptions{} opts := BackupOptions{}
gopts := env.gopts gopts := env.gopts
gopts.stderr = ioutil.Discard gopts.stderr = io.Discard
err := testRunBackupAssumeFailure(t, filepath.Dir(env.testdata), []string{"testdata"}, opts, gopts) err := testRunBackupAssumeFailure(t, filepath.Dir(env.testdata), []string{"testdata"}, opts, gopts)
rtest.Assert(t, err != nil, "Assumed failure, but no error occurred.") rtest.Assert(t, err != nil, "Assumed failure, but no error occurred.")
rtest.Assert(t, err == ErrInvalidSourceData, "Wrong error returned") rtest.Assert(t, err == ErrInvalidSourceData, "Wrong error returned")
@ -1243,7 +1242,7 @@ func TestRestoreLatest(t *testing.T) {
opts := BackupOptions{} opts := BackupOptions{}
// chdir manually here so we can get the current directory. This is not the // chdir manually here so we can get the current directory. This is not the
// same as the temp dir returned by ioutil.TempDir() on darwin. // same as the temp dir returned by os.MkdirTemp() on darwin.
back := rtest.Chdir(t, filepath.Dir(env.testdata)) back := rtest.Chdir(t, filepath.Dir(env.testdata))
defer back() defer back()
@ -1308,7 +1307,7 @@ func TestRestoreWithPermissionFailure(t *testing.T) {
rtest.Assert(t, len(snapshots) > 0, rtest.Assert(t, len(snapshots) > 0,
"no snapshots found in repo (%v)", datafile) "no snapshots found in repo (%v)", datafile)
globalOptions.stderr = ioutil.Discard globalOptions.stderr = io.Discard
defer func() { defer func() {
globalOptions.stderr = os.Stderr globalOptions.stderr = os.Stderr
}() }()
@ -1542,7 +1541,7 @@ func TestRebuildIndexFailsOnAppendOnly(t *testing.T) {
datafile := filepath.Join("..", "..", "internal", "checker", "testdata", "duplicate-packs-in-index-test-repo.tar.gz") datafile := filepath.Join("..", "..", "internal", "checker", "testdata", "duplicate-packs-in-index-test-repo.tar.gz")
rtest.SetupTarTestFixture(t, env.base, datafile) rtest.SetupTarTestFixture(t, env.base, datafile)
globalOptions.stdout = ioutil.Discard globalOptions.stdout = io.Discard
defer func() { defer func() {
globalOptions.stdout = os.Stdout globalOptions.stdout = os.Stdout
}() }()

View file

@ -1,7 +1,7 @@
package main package main
import ( import (
"io/ioutil" "os"
"path/filepath" "path/filepath"
"testing" "testing"
@ -167,7 +167,7 @@ func TestFillSecondaryGlobalOpts(t *testing.T) {
defer cleanup() defer cleanup()
//Create temporary password file //Create temporary password file
err := ioutil.WriteFile(filepath.Join(dir, "passwordFileDst"), []byte("secretDst"), 0666) err := os.WriteFile(filepath.Join(dir, "passwordFileDst"), []byte("secretDst"), 0666)
rtest.OK(t, err) rtest.OK(t, err)
// Test all valid cases // Test all valid cases

View file

@ -73,13 +73,13 @@ func run(cmd string, args ...string) {
func replace(filename, from, to string) { func replace(filename, from, to string) {
reg := regexp.MustCompile(from) reg := regexp.MustCompile(from)
buf, err := ioutil.ReadFile(filename) buf, err := os.ReadFile(filename)
if err != nil { if err != nil {
die("error reading file %v: %v", filename, err) die("error reading file %v: %v", filename, err)
} }
buf = reg.ReplaceAll(buf, []byte(to)) buf = reg.ReplaceAll(buf, []byte(to))
err = ioutil.WriteFile(filename, buf, 0644) err = os.WriteFile(filename, buf, 0644)
if err != nil { if err != nil {
die("error writing file %v: %v", filename, err) die("error writing file %v: %v", filename, err)
} }
@ -308,7 +308,7 @@ var versionPattern = `var version = ".*"`
const versionCodeFile = "cmd/restic/global.go" const versionCodeFile = "cmd/restic/global.go"
func updateVersion() { func updateVersion() {
err := ioutil.WriteFile("VERSION", []byte(opts.Version+"\n"), 0644) err := os.WriteFile("VERSION", []byte(opts.Version+"\n"), 0644)
if err != nil { if err != nil {
die("unable to write version to file: %v", err) die("unable to write version to file: %v", err)
} }
@ -420,7 +420,7 @@ func updateDocker(outputDir, version string) {
} }
func tempdir(prefix string) string { func tempdir(prefix string) string {
dir, err := ioutil.TempDir(getwd(), prefix) dir, err := os.MkdirTemp(getwd(), prefix)
if err != nil { if err != nil {
die("unable to create temp dir %q: %v", prefix, err) die("unable to create temp dir %q: %v", prefix, err)
} }

View file

@ -4,7 +4,6 @@ import (
"bytes" "bytes"
"context" "context"
"io" "io"
"io/ioutil"
"os" "os"
"path/filepath" "path/filepath"
"runtime" "runtime"
@ -189,7 +188,7 @@ func TestArchiverSaveFileReaderFS(t *testing.T) {
ModTime: ts, ModTime: ts,
Mode: 0123, Mode: 0123,
Name: filename, Name: filename,
ReadCloser: ioutil.NopCloser(strings.NewReader(test.Data)), ReadCloser: io.NopCloser(strings.NewReader(test.Data)),
} }
node, stats := saveFile(t, repo, filename, readerFs) node, stats := saveFile(t, repo, filename, readerFs)
@ -304,7 +303,7 @@ func TestArchiverSaveReaderFS(t *testing.T) {
ModTime: ts, ModTime: ts,
Mode: 0123, Mode: 0123,
Name: filename, Name: filename,
ReadCloser: ioutil.NopCloser(strings.NewReader(test.Data)), ReadCloser: io.NopCloser(strings.NewReader(test.Data)),
} }
arch := New(repo, readerFs, Options{}) arch := New(repo, readerFs, Options{})

View file

@ -3,7 +3,6 @@ package archiver
import ( import (
"context" "context"
"fmt" "fmt"
"io/ioutil"
"os" "os"
"path/filepath" "path/filepath"
"runtime" "runtime"
@ -21,7 +20,7 @@ func createTestFiles(t testing.TB, num int) (files []string, cleanup func()) {
for i := 0; i < 15; i++ { for i := 0; i < 15; i++ {
filename := fmt.Sprintf("testfile-%d", i) filename := fmt.Sprintf("testfile-%d", i)
err := ioutil.WriteFile(filepath.Join(tempdir, filename), []byte(filename), 0600) err := os.WriteFile(filepath.Join(tempdir, filename), []byte(filename), 0600)
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }

View file

@ -2,7 +2,6 @@ package archiver
import ( import (
"context" "context"
"io/ioutil"
"os" "os"
"path" "path"
"path/filepath" "path/filepath"
@ -73,7 +72,7 @@ func TestCreateFiles(t testing.TB, target string, dir TestDir) {
switch it := item.(type) { switch it := item.(type) {
case TestFile: case TestFile:
err := ioutil.WriteFile(targetPath, []byte(it.Content), 0644) err := os.WriteFile(targetPath, []byte(it.Content), 0644)
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
@ -152,7 +151,7 @@ func TestEnsureFiles(t testing.TB, target string, dir TestDir) {
return nil return nil
} }
content, err := ioutil.ReadFile(path) content, err := os.ReadFile(path)
if err != nil { if err != nil {
return err return err
} }

View file

@ -3,7 +3,6 @@ package archiver
import ( import (
"context" "context"
"fmt" "fmt"
"io/ioutil"
"os" "os"
"path/filepath" "path/filepath"
"testing" "testing"
@ -62,7 +61,7 @@ func createFilesAt(t testing.TB, targetdir string, files map[string]interface{})
switch it := item.(type) { switch it := item.(type) {
case TestFile: case TestFile:
err := ioutil.WriteFile(target, []byte(it.Content), 0600) err := os.WriteFile(target, []byte(it.Content), 0600)
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
@ -129,7 +128,7 @@ func TestTestCreateFiles(t *testing.T) {
continue continue
} }
content, err := ioutil.ReadFile(targetPath) content, err := os.ReadFile(targetPath)
if err != nil { if err != nil {
t.Error(err) t.Error(err)
continue continue

View file

@ -4,7 +4,6 @@ import (
"context" "context"
"fmt" "fmt"
"io" "io"
"io/ioutil"
"sort" "sort"
"strings" "strings"
"testing" "testing"
@ -109,7 +108,7 @@ func TestDry(t *testing.T) {
case "load": case "load":
data := "" data := ""
err = step.be.Load(ctx, handle, 100, 0, func(rd io.Reader) error { err = step.be.Load(ctx, handle, 100, 0, func(rd io.Reader) error {
buf, err := ioutil.ReadAll(rd) buf, err := io.ReadAll(rd)
data = string(buf) data = string(buf)
return err return err
}) })

View file

@ -4,9 +4,9 @@ import (
"crypto/tls" "crypto/tls"
"crypto/x509" "crypto/x509"
"encoding/pem" "encoding/pem"
"io/ioutil"
"net" "net"
"net/http" "net/http"
"os"
"strings" "strings"
"time" "time"
@ -30,7 +30,7 @@ type TransportOptions struct {
// readPEMCertKey reads a file and returns the PEM encoded certificate and key // readPEMCertKey reads a file and returns the PEM encoded certificate and key
// blocks. // blocks.
func readPEMCertKey(filename string) (certs []byte, key []byte, err error) { func readPEMCertKey(filename string) (certs []byte, key []byte, err error) {
data, err := ioutil.ReadFile(filename) data, err := os.ReadFile(filename)
if err != nil { if err != nil {
return nil, nil, errors.Wrap(err, "ReadFile") return nil, nil, errors.Wrap(err, "ReadFile")
} }
@ -105,7 +105,7 @@ func Transport(opts TransportOptions) (http.RoundTripper, error) {
if filename == "" { if filename == "" {
return nil, errors.Errorf("empty filename for root certificate supplied") return nil, errors.Errorf("empty filename for root certificate supplied")
} }
b, err := ioutil.ReadFile(filename) b, err := os.ReadFile(filename)
if err != nil { if err != nil {
return nil, errors.Errorf("unable to read root certificate: %v", err) return nil, errors.Errorf("unable to read root certificate: %v", err)
} }

View file

@ -4,7 +4,6 @@ import (
"context" "context"
"hash" "hash"
"io" "io"
"io/ioutil"
"os" "os"
"path/filepath" "path/filepath"
"syscall" "syscall"
@ -209,7 +208,7 @@ func (b *Local) Save(ctx context.Context, h restic.Handle, rd restic.RewindReade
return nil return nil
} }
var tempFile = ioutil.TempFile // Overridden by test. var tempFile = os.CreateTemp // Overridden by test.
// Load runs fn with a reader that yields the contents of the file at h at the // Load runs fn with a reader that yields the contents of the file at h at the
// given offset. // given offset.

View file

@ -2,7 +2,6 @@ package local_test
import ( import (
"context" "context"
"io/ioutil"
"os" "os"
"path/filepath" "path/filepath"
"testing" "testing"
@ -17,7 +16,7 @@ func newTestSuite(t testing.TB) *test.Suite {
return &test.Suite{ return &test.Suite{
// NewConfig returns a config for a new temporary backend that will be used in tests. // NewConfig returns a config for a new temporary backend that will be used in tests.
NewConfig: func() (interface{}, error) { NewConfig: func() (interface{}, error) {
dir, err := ioutil.TempDir(rtest.TestTempDir, "restic-test-local-") dir, err := os.MkdirTemp(rtest.TestTempDir, "restic-test-local-")
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }

View file

@ -6,7 +6,6 @@ import (
"encoding/base64" "encoding/base64"
"hash" "hash"
"io" "io"
"io/ioutil"
"sync" "sync"
"github.com/cespare/xxhash/v2" "github.com/cespare/xxhash/v2"
@ -96,7 +95,7 @@ func (be *MemoryBackend) Save(ctx context.Context, h restic.Handle, rd restic.Re
return errors.New("file already exists") return errors.New("file already exists")
} }
buf, err := ioutil.ReadAll(rd) buf, err := io.ReadAll(rd)
if err != nil { if err != nil {
return err return err
} }
@ -168,7 +167,7 @@ func (be *MemoryBackend) openReader(ctx context.Context, h restic.Handle, length
buf = buf[:length] buf = buf[:length]
} }
return be.sem.ReleaseTokenOnClose(ioutil.NopCloser(bytes.NewReader(buf)), nil), ctx.Err() return be.sem.ReleaseTokenOnClose(io.NopCloser(bytes.NewReader(buf)), nil), ctx.Err()
} }
// Stat returns information about a file in the backend. // Stat returns information about a file in the backend.

View file

@ -6,7 +6,6 @@ import (
"fmt" "fmt"
"hash" "hash"
"io" "io"
"io/ioutil"
"net/http" "net/http"
"net/url" "net/url"
"path" "path"
@ -89,7 +88,7 @@ func Create(ctx context.Context, cfg Config, rt http.RoundTripper) (*Backend, er
return nil, errors.Fatalf("server response unexpected: %v (%v)", resp.Status, resp.StatusCode) return nil, errors.Fatalf("server response unexpected: %v (%v)", resp.Status, resp.StatusCode)
} }
_, err = io.Copy(ioutil.Discard, resp.Body) _, err = io.Copy(io.Discard, resp.Body)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -133,7 +132,7 @@ func (b *Backend) Save(ctx context.Context, h restic.Handle, rd restic.RewindRea
// make sure that client.Post() cannot close the reader by wrapping it // make sure that client.Post() cannot close the reader by wrapping it
req, err := http.NewRequestWithContext(ctx, req, err := http.NewRequestWithContext(ctx,
http.MethodPost, b.Filename(h), ioutil.NopCloser(rd)) http.MethodPost, b.Filename(h), io.NopCloser(rd))
if err != nil { if err != nil {
return errors.WithStack(err) return errors.WithStack(err)
} }
@ -150,7 +149,7 @@ func (b *Backend) Save(ctx context.Context, h restic.Handle, rd restic.RewindRea
var cerr error var cerr error
if resp != nil { if resp != nil {
_, _ = io.Copy(ioutil.Discard, resp.Body) _, _ = io.Copy(io.Discard, resp.Body)
cerr = resp.Body.Close() cerr = resp.Body.Close()
} }
@ -245,7 +244,7 @@ func (b *Backend) openReader(ctx context.Context, h restic.Handle, length int, o
if err != nil { if err != nil {
if resp != nil { if resp != nil {
_, _ = io.Copy(ioutil.Discard, resp.Body) _, _ = io.Copy(io.Discard, resp.Body)
_ = resp.Body.Close() _ = resp.Body.Close()
} }
return nil, errors.Wrap(err, "client.Do") return nil, errors.Wrap(err, "client.Do")
@ -283,7 +282,7 @@ func (b *Backend) Stat(ctx context.Context, h restic.Handle) (restic.FileInfo, e
return restic.FileInfo{}, errors.WithStack(err) return restic.FileInfo{}, errors.WithStack(err)
} }
_, _ = io.Copy(ioutil.Discard, resp.Body) _, _ = io.Copy(io.Discard, resp.Body)
if err = resp.Body.Close(); err != nil { if err = resp.Body.Close(); err != nil {
return restic.FileInfo{}, errors.Wrap(err, "Close") return restic.FileInfo{}, errors.Wrap(err, "Close")
} }
@ -348,7 +347,7 @@ func (b *Backend) Remove(ctx context.Context, h restic.Handle) error {
return errors.Errorf("blob not removed, server response: %v (%v)", resp.Status, resp.StatusCode) return errors.Errorf("blob not removed, server response: %v (%v)", resp.Status, resp.StatusCode)
} }
_, err = io.Copy(ioutil.Discard, resp.Body) _, err = io.Copy(io.Discard, resp.Body)
if err != nil { if err != nil {
return errors.Wrap(err, "Copy") return errors.Wrap(err, "Copy")
} }

View file

@ -4,7 +4,6 @@ import (
"bytes" "bytes"
"context" "context"
"io" "io"
"io/ioutil"
"testing" "testing"
"time" "time"
@ -22,7 +21,7 @@ func TestBackendSaveRetry(t *testing.T) {
SaveFn: func(ctx context.Context, h restic.Handle, rd restic.RewindReader) error { SaveFn: func(ctx context.Context, h restic.Handle, rd restic.RewindReader) error {
if errcount == 0 { if errcount == 0 {
errcount++ errcount++
_, err := io.CopyN(ioutil.Discard, rd, 120) _, err := io.CopyN(io.Discard, rd, 120)
if err != nil { if err != nil {
return err return err
} }
@ -267,7 +266,7 @@ func TestBackendLoadRetry(t *testing.T) {
var buf []byte var buf []byte
err := retryBackend.Load(context.TODO(), restic.Handle{}, 0, 0, func(rd io.Reader) (err error) { err := retryBackend.Load(context.TODO(), restic.Handle{}, 0, 0, func(rd io.Reader) (err error) {
buf, err = ioutil.ReadAll(rd) buf, err = io.ReadAll(rd)
return err return err
}) })
test.OK(t, err) test.OK(t, err)

View file

@ -5,7 +5,6 @@ import (
"fmt" "fmt"
"hash" "hash"
"io" "io"
"io/ioutil"
"net/http" "net/http"
"os" "os"
"path" "path"
@ -296,7 +295,7 @@ func (be *Backend) Save(ctx context.Context, h restic.Handle, rd restic.RewindRe
opts.PartSize = 200 * 1024 * 1024 opts.PartSize = 200 * 1024 * 1024
debug.Log("PutObject(%v, %v, %v)", be.cfg.Bucket, objName, rd.Length()) debug.Log("PutObject(%v, %v, %v)", be.cfg.Bucket, objName, rd.Length())
info, err := be.client.PutObject(ctx, be.cfg.Bucket, objName, ioutil.NopCloser(rd), int64(rd.Length()), opts) info, err := be.client.PutObject(ctx, be.cfg.Bucket, objName, io.NopCloser(rd), int64(rd.Length()), opts)
debug.Log("%v -> %v bytes, err %#v: %v", objName, info.Size, err, err) debug.Log("%v -> %v bytes, err %#v: %v", objName, info.Size, err, err)

View file

@ -3,7 +3,6 @@ package sftp_test
import ( import (
"context" "context"
"fmt" "fmt"
"io/ioutil"
"os" "os"
"path/filepath" "path/filepath"
"strings" "strings"
@ -34,7 +33,7 @@ func newTestSuite(t testing.TB) *test.Suite {
return &test.Suite{ return &test.Suite{
// NewConfig returns a config for a new temporary backend that will be used in tests. // NewConfig returns a config for a new temporary backend that will be used in tests.
NewConfig: func() (interface{}, error) { NewConfig: func() (interface{}, error) {
dir, err := ioutil.TempDir(rtest.TestTempDir, "restic-test-sftp-") dir, err := os.MkdirTemp(rtest.TestTempDir, "restic-test-sftp-")
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }

View file

@ -5,7 +5,6 @@ import (
"context" "context"
"fmt" "fmt"
"io" "io"
"io/ioutil"
"math/rand" "math/rand"
"os" "os"
"reflect" "reflect"
@ -148,7 +147,7 @@ func (s *Suite) TestLoad(t *testing.T) {
} }
err = b.Load(context.TODO(), handle, 0, 0, func(rd io.Reader) error { err = b.Load(context.TODO(), handle, 0, 0, func(rd io.Reader) error {
_, err := io.Copy(ioutil.Discard, rd) _, err := io.Copy(io.Discard, rd)
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
@ -189,7 +188,7 @@ func (s *Suite) TestLoad(t *testing.T) {
var buf []byte var buf []byte
err := b.Load(context.TODO(), handle, getlen, int64(o), func(rd io.Reader) (ierr error) { err := b.Load(context.TODO(), handle, getlen, int64(o), func(rd io.Reader) (ierr error) {
buf, ierr = ioutil.ReadAll(rd) buf, ierr = io.ReadAll(rd)
return ierr return ierr
}) })
if err != nil { if err != nil {
@ -522,7 +521,7 @@ func (s *Suite) TestSave(t *testing.T) {
} }
// test saving from a tempfile // test saving from a tempfile
tmpfile, err := ioutil.TempFile("", "restic-backend-save-test-") tmpfile, err := os.CreateTemp("", "restic-backend-save-test-")
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
@ -678,7 +677,7 @@ func store(t testing.TB, b restic.Backend, tpe restic.FileType, data []byte) res
// testLoad loads a blob (but discards its contents). // testLoad loads a blob (but discards its contents).
func testLoad(b restic.Backend, h restic.Handle, length int, offset int64) error { func testLoad(b restic.Backend, h restic.Handle, length int, offset int64) error {
return b.Load(context.TODO(), h, 0, 0, func(rd io.Reader) (ierr error) { return b.Load(context.TODO(), h, 0, 0, func(rd io.Reader) (ierr error) {
_, ierr = io.Copy(ioutil.Discard, rd) _, ierr = io.Copy(io.Discard, rd)
return ierr return ierr
}) })
} }

View file

@ -5,7 +5,6 @@ import (
"context" "context"
"fmt" "fmt"
"io" "io"
"io/ioutil"
"math/rand" "math/rand"
"testing" "testing"
@ -79,7 +78,7 @@ func TestLoadAllBroken(t *testing.T) {
data[0] ^= 0xff data[0] ^= 0xff
b.OpenReaderFn = func(ctx context.Context, h restic.Handle, length int, offset int64) (io.ReadCloser, error) { b.OpenReaderFn = func(ctx context.Context, h restic.Handle, length int, offset int64) (io.ReadCloser, error) {
return ioutil.NopCloser(bytes.NewReader(data)), nil return io.NopCloser(bytes.NewReader(data)), nil
} }
// must fail on first try // must fail on first try

View file

@ -4,7 +4,6 @@ import (
"bytes" "bytes"
"context" "context"
"io" "io"
"io/ioutil"
"math/rand" "math/rand"
"sync" "sync"
"testing" "testing"
@ -203,7 +202,7 @@ func TestBackendRemoveBroken(t *testing.T) {
_ = rd.Close() _ = rd.Close()
}() }()
test.OK(t, err) test.OK(t, err)
cached, err := ioutil.ReadAll(rd) cached, err := io.ReadAll(rd)
test.OK(t, err) test.OK(t, err)
if !bytes.Equal(cached, data) { if !bytes.Equal(cached, data) {
t.Fatalf("wrong data cache") t.Fatalf("wrong data cache")

View file

@ -2,7 +2,6 @@ package cache
import ( import (
"fmt" "fmt"
"io/ioutil"
"os" "os"
"path/filepath" "path/filepath"
"regexp" "regexp"
@ -26,7 +25,7 @@ const dirMode = 0700
const fileMode = 0644 const fileMode = 0644
func readVersion(dir string) (v uint, err error) { func readVersion(dir string) (v uint, err error) {
buf, err := ioutil.ReadFile(filepath.Join(dir, "version")) buf, err := os.ReadFile(filepath.Join(dir, "version"))
if errors.Is(err, os.ErrNotExist) { if errors.Is(err, os.ErrNotExist) {
return 0, nil return 0, nil
} }
@ -130,7 +129,7 @@ func New(id string, basedir string) (c *Cache, err error) {
} }
if v < cacheVersion { if v < cacheVersion {
err = ioutil.WriteFile(filepath.Join(cachedir, "version"), []byte(fmt.Sprintf("%d", cacheVersion)), fileMode) err = os.WriteFile(filepath.Join(cachedir, "version"), []byte(fmt.Sprintf("%d", cacheVersion)), fileMode)
if err != nil { if err != nil {
return nil, errors.WithStack(err) return nil, errors.WithStack(err)
} }

View file

@ -2,7 +2,6 @@ package cache
import ( import (
"io" "io"
"io/ioutil"
"os" "os"
"path/filepath" "path/filepath"
"runtime" "runtime"
@ -106,7 +105,7 @@ func (c *Cache) Save(h restic.Handle, rd io.Reader) error {
// First save to a temporary location. This allows multiple concurrent // First save to a temporary location. This allows multiple concurrent
// restics to use a single cache dir. // restics to use a single cache dir.
f, err := ioutil.TempFile(dir, "tmp-") f, err := os.CreateTemp(dir, "tmp-")
if err != nil { if err != nil {
return err return err
} }

View file

@ -3,7 +3,7 @@ package cache
import ( import (
"bytes" "bytes"
"fmt" "fmt"
"io/ioutil" "io"
"math/rand" "math/rand"
"os" "os"
"runtime" "runtime"
@ -55,7 +55,7 @@ func load(t testing.TB, c *Cache, h restic.Handle) []byte {
t.Fatalf("load() returned nil reader") t.Fatalf("load() returned nil reader")
} }
buf, err := ioutil.ReadAll(rd) buf, err := io.ReadAll(rd)
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
@ -174,7 +174,7 @@ func TestFileLoad(t *testing.T) {
t.Fatal(err) t.Fatal(err)
} }
buf, err := ioutil.ReadAll(rd) buf, err := io.ReadAll(rd)
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
@ -258,7 +258,7 @@ func TestFileSaveConcurrent(t *testing.T) {
} }
defer func() { _ = f.Close() }() defer func() { _ = f.Close() }()
read, err := ioutil.ReadAll(f) read, err := io.ReadAll(f)
if err == nil && !bytes.Equal(read, data) { if err == nil && !bytes.Equal(read, data) {
err = errors.New("mismatch between Save and Load") err = errors.New("mismatch between Save and Load")
} }

View file

@ -6,7 +6,6 @@ import (
"context" "context"
"fmt" "fmt"
"io" "io"
"io/ioutil"
"runtime" "runtime"
"sort" "sort"
"sync" "sync"
@ -556,7 +555,7 @@ func checkPack(ctx context.Context, r restic.Repository, id restic.ID, blobs []r
} }
// read remainder, which should be the pack header // read remainder, which should be the pack header
hdrBuf, err = ioutil.ReadAll(bufRd) hdrBuf, err = io.ReadAll(bufRd)
if err != nil { if err != nil {
return err return err
} }

View file

@ -3,7 +3,6 @@ package checker_test
import ( import (
"context" "context"
"io" "io"
"io/ioutil"
"math/rand" "math/rand"
"os" "os"
"path/filepath" "path/filepath"
@ -208,7 +207,7 @@ func TestModifiedIndex(t *testing.T) {
Name: "90f838b4ac28735fda8644fe6a08dbc742e57aaf81b30977b4fefa357010eafd", Name: "90f838b4ac28735fda8644fe6a08dbc742e57aaf81b30977b4fefa357010eafd",
} }
tmpfile, err := ioutil.TempFile("", "restic-test-mod-index-") tmpfile, err := os.CreateTemp("", "restic-test-mod-index-")
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }

View file

@ -3,7 +3,6 @@ package debug
import ( import (
"fmt" "fmt"
"io" "io"
"io/ioutil"
"net/http" "net/http"
"net/http/httputil" "net/http/httputil"
"os" "os"
@ -30,7 +29,7 @@ func (rd *eofDetectReader) Read(p []byte) (n int, err error) {
func (rd *eofDetectReader) Close() error { func (rd *eofDetectReader) Close() error {
if !rd.eofSeen { if !rd.eofSeen {
buf, err := ioutil.ReadAll(rd) buf, err := io.ReadAll(rd)
msg := fmt.Sprintf("body not drained, %d bytes not read", len(buf)) msg := fmt.Sprintf("body not drained, %d bytes not read", len(buf))
if err != nil { if err != nil {
msg += fmt.Sprintf(", error: %v", err) msg += fmt.Sprintf(", error: %v", err)

View file

@ -5,7 +5,6 @@ import (
"bytes" "bytes"
"fmt" "fmt"
"io" "io"
"io/ioutil"
"os" "os"
"path/filepath" "path/filepath"
"strings" "strings"
@ -91,7 +90,7 @@ func checkTar(t *testing.T, testDir string, srcTar *bytes.Buffer) error {
if match.Size() != hdr.Size { if match.Size() != hdr.Size {
return fmt.Errorf("size does not match got %v want %v", hdr.Size, match.Size()) return fmt.Errorf("size does not match got %v want %v", hdr.Size, match.Size())
} }
contentsFile, err := ioutil.ReadFile(matchPath) contentsFile, err := os.ReadFile(matchPath)
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }

View file

@ -4,7 +4,6 @@ import (
"archive/zip" "archive/zip"
"bytes" "bytes"
"fmt" "fmt"
"io/ioutil"
"os" "os"
"path/filepath" "path/filepath"
"strings" "strings"
@ -107,7 +106,7 @@ func checkZip(t *testing.T, testDir string, srcZip *bytes.Buffer) error {
if uint64(match.Size()) != f.UncompressedSize64 { if uint64(match.Size()) != f.UncompressedSize64 {
return fmt.Errorf("size does not match got %v want %v", f.UncompressedSize64, match.Size()) return fmt.Errorf("size does not match got %v want %v", f.UncompressedSize64, match.Size())
} }
contentsFile, err := ioutil.ReadFile(matchPath) contentsFile, err := os.ReadFile(matchPath)
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }

View file

@ -4,7 +4,6 @@
package fs package fs
import ( import (
"io/ioutil"
"os" "os"
"syscall" "syscall"
) )
@ -18,7 +17,7 @@ func fixpath(name string) string {
// TempFile creates a temporary file which has already been deleted (on // TempFile creates a temporary file which has already been deleted (on
// supported platforms) // supported platforms)
func TempFile(dir, prefix string) (f *os.File, err error) { func TempFile(dir, prefix string) (f *os.File, err error) {
f, err = ioutil.TempFile(dir, prefix) f, err = os.CreateTemp(dir, prefix)
if err != nil { if err != nil {
return nil, err return nil, err
} }

View file

@ -36,7 +36,7 @@ func fixpath(name string) string {
// TempFile creates a temporary file which is marked as delete-on-close // TempFile creates a temporary file which is marked as delete-on-close
func TempFile(dir, prefix string) (f *os.File, err error) { func TempFile(dir, prefix string) (f *os.File, err error) {
// slightly modified implementation of ioutil.TempFile(dir, prefix) to allow us to add // slightly modified implementation of os.CreateTemp(dir, prefix) to allow us to add
// the FILE_ATTRIBUTE_TEMPORARY | FILE_FLAG_DELETE_ON_CLOSE flags. // the FILE_ATTRIBUTE_TEMPORARY | FILE_FLAG_DELETE_ON_CLOSE flags.
// These provide two large benefits: // These provide two large benefits:
// FILE_ATTRIBUTE_TEMPORARY tells Windows to keep the file in memory only if possible // FILE_ATTRIBUTE_TEMPORARY tells Windows to keep the file in memory only if possible

View file

@ -2,7 +2,7 @@ package fs
import ( import (
"bytes" "bytes"
"io/ioutil" "io"
"os" "os"
"path" "path"
"sort" "sort"
@ -20,7 +20,7 @@ func verifyFileContentOpen(t testing.TB, fs FS, filename string, want []byte) {
t.Fatal(err) t.Fatal(err)
} }
buf, err := ioutil.ReadAll(f) buf, err := io.ReadAll(f)
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
@ -41,7 +41,7 @@ func verifyFileContentOpenFile(t testing.TB, fs FS, filename string, want []byte
t.Fatal(err) t.Fatal(err)
} }
buf, err := ioutil.ReadAll(f) buf, err := io.ReadAll(f)
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
@ -320,7 +320,7 @@ func TestFSReader(t *testing.T) {
for _, test := range tests { for _, test := range tests {
fs := &Reader{ fs := &Reader{
Name: filename, Name: filename,
ReadCloser: ioutil.NopCloser(bytes.NewReader(data)), ReadCloser: io.NopCloser(bytes.NewReader(data)),
Mode: 0644, Mode: 0644,
Size: int64(len(data)), Size: int64(len(data)),
@ -355,7 +355,7 @@ func TestFSReaderDir(t *testing.T) {
t.Run(test.name, func(t *testing.T) { t.Run(test.name, func(t *testing.T) {
fs := &Reader{ fs := &Reader{
Name: test.filename, Name: test.filename,
ReadCloser: ioutil.NopCloser(bytes.NewReader(data)), ReadCloser: io.NopCloser(bytes.NewReader(data)),
Mode: 0644, Mode: 0644,
Size: int64(len(data)), Size: int64(len(data)),
@ -410,7 +410,7 @@ func TestFSReaderMinFileSize(t *testing.T) {
t.Run(test.name, func(t *testing.T) { t.Run(test.name, func(t *testing.T) {
fs := &Reader{ fs := &Reader{
Name: "testfile", Name: "testfile",
ReadCloser: ioutil.NopCloser(strings.NewReader(test.data)), ReadCloser: io.NopCloser(strings.NewReader(test.data)),
Mode: 0644, Mode: 0644,
ModTime: time.Now(), ModTime: time.Now(),
AllowEmptyFile: test.allowEmpty, AllowEmptyFile: test.allowEmpty,
@ -421,7 +421,7 @@ func TestFSReaderMinFileSize(t *testing.T) {
t.Fatal(err) t.Fatal(err)
} }
buf, err := ioutil.ReadAll(f) buf, err := io.ReadAll(f)
if test.readMustErr { if test.readMustErr {
if err == nil { if err == nil {
t.Fatal("expected error not found, got nil") t.Fatal("expected error not found, got nil")

View file

@ -2,7 +2,6 @@ package fs
import ( import (
"io" "io"
"io/ioutil"
"os" "os"
"testing" "testing"
"time" "time"
@ -13,7 +12,7 @@ import (
) )
func TestNoatime(t *testing.T) { func TestNoatime(t *testing.T) {
f, err := ioutil.TempFile("", "restic-test-noatime") f, err := os.CreateTemp("", "restic-test-noatime")
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }

View file

@ -1,7 +1,7 @@
package fs package fs
import ( import (
"io/ioutil" "os"
"path/filepath" "path/filepath"
"testing" "testing"
@ -13,7 +13,7 @@ func TestExtendedStat(t *testing.T) {
defer cleanup() defer cleanup()
filename := filepath.Join(tempdir, "file") filename := filepath.Join(tempdir, "file")
err := ioutil.WriteFile(filename, []byte("foobar"), 0640) err := os.WriteFile(filename, []byte("foobar"), 0640)
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }

View file

@ -5,7 +5,6 @@ import (
"crypto/rand" "crypto/rand"
"crypto/sha256" "crypto/sha256"
"io" "io"
"io/ioutil"
"testing" "testing"
) )
@ -22,7 +21,7 @@ func TestReader(t *testing.T) {
expectedHash := sha256.Sum256(data) expectedHash := sha256.Sum256(data)
rd := NewReader(bytes.NewReader(data), sha256.New()) rd := NewReader(bytes.NewReader(data), sha256.New())
n, err := io.Copy(ioutil.Discard, rd) n, err := io.Copy(io.Discard, rd)
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
@ -54,7 +53,7 @@ func BenchmarkReader(b *testing.B) {
b.ResetTimer() b.ResetTimer()
for i := 0; i < b.N; i++ { for i := 0; i < b.N; i++ {
rd := NewReader(bytes.NewReader(buf), sha256.New()) rd := NewReader(bytes.NewReader(buf), sha256.New())
n, err := io.Copy(ioutil.Discard, rd) n, err := io.Copy(io.Discard, rd)
if err != nil { if err != nil {
b.Fatal(err) b.Fatal(err)
} }

View file

@ -5,7 +5,6 @@ import (
"crypto/rand" "crypto/rand"
"crypto/sha256" "crypto/sha256"
"io" "io"
"io/ioutil"
"testing" "testing"
) )
@ -21,7 +20,7 @@ func TestWriter(t *testing.T) {
expectedHash := sha256.Sum256(data) expectedHash := sha256.Sum256(data)
wr := NewWriter(ioutil.Discard, sha256.New()) wr := NewWriter(io.Discard, sha256.New())
n, err := io.Copy(wr, bytes.NewReader(data)) n, err := io.Copy(wr, bytes.NewReader(data))
if err != nil { if err != nil {
@ -54,7 +53,7 @@ func BenchmarkWriter(b *testing.B) {
b.SetBytes(int64(len(buf))) b.SetBytes(int64(len(buf)))
b.ResetTimer() b.ResetTimer()
for i := 0; i < b.N; i++ { for i := 0; i < b.N; i++ {
wr := NewWriter(ioutil.Discard, sha256.New()) wr := NewWriter(io.Discard, sha256.New())
n, err := io.Copy(wr, bytes.NewReader(buf)) n, err := io.Copy(wr, bytes.NewReader(buf))
if err != nil { if err != nil {
b.Fatal(err) b.Fatal(err)

View file

@ -4,7 +4,6 @@ import (
"context" "context"
"fmt" "fmt"
"io" "io"
"io/ioutil"
"os" "os"
"path/filepath" "path/filepath"
@ -81,7 +80,7 @@ func (*UpgradeRepoV2) upgrade(ctx context.Context, repo restic.Repository) error
} }
func (m *UpgradeRepoV2) Apply(ctx context.Context, repo restic.Repository) error { func (m *UpgradeRepoV2) Apply(ctx context.Context, repo restic.Repository) error {
tempdir, err := ioutil.TempDir("", "restic-migrate-upgrade-repo-v2-") tempdir, err := os.MkdirTemp("", "restic-migrate-upgrade-repo-v2-")
if err != nil { if err != nil {
return fmt.Errorf("create temp dir failed: %w", err) return fmt.Errorf("create temp dir failed: %w", err)
} }
@ -91,7 +90,7 @@ func (m *UpgradeRepoV2) Apply(ctx context.Context, repo restic.Repository) error
// read raw config file and save it to a temp dir, just in case // read raw config file and save it to a temp dir, just in case
var rawConfigFile []byte var rawConfigFile []byte
err = repo.Backend().Load(ctx, h, 0, 0, func(rd io.Reader) (err error) { err = repo.Backend().Load(ctx, h, 0, 0, func(rd io.Reader) (err error) {
rawConfigFile, err = ioutil.ReadAll(rd) rawConfigFile, err = io.ReadAll(rd)
return err return err
}) })
if err != nil { if err != nil {
@ -99,7 +98,7 @@ func (m *UpgradeRepoV2) Apply(ctx context.Context, repo restic.Repository) error
} }
backupFileName := filepath.Join(tempdir, "config") backupFileName := filepath.Join(tempdir, "config")
err = ioutil.WriteFile(backupFileName, rawConfigFile, 0600) err = os.WriteFile(backupFileName, rawConfigFile, 0600)
if err != nil { if err != nil {
return fmt.Errorf("write config file backup to %v failed: %w", tempdir, err) return fmt.Errorf("write config file backup to %v failed: %w", tempdir, err)
} }

View file

@ -4,7 +4,6 @@ import (
"bufio" "bufio"
"context" "context"
"io" "io"
"io/ioutil"
"os" "os"
"runtime" "runtime"
"sync" "sync"
@ -151,7 +150,7 @@ func (r *Repository) savePacker(ctx context.Context, t restic.BlobType, p *Packe
} }
hr := hashing.NewReader(rd, sha256.New()) hr := hashing.NewReader(rd, sha256.New())
_, err = io.Copy(ioutil.Discard, hr) _, err = io.Copy(io.Discard, hr)
if err != nil { if err != nil {
return err return err
} }

View file

@ -2,7 +2,6 @@ package restic_test
import ( import (
"context" "context"
"io/ioutil"
"os" "os"
"path/filepath" "path/filepath"
"runtime" "runtime"
@ -14,7 +13,7 @@ import (
) )
func BenchmarkNodeFillUser(t *testing.B) { func BenchmarkNodeFillUser(t *testing.B) {
tempfile, err := ioutil.TempFile("", "restic-test-temp-") tempfile, err := os.CreateTemp("", "restic-test-temp-")
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
@ -38,7 +37,7 @@ func BenchmarkNodeFillUser(t *testing.B) {
} }
func BenchmarkNodeFromFileInfo(t *testing.B) { func BenchmarkNodeFromFileInfo(t *testing.B) {
tempfile, err := ioutil.TempFile("", "restic-test-temp-") tempfile, err := os.CreateTemp("", "restic-test-temp-")
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
@ -167,7 +166,7 @@ var nodeTests = []restic.Node{
} }
func TestNodeRestoreAt(t *testing.T) { func TestNodeRestoreAt(t *testing.T) {
tempdir, err := ioutil.TempDir(rtest.TestTempDir, "restic-test-") tempdir, err := os.MkdirTemp(rtest.TestTempDir, "restic-test-")
rtest.OK(t, err) rtest.OK(t, err)
defer func() { defer func() {

View file

@ -5,7 +5,6 @@ import (
"crypto/md5" "crypto/md5"
"hash" "hash"
"io" "io"
"io/ioutil"
"math/rand" "math/rand"
"os" "os"
"path/filepath" "path/filepath"
@ -32,7 +31,7 @@ func TestFileReader(t *testing.T) {
defer cleanup() defer cleanup()
filename := filepath.Join(d, "file-reader-test") filename := filepath.Join(d, "file-reader-test")
err := ioutil.WriteFile(filename, buf, 0600) err := os.WriteFile(filename, buf, 0600)
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }

View file

@ -3,7 +3,7 @@ package restic_test
import ( import (
"encoding/json" "encoding/json"
"fmt" "fmt"
"io/ioutil" "os"
"path/filepath" "path/filepath"
"testing" "testing"
"time" "time"
@ -61,7 +61,7 @@ type ApplyPolicyResult struct {
} }
func loadGoldenFile(t testing.TB, filename string) (res ApplyPolicyResult) { func loadGoldenFile(t testing.TB, filename string) (res ApplyPolicyResult) {
buf, err := ioutil.ReadFile(filename) buf, err := os.ReadFile(filename)
if err != nil { if err != nil {
t.Fatalf("error loading golden file %v: %v", filename, err) t.Fatalf("error loading golden file %v: %v", filename, err)
} }
@ -85,7 +85,7 @@ func saveGoldenFile(t testing.TB, filename string, keep restic.Snapshots, reason
t.Fatalf("error marshaling result: %v", err) t.Fatalf("error marshaling result: %v", err)
} }
if err = ioutil.WriteFile(filename, buf, 0644); err != nil { if err = os.WriteFile(filename, buf, 0644); err != nil {
t.Fatalf("unable to update golden file: %v", err) t.Fatalf("unable to update golden file: %v", err)
} }
} }

View file

@ -4,7 +4,6 @@ import (
"context" "context"
"encoding/json" "encoding/json"
"errors" "errors"
"io/ioutil"
"os" "os"
"path/filepath" "path/filepath"
"strconv" "strconv"
@ -27,7 +26,7 @@ var testFiles = []struct {
} }
func createTempDir(t *testing.T) string { func createTempDir(t *testing.T) string {
tempdir, err := ioutil.TempDir(rtest.TestTempDir, "restic-test-") tempdir, err := os.MkdirTemp(rtest.TestTempDir, "restic-test-")
rtest.OK(t, err) rtest.OK(t, err)
for _, test := range testFiles { for _, test := range testFiles {

View file

@ -5,7 +5,7 @@ import (
"context" "context"
"fmt" "fmt"
"io" "io"
"io/ioutil" "os"
"testing" "testing"
"github.com/restic/restic/internal/crypto" "github.com/restic/restic/internal/crypto"
@ -171,7 +171,7 @@ func restoreAndVerify(t *testing.T, tempdir string, content []TestFile, files ma
func verifyRestore(t *testing.T, r *fileRestorer, repo *TestRepo) { func verifyRestore(t *testing.T, r *fileRestorer, repo *TestRepo) {
for _, file := range r.files { for _, file := range r.files {
target := r.targetPath(file.location) target := r.targetPath(file.location)
data, err := ioutil.ReadFile(target) data, err := os.ReadFile(target)
if err != nil { if err != nil {
t.Errorf("unable to read file %v: %v", file.location, err) t.Errorf("unable to read file %v: %v", file.location, err)
continue continue

View file

@ -1,7 +1,7 @@
package restorer package restorer
import ( import (
"io/ioutil" "os"
"testing" "testing"
rtest "github.com/restic/restic/internal/test" rtest "github.com/restic/restic/internal/test"
@ -28,11 +28,11 @@ func TestFilesWriterBasic(t *testing.T) {
rtest.OK(t, w.writeToFile(f2, []byte{2}, 1, -1, false)) rtest.OK(t, w.writeToFile(f2, []byte{2}, 1, -1, false))
rtest.Equals(t, 0, len(w.buckets[0].files)) rtest.Equals(t, 0, len(w.buckets[0].files))
buf, err := ioutil.ReadFile(f1) buf, err := os.ReadFile(f1)
rtest.OK(t, err) rtest.OK(t, err)
rtest.Equals(t, []byte{1, 1}, buf) rtest.Equals(t, []byte{1, 1}, buf)
buf, err = ioutil.ReadFile(f2) buf, err = os.ReadFile(f2)
rtest.OK(t, err) rtest.OK(t, err)
rtest.Equals(t, []byte{2, 2}, buf) rtest.Equals(t, []byte{2, 2}, buf)
} }

View file

@ -3,7 +3,7 @@ package restorer
import ( import (
"bytes" "bytes"
"context" "context"
"io/ioutil" "io"
"math" "math"
"os" "os"
"path/filepath" "path/filepath"
@ -401,7 +401,7 @@ func TestRestorer(t *testing.T) {
} }
for filename, content := range test.Files { for filename, content := range test.Files {
data, err := ioutil.ReadFile(filepath.Join(tempdir, filepath.FromSlash(filename))) data, err := os.ReadFile(filepath.Join(tempdir, filepath.FromSlash(filename)))
if err != nil { if err != nil {
t.Errorf("unable to read file %v: %v", filename, err) t.Errorf("unable to read file %v: %v", filename, err)
continue continue
@ -477,7 +477,7 @@ func TestRestorerRelative(t *testing.T) {
} }
for filename, content := range test.Files { for filename, content := range test.Files {
data, err := ioutil.ReadFile(filepath.Join(tempdir, "restore", filepath.FromSlash(filename))) data, err := os.ReadFile(filepath.Join(tempdir, "restore", filepath.FromSlash(filename)))
if err != nil { if err != nil {
t.Errorf("unable to read file %v: %v", filename, err) t.Errorf("unable to read file %v: %v", filename, err)
continue continue
@ -825,7 +825,7 @@ func TestVerifyCancel(t *testing.T) {
defer cancel() defer cancel()
rtest.OK(t, res.RestoreTo(ctx, tempdir)) rtest.OK(t, res.RestoreTo(ctx, tempdir))
err := ioutil.WriteFile(filepath.Join(tempdir, "foo"), []byte("bar"), 0644) err := os.WriteFile(filepath.Join(tempdir, "foo"), []byte("bar"), 0644)
rtest.OK(t, err) rtest.OK(t, err)
var errs []error var errs []error
@ -850,7 +850,7 @@ func TestRestorerSparseFiles(t *testing.T) {
target := &fs.Reader{ target := &fs.Reader{
Mode: 0600, Mode: 0600,
Name: "/zeros", Name: "/zeros",
ReadCloser: ioutil.NopCloser(bytes.NewReader(zeros[:])), ReadCloser: io.NopCloser(bytes.NewReader(zeros[:])),
} }
sc := archiver.NewScanner(target) sc := archiver.NewScanner(target)
err := sc.Scan(context.TODO(), []string{"/zeros"}) err := sc.Scan(context.TODO(), []string{"/zeros"})
@ -873,7 +873,7 @@ func TestRestorerSparseFiles(t *testing.T) {
rtest.OK(t, err) rtest.OK(t, err)
filename := filepath.Join(tempdir, "zeros") filename := filepath.Join(tempdir, "zeros")
content, err := ioutil.ReadFile(filename) content, err := os.ReadFile(filename)
rtest.OK(t, err) rtest.OK(t, err)
rtest.Equals(t, len(zeros[:]), len(content)) rtest.Equals(t, len(zeros[:]), len(content))

View file

@ -10,7 +10,6 @@ import (
"encoding/hex" "encoding/hex"
"fmt" "fmt"
"io" "io"
"io/ioutil"
"os" "os"
"path/filepath" "path/filepath"
"runtime" "runtime"
@ -69,7 +68,7 @@ func extractToFile(buf []byte, filename, target string, printf func(string, ...i
// Write everything to a temp file // Write everything to a temp file
dir := filepath.Dir(target) dir := filepath.Dir(target)
new, err := ioutil.TempFile(dir, "restic") new, err := os.CreateTemp(dir, "restic")
if err != nil { if err != nil {
return err return err
} }

View file

@ -4,7 +4,7 @@ import (
"context" "context"
"encoding/json" "encoding/json"
"fmt" "fmt"
"io/ioutil" "io"
"net/http" "net/http"
"strings" "strings"
"time" "time"
@ -80,7 +80,7 @@ func GitHubLatestRelease(ctx context.Context, owner, repo string) (Release, erro
return Release{}, fmt.Errorf("unexpected status %v (%v) returned", res.StatusCode, res.Status) return Release{}, fmt.Errorf("unexpected status %v (%v) returned", res.StatusCode, res.Status)
} }
buf, err := ioutil.ReadAll(res.Body) buf, err := io.ReadAll(res.Body)
if err != nil { if err != nil {
_ = res.Body.Close() _ = res.Body.Close()
return Release{}, err return Release{}, err
@ -128,7 +128,7 @@ func getGithubData(ctx context.Context, url string) ([]byte, error) {
return nil, fmt.Errorf("unexpected status %v (%v) returned", res.StatusCode, res.Status) return nil, fmt.Errorf("unexpected status %v (%v) returned", res.StatusCode, res.Status)
} }
buf, err := ioutil.ReadAll(res.Body) buf, err := io.ReadAll(res.Body)
if err != nil { if err != nil {
_ = res.Body.Close() _ = res.Body.Close()
return nil, err return nil, err

View file

@ -5,7 +5,6 @@ import (
"compress/gzip" "compress/gzip"
"fmt" "fmt"
"io" "io"
"io/ioutil"
"os" "os"
"os/exec" "os/exec"
"path/filepath" "path/filepath"
@ -131,7 +130,7 @@ func SetupTarTestFixture(t testing.TB, outputDir, tarFile string) {
// Env creates a test environment and extracts the repository fixture. // Env creates a test environment and extracts the repository fixture.
// Returned is the repo path and a cleanup function. // Returned is the repo path and a cleanup function.
func Env(t testing.TB, repoFixture string) (repodir string, cleanup func()) { func Env(t testing.TB, repoFixture string) (repodir string, cleanup func()) {
tempdir, err := ioutil.TempDir(TestTempDir, "restic-test-env-") tempdir, err := os.MkdirTemp(TestTempDir, "restic-test-env-")
OK(t, err) OK(t, err)
fd, err := os.Open(repoFixture) fd, err := os.Open(repoFixture)
@ -195,7 +194,7 @@ func RemoveAll(t testing.TB, path string) {
// TempDir returns a temporary directory that is removed when cleanup is // TempDir returns a temporary directory that is removed when cleanup is
// called, except if TestCleanupTempDirs is set to false. // called, except if TestCleanupTempDirs is set to false.
func TempDir(t testing.TB) (path string, cleanup func()) { func TempDir(t testing.TB) (path string, cleanup func()) {
tempdir, err := ioutil.TempDir(TestTempDir, "restic-test-") tempdir, err := os.MkdirTemp(TestTempDir, "restic-test-")
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }

View file

@ -4,7 +4,7 @@ package textfile
import ( import (
"bytes" "bytes"
"io/ioutil" "os"
"golang.org/x/text/encoding/unicode" "golang.org/x/text/encoding/unicode"
) )
@ -34,7 +34,7 @@ func Decode(data []byte) ([]byte, error) {
// Read returns the contents of the file, converted to UTF-8, stripped of any BOM. // Read returns the contents of the file, converted to UTF-8, stripped of any BOM.
func Read(filename string) ([]byte, error) { func Read(filename string) ([]byte, error) {
data, err := ioutil.ReadFile(filename) data, err := os.ReadFile(filename)
if err != nil { if err != nil {
return nil, err return nil, err
} }

View file

@ -3,7 +3,6 @@ package textfile
import ( import (
"bytes" "bytes"
"encoding/hex" "encoding/hex"
"io/ioutil"
"os" "os"
"testing" "testing"
) )
@ -13,7 +12,7 @@ import (
func writeTempfile(t testing.TB, data []byte) (string, func()) { func writeTempfile(t testing.TB, data []byte) (string, func()) {
t.Helper() t.Helper()
f, err := ioutil.TempFile("", "restic-test-textfile-read-") f, err := os.CreateTemp("", "restic-test-textfile-read-")
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }