diff --git a/internal/fs/fs_reader.go b/internal/fs/fs_reader.go index 91fedb263..d991951aa 100644 --- a/internal/fs/fs_reader.go +++ b/internal/fs/fs_reader.go @@ -252,10 +252,6 @@ func (f fakeFile) Seek(int64, int) (int64, error) { return 0, os.ErrInvalid } -func (f fakeFile) Write(p []byte) (int, error) { - return 0, os.ErrInvalid -} - func (f fakeFile) Read(p []byte) (int, error) { return 0, os.ErrInvalid } diff --git a/internal/fs/helpers.go b/internal/fs/helpers.go index 7ce24afe9..b7f7ad6ba 100644 --- a/internal/fs/helpers.go +++ b/internal/fs/helpers.go @@ -1,10 +1,6 @@ package fs -import ( - "io/ioutil" - "os" - "testing" -) +import "os" // IsRegularFile returns true if fi belongs to a normal file. If fi is nil, // false is returned. @@ -15,22 +11,3 @@ func IsRegularFile(fi os.FileInfo) bool { return fi.Mode()&(os.ModeType|os.ModeCharDevice) == 0 } - -// TestTempFile returns a new temporary file, which is removed when cleanup() -// is called. -func TestTempFile(t testing.TB, prefix string) (File, func()) { - f, err := ioutil.TempFile("", prefix) - if err != nil { - t.Fatal(err) - } - - cleanup := func() { - _ = f.Close() - err = Remove(f.Name()) - if err != nil { - t.Fatal(err) - } - } - - return f, cleanup -} diff --git a/internal/fs/interface.go b/internal/fs/interface.go index 1c2260215..b26c56944 100644 --- a/internal/fs/interface.go +++ b/internal/fs/interface.go @@ -26,7 +26,6 @@ type FS interface { // File is an open file on a file system. type File interface { io.Reader - io.Writer io.Closer Fd() uintptr diff --git a/internal/textfile/read_test.go b/internal/textfile/read_test.go index 572a33ebe..8e8e659dc 100644 --- a/internal/textfile/read_test.go +++ b/internal/textfile/read_test.go @@ -3,25 +3,44 @@ package textfile import ( "bytes" "encoding/hex" + "io/ioutil" + "os" "testing" - - "github.com/restic/restic/internal/fs" ) -func writeTempfile(t testing.TB, data []byte) (fs.File, func()) { - f, removeTempfile := fs.TestTempFile(t, "restic-test-textfile-read-") +// writeTempfile writes data to a new temporary file and returns its name +// and a callback that removes it. +func writeTempfile(t testing.TB, data []byte) (string, func()) { + t.Helper() - _, err := f.Write(data) + f, err := ioutil.TempFile("", "restic-test-textfile-read-") + if err != nil { + t.Fatal(err) + } + name := f.Name() + + defer func() { + closeErr := f.Close() + if err == nil && closeErr != nil { + err = closeErr + } + if err != nil { + os.Remove(name) + t.Fatal(err) + } + }() + + _, err = f.Write(data) if err != nil { t.Fatal(err) } - err = f.Close() - if err != nil { - t.Fatal(err) + return name, func() { + err := os.Remove(name) + if err != nil { + t.Fatal(err) + } } - - return f, removeTempfile } func dec(s string) []byte { @@ -60,10 +79,10 @@ func TestRead(t *testing.T) { want = test.data } - f, cleanup := writeTempfile(t, test.data) + tempname, cleanup := writeTempfile(t, test.data) defer cleanup() - data, err := Read(f.Name()) + data, err := Read(tempname) if err != nil { t.Fatal(err) }