diff --git a/assemble_test.go b/assemble_test.go index 6392d81..7d81e09 100644 --- a/assemble_test.go +++ b/assemble_test.go @@ -5,17 +5,17 @@ import ( "context" "crypto/md5" "crypto/rand" - "github.com/stretchr/testify/require" "io" - "io/ioutil" "os" "path/filepath" "testing" + + "github.com/stretchr/testify/require" ) func TestExtract(t *testing.T) { // Make a test file that's guaranteed to have duplicate chunks. - b, err := ioutil.ReadFile("testdata/chunker.input") + b, err := os.ReadFile("testdata/chunker.input") if err != nil { t.Fatal(err) } @@ -23,7 +23,7 @@ func TestExtract(t *testing.T) { b = append(b, b...) } b = append(b, make([]byte, 2*ChunkSizeMaxDefault)...) // want to have at least one null-chunk in the input - in, err := ioutil.TempFile("", "in") + in, err := os.CreateTemp("", "in") if err != nil { t.Fatal(err) } @@ -67,14 +67,14 @@ func TestExtract(t *testing.T) { } // Prepare output files for each test - first a non-existing one - out1, err := ioutil.TempFile("", "out1") + out1, err := os.CreateTemp("", "out1") if err != nil { t.Fatal(err) } os.Remove(out1.Name()) // This one is a complete file matching what we expect at the end - out2, err := ioutil.TempFile("", "out2") + out2, err := os.CreateTemp("", "out2") if err != nil { t.Fatal(err) } @@ -85,7 +85,7 @@ func TestExtract(t *testing.T) { defer os.Remove(out2.Name()) // Incomplete or damaged file that has most but not all data - out3, err := ioutil.TempFile("", "out3") + out3, err := os.CreateTemp("", "out3") if err != nil { t.Fatal(err) } @@ -126,7 +126,7 @@ func TestExtract(t *testing.T) { ); err != nil { t.Fatal(err) } - b, err := ioutil.ReadFile(test.outfile) + b, err := os.ReadFile(test.outfile) if err != nil { t.Fatal(err) } @@ -141,7 +141,7 @@ func TestExtract(t *testing.T) { func TestSeed(t *testing.T) { // Prepare different types of data slices that'll be used to assemble target // and seed files with varying amount of duplication - data1, err := ioutil.ReadFile("testdata/chunker.input") + data1, err := os.ReadFile("testdata/chunker.input") if err != nil { t.Fatal(err) } @@ -200,7 +200,7 @@ func TestSeed(t *testing.T) { for name, test := range tests { t.Run(name, func(t *testing.T) { // Build the destination file so we can chunk it - dst, err := ioutil.TempFile("", "dst") + dst, err := os.CreateTemp("", "dst") if err != nil { t.Fatal(err) } @@ -234,7 +234,7 @@ func TestSeed(t *testing.T) { // Build the seed files and indexes then populate the array of seeds var seeds []Seed for _, f := range test.seeds { - seedFile, err := ioutil.TempFile("", "seed") + seedFile, err := os.CreateTemp("", "seed") if err != nil { t.Fatal(err) } @@ -265,7 +265,7 @@ func TestSeed(t *testing.T) { ); err != nil { t.Fatal(err) } - b, err := ioutil.ReadFile(dst.Name()) + b, err := os.ReadFile(dst.Name()) if err != nil { t.Fatal(err) } @@ -353,7 +353,7 @@ func TestSelfSeedInPlace(t *testing.T) { sum := md5.Sum(b) // Build a temp target file pre-populated with the correct content - dst, err := ioutil.TempFile("", "dst") + dst, err := os.CreateTemp("", "dst") if err != nil { t.Fatal(err) } @@ -373,7 +373,7 @@ func TestSelfSeedInPlace(t *testing.T) { } // Compare the checksums to that of the input data - b, err = ioutil.ReadFile(dst.Name()) + b, err = os.ReadFile(dst.Name()) if err != nil { t.Fatal(err) } diff --git a/chunker.go b/chunker.go index 1dacca5..bbe0894 100644 --- a/chunker.go +++ b/chunker.go @@ -4,7 +4,6 @@ import ( "errors" "fmt" "io" - "io/ioutil" "math/bits" ) @@ -234,7 +233,7 @@ func (c *Chunker) Advance(n int) error { _, err := rs.Seek(readerN, io.SeekCurrent) return err } - _, err := io.CopyN(ioutil.Discard, c.r, readerN) + _, err := io.CopyN(io.Discard, c.r, readerN) return err } diff --git a/cmd/desync/cache_test.go b/cmd/desync/cache_test.go index d1ee7e6..9e3a704 100644 --- a/cmd/desync/cache_test.go +++ b/cmd/desync/cache_test.go @@ -2,7 +2,8 @@ package main import ( "context" - "io/ioutil" + "io" + "os" "testing" "github.com/stretchr/testify/require" @@ -27,13 +28,13 @@ func TestCacheCommand(t *testing.T) { cmd.SetArgs(append(test.args, "-c", cache)) // Redirect the command's output to turn off the progressbar and run it - stderr = ioutil.Discard - cmd.SetOutput(ioutil.Discard) + stderr = io.Discard + cmd.SetOutput(io.Discard) _, err := cmd.ExecuteC() require.NoError(t, err) // If the file was split right, we'll have chunks in the dir now - dirs, err := ioutil.ReadDir(cache) + dirs, err := os.ReadDir(cache) require.NoError(t, err) require.NotEmpty(t, dirs) }) diff --git a/cmd/desync/cat_test.go b/cmd/desync/cat_test.go index 1491651..2d51b43 100644 --- a/cmd/desync/cat_test.go +++ b/cmd/desync/cat_test.go @@ -3,7 +3,8 @@ package main import ( "bytes" "context" - "io/ioutil" + "io" + "os" "testing" "github.com/stretchr/testify/require" @@ -11,7 +12,7 @@ import ( func TestCatCommand(t *testing.T) { // Read the whole expected blob from disk - f, err := ioutil.ReadFile("testdata/blob1") + f, err := os.ReadFile("testdata/blob1") require.NoError(t, err) for _, test := range []struct { @@ -33,7 +34,7 @@ func TestCatCommand(t *testing.T) { // Redirect the command's output stdout = b - cmd.SetOutput(ioutil.Discard) + cmd.SetOutput(io.Discard) _, err := cmd.ExecuteC() require.NoError(t, err) diff --git a/cmd/desync/chop_test.go b/cmd/desync/chop_test.go index fb927d6..c9e4a5f 100644 --- a/cmd/desync/chop_test.go +++ b/cmd/desync/chop_test.go @@ -2,7 +2,7 @@ package main import ( "context" - "io/ioutil" + "io" "os" "path/filepath" "testing" @@ -29,13 +29,13 @@ func TestChopCommand(t *testing.T) { cmd.SetArgs(args) // Redirect the command's output to turn off the progressbar and run it - stderr = ioutil.Discard - cmd.SetOutput(ioutil.Discard) + stderr = io.Discard + cmd.SetOutput(io.Discard) _, err := cmd.ExecuteC() require.NoError(t, err) // If the file was split right, we'll have chunks in the dir now - dirs, err := ioutil.ReadDir(store) + dirs, err := os.ReadDir(store) require.NoError(t, err) require.NotEmpty(t, dirs) } @@ -53,7 +53,7 @@ func TestChopErrors(t *testing.T) { } { t.Run(test.name, func(t *testing.T) { cmd := newChopCommand(context.Background()) - cmd.SetOutput(ioutil.Discard) + cmd.SetOutput(io.Discard) cmd.SetArgs(test.args) _, err := cmd.ExecuteC() require.Error(t, err) diff --git a/cmd/desync/chunkserver_test.go b/cmd/desync/chunkserver_test.go index 7237017..51b49ce 100644 --- a/cmd/desync/chunkserver_test.go +++ b/cmd/desync/chunkserver_test.go @@ -3,7 +3,7 @@ package main import ( "context" "fmt" - "io/ioutil" + "io" "net" "net/http" "path/filepath" @@ -25,8 +25,8 @@ func TestChunkServerReadCommand(t *testing.T) { // Run an "extract" command to confirm the chunk server provides chunks extractCmd := newExtractCommand(context.Background()) extractCmd.SetArgs([]string{"-s", store, "testdata/blob1.caibx", filepath.Join(outdir, "blob")}) - stdout = ioutil.Discard - extractCmd.SetOutput(ioutil.Discard) + stdout = io.Discard + extractCmd.SetOutput(io.Discard) _, err := extractCmd.ExecuteC() require.NoError(t, err) @@ -46,7 +46,7 @@ func TestChunkServerReadCommand(t *testing.T) { // the "chop" command and storing the chunks there. chopCmd := newChopCommand(context.Background()) chopCmd.SetArgs([]string{"-s", store, "testdata/blob2.caibx", "testdata/blob2"}) - chopCmd.SetOutput(ioutil.Discard) + chopCmd.SetOutput(io.Discard) _, err = chopCmd.ExecuteC() require.Error(t, err) require.Contains(t, err.Error(), "writing to upstream") @@ -63,7 +63,7 @@ func TestChunkServerWriteCommand(t *testing.T) { // Run a "chop" command to confirm the chunk server can be used to write chunks chopCmd := newChopCommand(context.Background()) chopCmd.SetArgs([]string{"-s", store, "testdata/blob1.caibx", "testdata/blob1"}) - chopCmd.SetOutput(ioutil.Discard) + chopCmd.SetOutput(io.Discard) _, err := chopCmd.ExecuteC() require.NoError(t, err) @@ -86,7 +86,7 @@ func TestChunkServerVerifiedTLS(t *testing.T) { // Run the "extract" command to confirm the TLS chunk server can be used extractCmd := newExtractCommand(context.Background()) extractCmd.SetArgs([]string{"--ca-cert", "testdata/ca.crt", "-s", store, "testdata/blob1.caibx", filepath.Join(outdir, "blob1")}) - extractCmd.SetOutput(ioutil.Discard) + extractCmd.SetOutput(io.Discard) _, err := extractCmd.ExecuteC() require.NoError(t, err) } @@ -94,8 +94,8 @@ func TestChunkServerVerifiedTLS(t *testing.T) { func TestChunkServerInsecureTLS(t *testing.T) { outdir := t.TempDir() - stderr = ioutil.Discard - stdout = ioutil.Discard + stderr = io.Discard + stdout = io.Discard // Start a (writable) server addr, cancel := startChunkServer(t, "-s", "testdata/blob1.store", "--key", "testdata/server.key", "--cert", "testdata/server.crt") @@ -106,15 +106,15 @@ func TestChunkServerInsecureTLS(t *testing.T) { // Run the "extract" command accepting any cert to confirm the TLS chunk server can be used extractCmd := newExtractCommand(context.Background()) extractCmd.SetArgs([]string{"-t", "-s", store, "testdata/blob1.caibx", filepath.Join(outdir, "blob1")}) - // extractCmd.SetOutput(ioutil.Discard) + // extractCmd.SetOutput(io.Discard) _, err := extractCmd.ExecuteC() require.NoError(t, err) // Run the "extract" command without accepting any cert. Should fail. extractCmd = newExtractCommand(context.Background()) - extractCmd.SetOutput(ioutil.Discard) + extractCmd.SetOutput(io.Discard) extractCmd.SetArgs([]string{"-s", store, "testdata/blob1.caibx", filepath.Join(outdir, "blob1")}) - extractCmd.SetOutput(ioutil.Discard) + extractCmd.SetOutput(io.Discard) _, err = extractCmd.ExecuteC() require.Error(t, err) @@ -123,8 +123,8 @@ func TestChunkServerInsecureTLS(t *testing.T) { func TestChunkServerMutualTLS(t *testing.T) { outdir := t.TempDir() - stderr = ioutil.Discard - stdout = ioutil.Discard + stderr = io.Discard + stdout = io.Discard // Start a (writable) server addr, cancel := startChunkServer(t, @@ -153,7 +153,7 @@ func TestChunkServerMutualTLS(t *testing.T) { extractCmd.SetArgs([]string{ "--ca-cert", "testdata/ca.crt", "-s", store, "testdata/blob1.caibx", filepath.Join(outdir, "blob1")}) - extractCmd.SetOutput(ioutil.Discard) + extractCmd.SetOutput(io.Discard) _, err = extractCmd.ExecuteC() require.Error(t, err) } diff --git a/cmd/desync/config_test.go b/cmd/desync/config_test.go index f7ecefa..c485abc 100644 --- a/cmd/desync/config_test.go +++ b/cmd/desync/config_test.go @@ -1,7 +1,6 @@ package main import ( - "io/ioutil" "os" "testing" @@ -10,11 +9,11 @@ import ( func TestConfigFile(t *testing.T) { cfgFileContent := []byte(`{"store-options": {"/path/to/store/":{"uncompressed": true}}}`) - f, err := ioutil.TempFile("", "") + f, err := os.CreateTemp("", "") require.NoError(t, err) f.Close() defer os.Remove(f.Name()) - require.NoError(t, ioutil.WriteFile(f.Name(), cfgFileContent, 0644)) + require.NoError(t, os.WriteFile(f.Name(), cfgFileContent, 0644)) // Set the global config file name cfgFile = f.Name() @@ -36,11 +35,11 @@ func TestConfigFile(t *testing.T) { func TestConfigFileMultipleMatches(t *testing.T) { cfgFileContent := []byte(`{"store-options": {"/path/to/store/":{"uncompressed": true}, "/path/to/store":{"uncompressed": false}}}`) - f, err := ioutil.TempFile("", "") + f, err := os.CreateTemp("", "") require.NoError(t, err) f.Close() defer os.Remove(f.Name()) - require.NoError(t, ioutil.WriteFile(f.Name(), cfgFileContent, 0644)) + require.NoError(t, os.WriteFile(f.Name(), cfgFileContent, 0644)) // Set the global config file name cfgFile = f.Name() diff --git a/cmd/desync/extract_test.go b/cmd/desync/extract_test.go index a1801ff..d857ac4 100644 --- a/cmd/desync/extract_test.go +++ b/cmd/desync/extract_test.go @@ -2,9 +2,10 @@ package main import ( "context" - "io/ioutil" + "io" "net/http" "net/http/httptest" + "os" "path/filepath" "testing" @@ -13,16 +14,16 @@ import ( func TestExtractCommand(t *testing.T) { // Read the whole expected blob from disk - expected, err := ioutil.ReadFile("testdata/blob1") + expected, err := os.ReadFile("testdata/blob1") require.NoError(t, err) // Now prepare several files used to extract into outDir := t.TempDir() out1 := filepath.Join(outDir, "out1") // Doesn't exit out2 := filepath.Join(outDir, "out2") // Exists, but different content - require.NoError(t, ioutil.WriteFile(out2, []byte{0, 1, 2, 3}, 0644)) + require.NoError(t, os.WriteFile(out2, []byte{0, 1, 2, 3}, 0644)) out3 := filepath.Join(outDir, "out3") // Exist and complete match - require.NoError(t, ioutil.WriteFile(out3, expected, 0644)) + require.NoError(t, os.WriteFile(out3, expected, 0644)) // Make a cache dir cacheDir := t.TempDir() @@ -87,13 +88,13 @@ func TestExtractCommand(t *testing.T) { cmd.SetArgs(append(test.args, test.output)) // Redirect the command's output and run it - stderr = ioutil.Discard - cmd.SetOutput(ioutil.Discard) + stderr = io.Discard + cmd.SetOutput(io.Discard) _, err := cmd.ExecuteC() require.NoError(t, err) // Compare to what we should have gotten - got, err := ioutil.ReadFile(test.output) + got, err := os.ReadFile(test.output) require.NoError(t, err) require.Equal(t, expected, got) }) @@ -115,8 +116,8 @@ func TestExtractWithFailover(t *testing.T) { cmd.SetArgs([]string{"--store", ts.URL + "|testdata/blob1.store", "testdata/blob1.caibx", out}) // Redirect the command's output and run it - stderr = ioutil.Discard - cmd.SetOutput(ioutil.Discard) + stderr = io.Discard + cmd.SetOutput(io.Discard) _, err := cmd.ExecuteC() require.NoError(t, err) } @@ -150,8 +151,8 @@ func TestExtractWithInvalidSeeds(t *testing.T) { cmd.SetArgs(append(test.args, test.output)) // Redirect the command's output and run it - stderr = ioutil.Discard - cmd.SetOutput(ioutil.Discard) + stderr = io.Discard + cmd.SetOutput(io.Discard) _, err := cmd.ExecuteC() require.Error(t, err) }) diff --git a/cmd/desync/indexserver.go b/cmd/desync/indexserver.go index 57e3c5a..7c3e441 100644 --- a/cmd/desync/indexserver.go +++ b/cmd/desync/indexserver.go @@ -6,7 +6,6 @@ import ( "crypto/x509" "errors" "fmt" - "io/ioutil" "log" "net/http" "os" @@ -122,7 +121,7 @@ func serve(ctx context.Context, opt cmdServerOptions, addresses ...string) error } if opt.clientCA != "" { certPool := x509.NewCertPool() - b, err := ioutil.ReadFile(opt.clientCA) + b, err := os.ReadFile(opt.clientCA) if err != nil { return err } diff --git a/cmd/desync/indexserver_test.go b/cmd/desync/indexserver_test.go index 0e7d672..120c80e 100644 --- a/cmd/desync/indexserver_test.go +++ b/cmd/desync/indexserver_test.go @@ -3,7 +3,7 @@ package main import ( "context" "fmt" - "io/ioutil" + "io" "net" "net/http" "strings" @@ -21,8 +21,8 @@ func TestIndexServerReadCommand(t *testing.T) { // Run a "list-chunks" command on a valid index to confirm it can be read listCmd := newListCommand(context.Background()) listCmd.SetArgs([]string{fmt.Sprintf("http://%s/blob1.caibx", addr)}) - stdout = ioutil.Discard - listCmd.SetOutput(ioutil.Discard) + stdout = io.Discard + listCmd.SetOutput(io.Discard) _, err := listCmd.ExecuteC() require.NoError(t, err) @@ -38,7 +38,7 @@ func TestIndexServerReadCommand(t *testing.T) { // the "make" command and storing a new index on the index server. makeCmd := newMakeCommand(context.Background()) makeCmd.SetArgs([]string{fmt.Sprintf("http://%s/new.caibx", addr), "testdata/blob1"}) - makeCmd.SetOutput(ioutil.Discard) + makeCmd.SetOutput(io.Discard) _, err = makeCmd.ExecuteC() require.Error(t, err) require.Contains(t, err.Error(), "writing to upstream") @@ -56,7 +56,7 @@ func TestIndexServerWriteCommand(t *testing.T) { // the "make" command and storing a new index on the index server. makeCmd := newMakeCommand(context.Background()) makeCmd.SetArgs([]string{fmt.Sprintf("http://%s/new.caibx", addr), "testdata/blob1"}) - makeCmd.SetOutput(ioutil.Discard) + makeCmd.SetOutput(io.Discard) _, err := makeCmd.ExecuteC() require.NoError(t, err) diff --git a/cmd/desync/info_test.go b/cmd/desync/info_test.go index ac84bf8..0deed41 100644 --- a/cmd/desync/info_test.go +++ b/cmd/desync/info_test.go @@ -4,7 +4,7 @@ import ( "bytes" "context" "encoding/json" - "io/ioutil" + "io" "testing" "github.com/stretchr/testify/require" @@ -113,7 +113,7 @@ func TestInfoCommand(t *testing.T) { // Redirect the command's output stdout = b - cmd.SetOutput(ioutil.Discard) + cmd.SetOutput(io.Discard) _, err = cmd.ExecuteC() require.NoError(t, err) diff --git a/cmd/desync/inspectchunks_test.go b/cmd/desync/inspectchunks_test.go index 9ad7361..5021789 100644 --- a/cmd/desync/inspectchunks_test.go +++ b/cmd/desync/inspectchunks_test.go @@ -4,7 +4,7 @@ import ( "bytes" "context" "encoding/json" - "io/ioutil" + "io" "os" "testing" @@ -44,7 +44,7 @@ func TestInspectChunksCommand(t *testing.T) { // Redirect the command's output stdout = b - cmd.SetOutput(ioutil.Discard) + cmd.SetOutput(io.Discard) _, err = cmd.ExecuteC() require.NoError(t, err) diff --git a/cmd/desync/list_test.go b/cmd/desync/list_test.go index 6f59384..0a17229 100644 --- a/cmd/desync/list_test.go +++ b/cmd/desync/list_test.go @@ -4,7 +4,7 @@ import ( "bufio" "bytes" "context" - "io/ioutil" + "io" "testing" "github.com/folbricht/desync" @@ -18,7 +18,7 @@ func TestListCommand(t *testing.T) { // Redirect the command's output stdout = b - cmd.SetOutput(ioutil.Discard) + cmd.SetOutput(io.Discard) _, err := cmd.ExecuteC() require.NoError(t, err) diff --git a/cmd/desync/verify_test.go b/cmd/desync/verify_test.go index 8f929c1..25fdac0 100644 --- a/cmd/desync/verify_test.go +++ b/cmd/desync/verify_test.go @@ -3,7 +3,6 @@ package main import ( "bytes" "context" - "io/ioutil" "os" "path/filepath" "testing" @@ -26,7 +25,7 @@ func TestVerifyCommand(t *testing.T) { invalidChunkFile := filepath.Join(store, "1234", invalidChunkID+".cacnk") err = os.MkdirAll(filepath.Dir(invalidChunkFile), 0755) require.NoError(t, err) - err = ioutil.WriteFile(invalidChunkFile, []byte("invalid"), 0600) + err = os.WriteFile(invalidChunkFile, []byte("invalid"), 0600) require.NoError(t, err) // Now run verify on the store. There should be an invalid one in there that should diff --git a/consoleindex.go b/consoleindex.go index a2ddf59..2e4fbac 100644 --- a/consoleindex.go +++ b/consoleindex.go @@ -1,7 +1,6 @@ package desync import ( - "io/ioutil" "os" "io" @@ -18,7 +17,7 @@ func NewConsoleIndexStore() (ConsoleIndexStore, error) { // GetIndexReader returns a reader from STDIN func (s ConsoleIndexStore) GetIndexReader(string) (io.ReadCloser, error) { - return ioutil.NopCloser(os.Stdin), nil + return io.NopCloser(os.Stdin), nil } // GetIndex reads an index from STDIN and returns it. diff --git a/format.go b/format.go index f7e9676..8296bf5 100644 --- a/format.go +++ b/format.go @@ -4,7 +4,6 @@ import ( "bytes" "fmt" "io" - "io/ioutil" "math" "os" "reflect" @@ -148,7 +147,7 @@ func (d *FormatDecoder) Next() (interface{}, error) { // If we previously returned a reader, make sure we advance all the way in // case the caller didn't read it all. if d.advance != nil { - io.Copy(ioutil.Discard, d.advance) + io.Copy(io.Discard, d.advance) d.advance = nil } hdr, err := d.r.ReadHeader() diff --git a/format_test.go b/format_test.go index ad5eb2a..187c32d 100644 --- a/format_test.go +++ b/format_test.go @@ -2,7 +2,6 @@ package desync import ( "bytes" - "io/ioutil" "os" "reflect" "testing" @@ -118,7 +117,7 @@ func TestEncoder(t *testing.T) { "testdata/nested.catar", } for _, name := range files { - in, err := ioutil.ReadFile(name) + in, err := os.ReadFile(name) if err != nil { t.Fatal(err) } diff --git a/gcs.go b/gcs.go index f4e6a30..edbb20a 100644 --- a/gcs.go +++ b/gcs.go @@ -5,7 +5,6 @@ import ( "context" "fmt" "io" - "io/ioutil" "net/url" "strings" @@ -37,9 +36,10 @@ type GCStore struct { // where there never is a leading slash, // and every folder name always is followed by a slash // so example outputs will be: -// -// folder1/ -// folder1/folder2/folder3/ +// +// +// folder1/ +// folder1/folder2/folder3/ func normalizeGCPrefix(path string) string { prefix := strings.Trim(path, "/") @@ -114,7 +114,7 @@ func (s GCStore) GetChunk(id ChunkID) (*Chunk, error) { } defer rc.Close() - b, err := ioutil.ReadAll(rc) + b, err := io.ReadAll(rc) if err == storage.ErrObjectNotExist { log.Warning("Unable to read from object in GCS bucket; the object may not exist, or the bucket may not exist, or you may not have permission to access it") diff --git a/index_test.go b/index_test.go index 60fddc3..304539c 100644 --- a/index_test.go +++ b/index_test.go @@ -3,7 +3,6 @@ package desync import ( "bytes" "context" - "io/ioutil" "os" "reflect" "testing" @@ -42,7 +41,7 @@ func TestIndexLoad(t *testing.T) { } func TestIndexWrite(t *testing.T) { - in, err := ioutil.ReadFile("testdata/index.caibx") + in, err := os.ReadFile("testdata/index.caibx") if err != nil { t.Fatal(err) } @@ -99,7 +98,7 @@ func TestIndexChunking(t *testing.T) { if _, err = idx.WriteTo(b); err != nil { t.Fatal(err) } - i, err := ioutil.ReadFile("testdata/chunker.index") + i, err := os.ReadFile("testdata/chunker.index") if err != nil { t.Fatal(err) } diff --git a/ioctl_linux.go b/ioctl_linux.go index 1f67d4a..62f8199 100644 --- a/ioctl_linux.go +++ b/ioctl_linux.go @@ -1,3 +1,4 @@ +//go:build linux // +build linux package desync @@ -5,7 +6,6 @@ package desync import ( "bytes" "encoding/binary" - "io/ioutil" "os" "path/filepath" "syscall" @@ -24,13 +24,13 @@ const fiCloneRange = 0x4020940d // two files. It'll create two tempfiles in the same dirs and attempt to perform // a 0-byte long block clone. If that's successful it'll return true. func CanClone(dstFile, srcFile string) bool { - dst, err := ioutil.TempFile(filepath.Dir(dstFile), ".tmp") + dst, err := os.CreateTemp(filepath.Dir(dstFile), ".tmp") if err != nil { return false } defer os.Remove(dst.Name()) defer dst.Close() - src, err := ioutil.TempFile(filepath.Dir(srcFile), ".tmp") + src, err := os.CreateTemp(filepath.Dir(srcFile), ".tmp") if err != nil { return false } diff --git a/local.go b/local.go index 518459f..19aef16 100644 --- a/local.go +++ b/local.go @@ -4,7 +4,6 @@ import ( "context" "fmt" "io" - "io/ioutil" "os" "path/filepath" "strings" @@ -48,7 +47,7 @@ func NewLocalStore(dir string, opt StoreOptions) (LocalStore, error) { // GetChunk reads and returns one (compressed!) chunk from the store func (s LocalStore) GetChunk(id ChunkID) (*Chunk, error) { _, p := s.nameFromID(id) - b, err := ioutil.ReadFile(p) + b, err := os.ReadFile(p) if os.IsNotExist(err) { return nil, ChunkMissing{id} } diff --git a/local_test.go b/local_test.go index 0f956f9..ff3c3d6 100644 --- a/local_test.go +++ b/local_test.go @@ -2,7 +2,7 @@ package desync import ( "context" - "io/ioutil" + "io" "os" "testing" @@ -42,7 +42,7 @@ func TestLocalStoreCompressed(t *testing.T) { // Now let's look at the file in the store directly to make sure it's compressed _, name := s.nameFromID(id) - b, err := ioutil.ReadFile(name) + b, err := os.ReadFile(name) require.NoError(t, err) require.NotEqual(t, dataIn, b, "chunk is not compressed") } @@ -79,7 +79,7 @@ func TestLocalStoreUncompressed(t *testing.T) { // Now let's look at the file in the store directly to make sure it's uncompressed _, name := s.nameFromID(id) - b, err := ioutil.ReadFile(name) + b, err := os.ReadFile(name) require.NoError(t, err) require.Equal(t, dataIn, b, "chunk is compressed") @@ -105,7 +105,7 @@ func TestLocalStoreErrorHandling(t *testing.T) { dirInvalid, nameInvalid := s.nameFromID(idInvalid) _ = os.Mkdir(dirInvalid, 0755) - err = ioutil.WriteFile(nameInvalid, []byte("invalid data"), 0644) + err = os.WriteFile(nameInvalid, []byte("invalid data"), 0644) require.NoError(t, err) // Also add a blank chunk @@ -114,7 +114,7 @@ func TestLocalStoreErrorHandling(t *testing.T) { dirBlank, nameBlank := s.nameFromID(idBlank) _ = os.Mkdir(dirBlank, 0755) - err = ioutil.WriteFile(nameBlank, nil, 0644) + err = os.WriteFile(nameBlank, nil, 0644) require.NoError(t, err) // Let's see if we can retrieve the good chunk and get errors from the bad ones @@ -131,7 +131,7 @@ func TestLocalStoreErrorHandling(t *testing.T) { } // Run the verify with repair enabled which should get rid of the invalid and blank chunks - err = s.Verify(context.Background(), 1, true, ioutil.Discard) + err = s.Verify(context.Background(), 1, true, io.Discard) require.NoError(t, err) // Let's see if we can still retrieve the good chunk and get Not Found for the others diff --git a/log.go b/log.go index 4174be1..bf85869 100644 --- a/log.go +++ b/log.go @@ -1,7 +1,7 @@ package desync import ( - "io/ioutil" + "io" "github.com/sirupsen/logrus" ) @@ -9,5 +9,5 @@ import ( var Log = logrus.New() func init() { - Log.SetOutput(ioutil.Discard) + Log.SetOutput(io.Discard) } diff --git a/mount-index_linux_test.go b/mount-index_linux_test.go index 7354322..80f2ef9 100644 --- a/mount-index_linux_test.go +++ b/mount-index_linux_test.go @@ -4,7 +4,6 @@ import ( "bytes" "context" "crypto/sha256" - "io/ioutil" "os" "path/filepath" "sync" @@ -35,7 +34,7 @@ func TestMountIndex(t *testing.T) { } // Calculate the expected hash - b, err := ioutil.ReadFile("testdata/blob1") + b, err := os.ReadFile("testdata/blob1") if err != nil { t.Fatal(err) } @@ -65,7 +64,7 @@ func TestMountIndex(t *testing.T) { } // Calculate the hash of the file in the mount point - b, err = ioutil.ReadFile(filepath.Join(mnt, "blob1")) + b, err = os.ReadFile(filepath.Join(mnt, "blob1")) if err != nil { t.Fatal(err) } diff --git a/nullseed.go b/nullseed.go index efdc30b..0cc45a9 100644 --- a/nullseed.go +++ b/nullseed.go @@ -4,7 +4,6 @@ import ( "context" "fmt" "io" - "io/ioutil" "os" "path/filepath" ) @@ -16,7 +15,7 @@ type nullChunkSeed struct { } func newNullChunkSeed(dstFile string, blocksize uint64, max uint64) (*nullChunkSeed, error) { - blockfile, err := ioutil.TempFile(filepath.Dir(dstFile), ".tmp-block") + blockfile, err := os.CreateTemp(filepath.Dir(dstFile), ".tmp-block") if err != nil { return nil, err } diff --git a/remotehttp.go b/remotehttp.go index 9927928..1249c01 100644 --- a/remotehttp.go +++ b/remotehttp.go @@ -5,9 +5,9 @@ import ( "crypto/tls" "fmt" "io" - "io/ioutil" "net/http" "net/url" + "os" "path" "strings" "time" @@ -60,7 +60,7 @@ func NewRemoteHTTPStoreBase(location *url.URL, opt StoreOptions) (*RemoteHTTPBas // Load custom CA set if provided if opt.CACert != "" { certPool := x509.NewCertPool() - b, err := ioutil.ReadFile(opt.CACert) + b, err := os.ReadFile(opt.CACert) if err != nil { return nil, err } @@ -132,7 +132,7 @@ func (r *RemoteHTTPBase) IssueHttpRequest(method string, u *url.URL, getReader G defer resp.Body.Close() - b, err := ioutil.ReadAll(resp.Body) + b, err := io.ReadAll(resp.Body) if err != nil { log.WithError(err).Error("error while reading response") return 0, nil, errors.Wrap(err, u.String()) diff --git a/remotehttp_test.go b/remotehttp_test.go index 0bdce87..15a15ac 100644 --- a/remotehttp_test.go +++ b/remotehttp_test.go @@ -2,7 +2,6 @@ package desync import ( "io" - "io/ioutil" "net/http" "net/http/httptest" "net/url" @@ -219,7 +218,7 @@ func TestPutChunk(t *testing.T) { attemptCount++ switch r.URL.String() { case "/3bc8/3bc8e3230df5515b1b40e938e49ebc765c6157d4cf4e2b9d5f9c272571365395": - content, err := ioutil.ReadAll(r.Body) + content, err := io.ReadAll(r.Body) if err != nil { w.WriteHeader(http.StatusBadRequest) io.WriteString(w, err.Error()) @@ -228,7 +227,7 @@ func TestPutChunk(t *testing.T) { w.WriteHeader(http.StatusOK) } case "/3cc8/3cc8e3230df5515b1b40e938e49ebc765c6157d4cf4e2b9d5f9c272571365395": - content, err := ioutil.ReadAll(r.Body) + content, err := io.ReadAll(r.Body) if err != nil { w.WriteHeader(http.StatusBadRequest) io.WriteString(w, err.Error()) @@ -247,7 +246,7 @@ func TestPutChunk(t *testing.T) { io.WriteString(w, "Bad Gateway") case "/65a1/65a128d0658c4cf0941771c7090fea6d9c6f981810659c24c91ba23edd71574b": if attemptCount >= 2 { - content, err := ioutil.ReadAll(r.Body) + content, err := io.ReadAll(r.Body) if err != nil { w.WriteHeader(http.StatusBadRequest) io.WriteString(w, err.Error()) diff --git a/remotehttpindex.go b/remotehttpindex.go index e0ce0a3..9723a9b 100644 --- a/remotehttpindex.go +++ b/remotehttpindex.go @@ -3,7 +3,6 @@ package desync import ( "bytes" "io" - "io/ioutil" "net/url" ) @@ -29,7 +28,7 @@ func (r RemoteHTTPIndex) GetIndexReader(name string) (rdr io.ReadCloser, e error if err != nil { return rdr, err } - rc := ioutil.NopCloser(bytes.NewReader(b)) + rc := io.NopCloser(bytes.NewReader(b)) return rc, nil } diff --git a/s3.go b/s3.go index a99c6b9..64edd69 100644 --- a/s3.go +++ b/s3.go @@ -4,7 +4,7 @@ import ( "bytes" "context" "fmt" - "io/ioutil" + "io" "net/url" "strings" @@ -101,7 +101,7 @@ retry: } defer obj.Close() - b, err := ioutil.ReadAll(obj) + b, err := io.ReadAll(obj) if err != nil { if attempt <= s.opt.ErrorRetry { goto retry diff --git a/selfseed_test.go b/selfseed_test.go index 5d521c3..055dd9c 100644 --- a/selfseed_test.go +++ b/selfseed_test.go @@ -4,7 +4,6 @@ import ( "context" "crypto/md5" "crypto/rand" - "io/ioutil" "os" "testing" ) @@ -98,7 +97,7 @@ func TestSelfSeed(t *testing.T) { sum := md5.Sum(b) // Build a temp target file to extract into - dst, err := ioutil.TempFile("", "dst") + dst, err := os.CreateTemp("", "dst") if err != nil { t.Fatal(err) } @@ -114,7 +113,7 @@ func TestSelfSeed(t *testing.T) { } // Compare the checksums to that of the input data - b, err = ioutil.ReadFile(dst.Name()) + b, err = os.ReadFile(dst.Name()) if err != nil { t.Fatal(err) } diff --git a/sftp.go b/sftp.go index 69cfdcd..ed6e35d 100644 --- a/sftp.go +++ b/sftp.go @@ -4,7 +4,6 @@ import ( "bytes" "context" "io" - "io/ioutil" "math/rand" "net/url" "os" @@ -167,7 +166,7 @@ func (s *SFTPStore) GetChunk(id ChunkID) (*Chunk, error) { return nil, err } defer f.Close() - b, err := ioutil.ReadAll(f) + b, err := io.ReadAll(f) if err != nil { return nil, errors.Wrapf(err, "unable to read from %s", name) } diff --git a/sparse-file.go b/sparse-file.go index 464bc9c..fe695d7 100644 --- a/sparse-file.go +++ b/sparse-file.go @@ -3,7 +3,6 @@ package desync import ( "errors" "io" - "io/ioutil" "os" "sort" "sync" @@ -321,7 +320,7 @@ func (l *sparseFileLoader) preloadChunksFromState(r io.Reader, n int) error { } func (l *sparseFileLoader) stateFromReader(r io.Reader) (bitmap.Bitmap, error) { - b, err := ioutil.ReadAll(r) + b, err := io.ReadAll(r) if err != nil { return nil, err } diff --git a/sparse-file_test.go b/sparse-file_test.go index 322a212..e1bcad1 100644 --- a/sparse-file_test.go +++ b/sparse-file_test.go @@ -3,7 +3,6 @@ package desync import ( "bytes" "crypto/sha256" - "io/ioutil" "math/rand" "os" "testing" @@ -52,7 +51,7 @@ func TestLoaderChunkRange(t *testing.T) { func TestSparseFileRead(t *testing.T) { // Sparse output file - sparseFile, err := ioutil.TempFile("", "") + sparseFile, err := os.CreateTemp("", "") require.NoError(t, err) defer os.Remove(sparseFile.Name()) @@ -69,7 +68,7 @@ func TestSparseFileRead(t *testing.T) { require.NoError(t, err) // // Calculate the expected hash - b, err := ioutil.ReadFile("testdata/blob1") + b, err := os.ReadFile("testdata/blob1") require.NoError(t, err) // Initialize the sparse file and open a handle @@ -82,8 +81,7 @@ func TestSparseFileRead(t *testing.T) { // Read a few random ranges and compare to the expected blob content for i := 0; i < 1000; i++ { length := rand.Intn(int(index.Index.ChunkSizeMax)) - offset := rand.Intn(int(index.Length()) - length -1) - + offset := rand.Intn(int(index.Length()) - length - 1) fromSparse := make([]byte, length) fromBlob := make([]byte, length) diff --git a/tar_test.go b/tar_test.go index 7991b11..066fb09 100644 --- a/tar_test.go +++ b/tar_test.go @@ -1,3 +1,4 @@ +//go:build !windows // +build !windows package desync @@ -6,7 +7,6 @@ import ( "bytes" "context" "fmt" - "io/ioutil" "os" "path/filepath" "reflect" @@ -34,7 +34,7 @@ func TestTar(t *testing.T) { "dir1/sub11/f12", } for i, name := range files { - ioutil.WriteFile(filepath.Join(base, name), []byte(fmt.Sprintf("filecontent%d", i)), 0644) + os.WriteFile(filepath.Join(base, name), []byte(fmt.Sprintf("filecontent%d", i)), 0644) } if err := os.Symlink("dir1", filepath.Join(base, "symlink")); err != nil { diff --git a/tarfs.go b/tarfs.go index fdda667..2417c50 100644 --- a/tarfs.go +++ b/tarfs.go @@ -3,7 +3,6 @@ package desync import ( gnutar "archive/tar" "io" - "io/ioutil" "os" "path" ) @@ -100,7 +99,7 @@ func (fs TarWriter) Close() error { // TarReader uses a GNU tar archive as source for a tar operation (to produce // a catar). type TarReader struct { - r *gnutar.Reader + r *gnutar.Reader root *File } @@ -122,7 +121,7 @@ func NewTarReader(r io.Reader, opts TarReaderOptions) *TarReader { } } return &TarReader{ - r: gnutar.NewReader(r), + r: gnutar.NewReader(r), root: root, } } @@ -155,7 +154,7 @@ func (fs *TarReader) Next() (f *File, err error) { Xattrs: h.Xattrs, DevMajor: uint64(h.Devmajor), DevMinor: uint64(h.Devminor), - Data: ioutil.NopCloser(fs.r), + Data: io.NopCloser(fs.r), } return f, nil diff --git a/tarfs_test.go b/tarfs_test.go index 47372f1..1719b60 100644 --- a/tarfs_test.go +++ b/tarfs_test.go @@ -3,7 +3,6 @@ package desync import ( "bytes" "context" - "io/ioutil" "os" "testing" ) @@ -17,7 +16,7 @@ func TestGnuTarWrite(t *testing.T) { defer r.Close() // Expected output - exp, err := ioutil.ReadFile("testdata/complex.gnu-tar") + exp, err := os.ReadFile("testdata/complex.gnu-tar") if err != nil { t.Fatal(err) }