diff --git a/logger/logger_test.go b/logger/logger_test.go index f22f8211..9111c0a2 100644 --- a/logger/logger_test.go +++ b/logger/logger_test.go @@ -17,7 +17,6 @@ import ( "errors" "flag" "fmt" - "io/ioutil" "os" "path/filepath" "strings" @@ -177,7 +176,7 @@ func TestLogger(t *testing.T) { checkLogger("Unable to close logger: dummy error") // Switch to file log - tmpDir, err := ioutil.TempDir("", "") + tmpDir, err := os.MkdirTemp("", "") if err != nil { t.Fatalf("Unable to create temp dir: %v", err) } @@ -188,7 +187,7 @@ func TestLogger(t *testing.T) { logger.SetFileSizeLimit(1000) // Reopen and check file content logger.ReopenLogFile() - buf, err := ioutil.ReadFile(fname) + buf, err := os.ReadFile(fname) if err != nil { t.Fatalf("Error reading file: %v", err) } @@ -201,7 +200,7 @@ func TestLogger(t *testing.T) { for i := 0; i < 100; i++ { logger.Noticef(notice) } - files, err := ioutil.ReadDir(tmpDir) + files, err := os.ReadDir(tmpDir) if err != nil { t.Fatalf("Unable to read temp dir: %v", err) } diff --git a/server/clustering_test.go b/server/clustering_test.go index 9b6f7b13..528db6c4 100644 --- a/server/clustering_test.go +++ b/server/clustering_test.go @@ -18,7 +18,6 @@ import ( "database/sql" "encoding/json" "fmt" - "io/ioutil" "math/rand" "net" "net/http" @@ -46,7 +45,7 @@ import ( var defaultRaftLog string func init() { - tmpDir, err := ioutil.TempDir("", "raft_logs_") + tmpDir, err := os.MkdirTemp("", "raft_logs_") if err != nil { panic("Could not create tmp dir") } @@ -3679,7 +3678,7 @@ func TestClusteringRaftLogReplayDoesNotDeleteLatestVersionOfChannel(t *testing.T follower := removeServer(servers, leader)[0] follower.Shutdown() witnessFile := filepath.Join(follower.opts.FilestoreDir, channel, "deleted.txt") - if err := ioutil.WriteFile(witnessFile, []byte("if present, channel has not been deleted then recreated"), 0666); err != nil { + if err := os.WriteFile(witnessFile, []byte("if present, channel has not been deleted then recreated"), 0666); err != nil { t.Fatalf("Error creating file: %v", err) } // Now restart.. @@ -4551,7 +4550,7 @@ func TestClusteringWithCryptoStore(t *testing.T) { check := func(t *testing.T, name, fname string) { t.Helper() - content, err := ioutil.ReadFile(fname) + content, err := os.ReadFile(fname) if err != nil { t.Fatalf("Error reading file %q: %v", fname1, err) } @@ -6770,7 +6769,7 @@ func TestClusteringRestoreSnapshotMsgsBailIfNoLeader(t *testing.T) { return nil }) - snaps, err := ioutil.ReadDir(filepath.Join(defaultRaftLog, "c", clusterName, "snapshots")) + snaps, err := os.ReadDir(filepath.Join(defaultRaftLog, "c", clusterName, "snapshots")) if err != nil { t.Fatalf("Error reading snapshots directory: %v", err) } diff --git a/server/conf_test.go b/server/conf_test.go index e54e1631..395d6486 100644 --- a/server/conf_test.go +++ b/server/conf_test.go @@ -16,7 +16,6 @@ package server import ( "bytes" "flag" - "io/ioutil" "os" "reflect" "runtime" @@ -314,11 +313,11 @@ func TestParsePermError(t *testing.T) { if runtime.GOOS == "windows" { t.SkipNow() } - tmpDir, err := ioutil.TempDir("", "streaming") + tmpDir, err := os.MkdirTemp("", "streaming") if err != nil { t.Fatalf("Could not create tmp dir: %v", err) } - file, err := ioutil.TempFile(tmpDir, "config.conf") + file, err := os.CreateTemp(tmpDir, "config.conf") if err != nil { t.Fatalf("Could not create tmp file: %v", err) } @@ -339,7 +338,7 @@ func TestParsePermError(t *testing.T) { func TestParseParserError(t *testing.T) { confFile := "wrong_config.conf" - if err := ioutil.WriteFile(confFile, []byte("x=."), 0660); err != nil { + if err := os.WriteFile(confFile, []byte("x=."), 0660); err != nil { t.Fatalf("Unexpected error creating conf file: %v", err) } defer os.Remove(confFile) @@ -351,7 +350,7 @@ func TestParseParserError(t *testing.T) { func TestParseStoreType(t *testing.T) { confFile := "wrong_config.conf" - if err := ioutil.WriteFile(confFile, []byte("store=memory"), 0660); err != nil { + if err := os.WriteFile(confFile, []byte("store=memory"), 0660); err != nil { t.Fatalf("Unexpected error creating conf file: %v", err) } defer os.Remove(confFile) @@ -364,7 +363,7 @@ func TestParseStoreType(t *testing.T) { } os.Remove(confFile) - if err := ioutil.WriteFile(confFile, []byte("store=xyz"), 0660); err != nil { + if err := os.WriteFile(confFile, []byte("store=xyz"), 0660); err != nil { t.Fatalf("Unexpected error creating conf file: %v", err) } defer os.Remove(confFile) @@ -380,7 +379,7 @@ func TestParseStoreType(t *testing.T) { stores.TypeSQL, } for _, gs := range goodStores { - if err := ioutil.WriteFile(confFile, []byte("store="+gs), 0660); err != nil { + if err := os.WriteFile(confFile, []byte("store="+gs), 0660); err != nil { t.Fatalf("Unexpected error creating conf file: %v", err) } defer os.Remove(confFile) @@ -398,7 +397,7 @@ func TestParseStoreType(t *testing.T) { func TestParsePerChannelLimitsSetToZero(t *testing.T) { confFile := "config.conf" defer os.Remove(confFile) - if err := ioutil.WriteFile(confFile, + if err := os.WriteFile(confFile, []byte("store_limits: {channels: {foo: {max_msgs: 0, max_bytes: 0, max_age: \"0\", max_subs: 0, max_inactivity: \"0\"}}}"), 0660); err != nil { t.Fatalf("Unexpected error creating conf file: %v", err) } @@ -532,7 +531,7 @@ func TestParseWrongTypes(t *testing.T) { func expectFailureFor(t *testing.T, content, errorMatch string) { confFile := "wrong_config.conf" - if err := ioutil.WriteFile(confFile, []byte(content), 0660); err != nil { + if err := os.WriteFile(confFile, []byte(content), 0660); err != nil { t.Fatalf("Unexpected error creating conf file: %v", err) } defer os.Remove(confFile) @@ -637,7 +636,7 @@ func TestParseConfigureOptions(t *testing.T) { streaming: { cluster_id: my_cluster }`) - if err := ioutil.WriteFile(sconf, scontent, 0660); err != nil { + if err := os.WriteFile(sconf, scontent, 0660); err != nil { t.Fatalf("Error creating conf file: %v", err) } ncontent := []byte(` @@ -645,7 +644,7 @@ func TestParseConfigureOptions(t *testing.T) { streaming: { cluster_id: my_cluster_2 }`) - if err := ioutil.WriteFile(nconf, ncontent, 0660); err != nil { + if err := os.WriteFile(nconf, ncontent, 0660); err != nil { t.Fatalf("Error creating conf file: %v", err) } sopts, nopts := mustNotFail([]string{"-sc", sconf, "-c", nconf}) @@ -700,7 +699,7 @@ func TestParseConfigureOptions(t *testing.T) { } else { ncontent = []byte(`logtime: true`) } - if err := ioutil.WriteFile(nconf, ncontent, 0660); err != nil { + if err := os.WriteFile(nconf, ncontent, 0660); err != nil { t.Fatalf("Error creating conf file: %v", err) } _, nopts = mustNotFail([]string{"-c", nconf}) diff --git a/server/monitor_test.go b/server/monitor_test.go index be9fda5f..4af7f459 100644 --- a/server/monitor_test.go +++ b/server/monitor_test.go @@ -18,9 +18,10 @@ import ( "crypto/x509" "encoding/json" "fmt" - "io/ioutil" + "io" "math/rand" "net/http" + "os" "reflect" "runtime" "strings" @@ -81,7 +82,7 @@ func getBodyEx(t *testing.T, client *http.Client, scheme, endpoint string, mp, e if ct != expectedContentType { stackFatalf(t, "Expected %s content-type, got %s\n", expectedContentType, ct) } - body, err := ioutil.ReadAll(resp.Body) + body, err := io.ReadAll(resp.Body) if err != nil { resp.Body.Close() stackFatalf(t, "Got an error reading the body: %v\n", err) @@ -155,7 +156,7 @@ func TestMonitorStartOwnHTTPSServer(t *testing.T) { defer s.Shutdown() tlsConfig := &tls.Config{} - caCert, err := ioutil.ReadFile("../test/certs/ca.pem") + caCert, err := os.ReadFile("../test/certs/ca.pem") if err != nil { t.Fatalf("Got error reading RootCA file: %s", err) } @@ -1494,7 +1495,7 @@ func TestMonitorNoPanicOnServerRestart(t *testing.T) { if err != nil { continue } - ioutil.ReadAll(resp.Body) + io.ReadAll(resp.Body) resp.Body.Close() select { case <-done: diff --git a/server/server_run_test.go b/server/server_run_test.go index 4c942076..0b73527d 100644 --- a/server/server_run_test.go +++ b/server/server_run_test.go @@ -17,7 +17,6 @@ import ( "crypto/tls" "flag" "fmt" - "io/ioutil" "os" "reflect" "runtime" @@ -1283,12 +1282,12 @@ func TestStreamingServerReadyLog(t *testing.T) { } func TestReopenLogFileStopsNATSDebugTrace(t *testing.T) { - tmpDir, err := ioutil.TempDir("", "nats-streaming-server") + tmpDir, err := os.MkdirTemp("", "nats-streaming-server") if err != nil { t.Fatal("Could not create tmp dir") } defer os.RemoveAll(tmpDir) - file, err := ioutil.TempFile(tmpDir, "log_") + file, err := os.CreateTemp(tmpDir, "log_") if err != nil { t.Fatalf("Could not create the temp file: %v", err) } @@ -1311,7 +1310,7 @@ func TestReopenLogFileStopsNATSDebugTrace(t *testing.T) { check := func(str string, expected bool) { t.Helper() - buf, err := ioutil.ReadFile(nOpts.LogFile) + buf, err := os.ReadFile(nOpts.LogFile) if err != nil { t.Fatalf("Error reading file: %v", err) } @@ -1352,7 +1351,7 @@ func TestReopenLogFileStopsNATSDebugTrace(t *testing.T) { s.log.Noticef(pstr) } // Check that size limit has been applied. - files, err := ioutil.ReadDir(tmpDir) + files, err := os.ReadDir(tmpDir) if err != nil { t.Fatalf("Error reading directory: %v", err) } diff --git a/server/server_test.go b/server/server_test.go index 299f4a04..734547de 100644 --- a/server/server_test.go +++ b/server/server_test.go @@ -17,7 +17,6 @@ import ( "errors" "flag" "fmt" - "io/ioutil" "os" "reflect" "regexp" @@ -162,7 +161,7 @@ func TestMain(m *testing.M) { } func init() { - tmpDir, err := ioutil.TempDir(".", "data_server_") + tmpDir, err := os.MkdirTemp(".", "data_server_") if err != nil { panic("Could not create tmp dir") } @@ -409,13 +408,13 @@ func createConnectionWithNatsOpts(t tLogger, clientName string, func createConfFile(t *testing.T, content []byte) string { t.Helper() - conf, err := ioutil.TempFile("", "") + conf, err := os.CreateTemp("", "") if err != nil { t.Fatalf("Error creating conf file: %v", err) } fName := conf.Name() conf.Close() - if err := ioutil.WriteFile(fName, content, 0666); err != nil { + if err := os.WriteFile(fName, content, 0666); err != nil { os.Remove(fName) t.Fatalf("Error writing conf file: %v", err) } @@ -424,7 +423,7 @@ func createConfFile(t *testing.T, content []byte) string { func changeCurrentConfigContentWithNewContent(t *testing.T, curConfig string, content []byte) { t.Helper() - if err := ioutil.WriteFile(curConfig, content, 0666); err != nil { + if err := os.WriteFile(curConfig, content, 0666); err != nil { t.Fatalf("Error writing config: %v", err) } } diff --git a/server/signal_test.go b/server/signal_test.go index af7e9f93..026dc206 100644 --- a/server/signal_test.go +++ b/server/signal_test.go @@ -19,7 +19,6 @@ package server import ( "bytes" "fmt" - "io/ioutil" "os" "os/exec" "strings" @@ -77,7 +76,7 @@ func TestSignalToReOpenLogFile(t *testing.T) { // Add a trace expectedStr := "This is a Notice" s.log.Noticef(expectedStr) - buf, err := ioutil.ReadFile(logFile) + buf, err := os.ReadFile(logFile) if err != nil { t.Fatalf("Error reading file: %v", err) } @@ -92,7 +91,7 @@ func TestSignalToReOpenLogFile(t *testing.T) { syscall.Kill(syscall.Getpid(), syscall.SIGUSR1) // Wait a bit for action to be performed waitFor(t, 2*time.Second, 15*time.Millisecond, func() error { - buf, err = ioutil.ReadFile(logFile) + buf, err = os.ReadFile(logFile) if err != nil { return fmt.Errorf("Error reading file: %v", err) } @@ -105,7 +104,7 @@ func TestSignalToReOpenLogFile(t *testing.T) { // Make sure that new traces are added expectedStr = "This is a new notice" s.log.Noticef(expectedStr) - buf, err = ioutil.ReadFile(logFile) + buf, err = os.ReadFile(logFile) if err != nil { t.Fatalf("Error reading file: %v", err) } @@ -208,7 +207,7 @@ func TestNATSServerConfigReloadFollowedByReopen(t *testing.T) { cmd.Start() // Wait for it to print some startup trace waitFor(t, 2*time.Second, 50*time.Millisecond, func() error { - content, err := ioutil.ReadFile(lfile) + content, err := os.ReadFile(lfile) if err != nil { return err } @@ -230,7 +229,7 @@ func TestNATSServerConfigReloadFollowedByReopen(t *testing.T) { c.Close() syscall.Kill(cmd.Process.Pid, syscall.SIGINT) cmd.Wait() - content, err := ioutil.ReadFile(lfile) + content, err := os.ReadFile(lfile) if err != nil { t.Fatalf("Error reading log file: %v", err) } diff --git a/stores/cryptostore_test.go b/stores/cryptostore_test.go index 08f18576..9ef9bdd1 100644 --- a/stores/cryptostore_test.go +++ b/stores/cryptostore_test.go @@ -16,7 +16,6 @@ package stores import ( "bytes" "fmt" - "io/ioutil" "os" "reflect" "strings" @@ -240,7 +239,7 @@ func TestCryptoStoreUseEnvKey(t *testing.T) { cs.Close() - datContent, err := ioutil.ReadFile(datFile) + datContent, err := os.ReadFile(datFile) if err != nil { t.Fatalf("Error reading file: %v", err) } @@ -399,7 +398,7 @@ func TestCryptoStoreCheckEncryptedStore(t *testing.T) { s.Close() - datContent, err := ioutil.ReadFile(datFile) + datContent, err := os.ReadFile(datFile) if err != nil { t.Fatalf("Error reading file: %v", err) } @@ -411,7 +410,7 @@ func TestCryptoStoreCheckEncryptedStore(t *testing.T) { } // Only message store is encrypted, so subscription file // should be in plain text. - subContent, err := ioutil.ReadFile(subFile) + subContent, err := os.ReadFile(subFile) if err != nil { t.Fatalf("Error reading file: %v", err) } diff --git a/stores/filestore.go b/stores/filestore.go index 8c0f87e4..6c018618 100644 --- a/stores/filestore.go +++ b/stores/filestore.go @@ -19,7 +19,6 @@ import ( "fmt" "hash/crc32" "io" - "io/ioutil" "os" "os/exec" "path/filepath" @@ -740,8 +739,10 @@ func checkFileVersion(r io.Reader) error { // writeRecord writes a record to `w`. // The record layout is as follows: -// 8 bytes: 4 bytes for type and/or size combined -// 4 bytes for CRC-32 +// 8 bytes: +// - 4 bytes for type and/or size combined +// - 4 bytes for CRC-32 +// // variable bytes: payload. // If a buffer is provided, this function uses it and expands it if necessary. // The function returns the buffer (possibly changed due to expansion) and the @@ -793,7 +794,7 @@ func writeRecord(w io.Writer, buf []byte, recType recordType, rec record, recSiz } // readRecord reads a record from `r`, possibly checking the CRC-32 checksum. -// When `buf`` is not nil, this function ensures the buffer is big enough to +// When `buf` is not nil, this function ensures the buffer is big enough to // hold the payload (expanding if necessary). Therefore, this call always // return `buf`, regardless if there is an error or not. // The caller is indicating if the record is supposed to be typed or not. @@ -1443,7 +1444,7 @@ func (fs *FileStore) Recover() (*RecoveredState, error) { } func (fs *FileStore) getChannelsDir() ([]os.FileInfo, error) { - files, err := ioutil.ReadDir(fs.fm.rootDir) + files, err := os.ReadDir(fs.fm.rootDir) if err != nil { return nil, err } @@ -1452,7 +1453,11 @@ func (fs *FileStore) getChannelsDir() ([]os.FileInfo, error) { if !f.IsDir() { continue } - channels = append(channels, f) + finfo, err := f.Info() + if err != nil { + return nil, err + } + channels = append(channels, finfo) } return channels, nil } @@ -1872,7 +1877,7 @@ func (fs *FileStore) compactClientFile(orgFileName string) error { // Return a temporary file (including file version) func getTempFile(rootDir, prefix string) (*os.File, error) { - tmpFile, err := ioutil.TempFile(rootDir, prefix) + tmpFile, err := os.CreateTemp(rootDir, prefix) if err != nil { return nil, err } @@ -2048,16 +2053,21 @@ func (fs *FileStore) newFileMsgStore(channelDirName, channel string, limits *Msg // Recovery case if doRecover { - var dirFiles []os.FileInfo + var dirEntries []os.DirEntry var fseq int64 var datFile, idxFile *file var useIdxFile bool - dirFiles, err = ioutil.ReadDir(channelDirName) - for _, file := range dirFiles { - if file.IsDir() { + dirEntries, err = os.ReadDir(channelDirName) + for _, entry := range dirEntries { + if entry.IsDir() { continue } + file, ierr := entry.Info() + if ierr != nil { + err = ierr + break + } fileName := file.Name() if !strings.HasPrefix(fileName, msgFilesPrefix) || !strings.HasSuffix(fileName, datSuffix) { continue diff --git a/stores/filestore_msg_test.go b/stores/filestore_msg_test.go index 592cf68c..82afc103 100644 --- a/stores/filestore_msg_test.go +++ b/stores/filestore_msg_test.go @@ -16,7 +16,6 @@ package stores import ( "fmt" "hash/crc32" - "io/ioutil" "os" "path/filepath" "reflect" @@ -83,11 +82,11 @@ func TestFSBadMsgFile(t *testing.T) { // Corrupt data file. Index's last message will not match // data file, so idx file will be removed and recovery from // data file will be done, which should report failure. - datContent, err := ioutil.ReadFile(firstSliceFileName) + datContent, err := os.ReadFile(firstSliceFileName) if err != nil { t.Fatalf("Error reading %v: %v", firstSliceFileName, err) } - if err := ioutil.WriteFile(firstSliceFileName, datContent[:len(datContent)-5], 0666); err != nil { + if err := os.WriteFile(firstSliceFileName, datContent[:len(datContent)-5], 0666); err != nil { t.Fatalf("Error writing file %v: %v", firstSliceFileName, err) } // So we should fail to create the filestore @@ -778,7 +777,7 @@ func TestFSArchiveScript(t *testing.T) { cleanupFSDatastore(t) defer cleanupFSDatastore(t) - tmpDir, err := ioutil.TempDir(".", "") + tmpDir, err := os.MkdirTemp(".", "") if err != nil { t.Fatalf("Unable to create temp dir: %v", err) } @@ -797,7 +796,7 @@ func TestFSArchiveScript(t *testing.T) { scriptFile = fmt.Sprintf("%s/script_%v.sh", pwd, time.Now().UnixNano()) content = fmt.Sprintf("#!/bin/bash\nmkdir -p %s/%s/$1\nmv $2 $3 %s/%s/$1\n", pwd, tmpDir, pwd, tmpDir) } - if err := ioutil.WriteFile(scriptFile, []byte(content), 0777); err != nil { + if err := os.WriteFile(scriptFile, []byte(content), 0777); err != nil { t.Fatalf("Error creating script: %v", err) } defer os.Remove(scriptFile) @@ -857,7 +856,7 @@ func TestFSArchiveScript(t *testing.T) { // Create a script that will error out os.Remove(scriptFile) content = "xxx" - if err := ioutil.WriteFile(scriptFile, []byte(content), 0777); err != nil { + if err := os.WriteFile(scriptFile, []byte(content), 0777); err != nil { t.Fatalf("Error creating script: %v", err) } defer os.Remove(scriptFile) @@ -1347,7 +1346,7 @@ func TestFSPanicOnMsgExpireWithClosedDatFile(t *testing.T) { ms.Lock() idxFileName := ms.files[1].idxFile.name os.Remove(idxFileName) - err := ioutil.WriteFile(idxFileName, []byte("xxxxxxx"), 0666) + err := os.WriteFile(idxFileName, []byte("xxxxxxx"), 0666) ms.Unlock() if err != nil { t.Fatalf("Error rewriting index file: %v", err) @@ -1698,11 +1697,11 @@ func TestFSExpirationWithTruncatedNonLastSlice(t *testing.T) { s.Close() - datContent, err := ioutil.ReadFile(fname) + datContent, err := os.ReadFile(fname) if err != nil { t.Fatalf("Error reading %v: %v", fname, err) } - if err := ioutil.WriteFile(fname, datContent[:len(datContent)-5], 0666); err != nil { + if err := os.WriteFile(fname, datContent[:len(datContent)-5], 0666); err != nil { t.Fatalf("Error writing file %v: %v", fname, err) } @@ -1929,12 +1928,12 @@ func TestFSNoPanicOnRemoveMsg(t *testing.T) { ms.Lock() idxFile := ms.files[1].idxFile ms.fm.closeLockedOrOpenedFile(idxFile) - content, err := ioutil.ReadFile(idxFile.name) + content, err := os.ReadFile(idxFile.name) if err != nil { t.Fatalf("Error reading file: %v", err) } copy(content[4:], []byte("xxx")) - if err := ioutil.WriteFile(idxFile.name, content, 0600); err != nil { + if err := os.WriteFile(idxFile.name, content, 0600); err != nil { t.Fatalf("Error writing file: %v", err) } ms.Unlock() @@ -2331,12 +2330,12 @@ func TestFSExpirationError(t *testing.T) { ms.Lock() idxFile := ms.files[1].idxFile ms.fm.closeLockedOrOpenedFile(idxFile) - content, err := ioutil.ReadFile(idxFile.name) + content, err := os.ReadFile(idxFile.name) if err != nil { t.Fatalf("Error reading file: %v", err) } copy(content[4:], []byte("xxx")) - if err := ioutil.WriteFile(idxFile.name, content, 0600); err != nil { + if err := os.WriteFile(idxFile.name, content, 0600); err != nil { t.Fatalf("Error writing file: %v", err) } ms.Unlock() @@ -2385,7 +2384,7 @@ func TestFSMsgsFileVersionError(t *testing.T) { s.Close() os.Remove(fname) - if err := ioutil.WriteFile(fname, []byte(""), 0666); err != nil { + if err := os.WriteFile(fname, []byte(""), 0666); err != nil { t.Fatalf("Error writing file: %v", err) } diff --git a/stores/filestore_sub_test.go b/stores/filestore_sub_test.go index 44fe5154..08babba6 100644 --- a/stores/filestore_sub_test.go +++ b/stores/filestore_sub_test.go @@ -15,7 +15,6 @@ package stores import ( "hash/crc32" - "io/ioutil" "os" "path/filepath" "reflect" @@ -911,7 +910,7 @@ func TestFSSubscriptionsFileVersionError(t *testing.T) { s.Close() os.Remove(fname) - if err := ioutil.WriteFile(fname, []byte(""), 0666); err != nil { + if err := os.WriteFile(fname, []byte(""), 0666); err != nil { t.Fatalf("Error writing file: %v", err) } diff --git a/stores/filestore_test.go b/stores/filestore_test.go index 3a4ba01a..7fc2f2c8 100644 --- a/stores/filestore_test.go +++ b/stores/filestore_test.go @@ -18,7 +18,6 @@ import ( "fmt" "hash/crc32" "io" - "io/ioutil" "math/rand" "os" "path" @@ -46,7 +45,7 @@ var ( var testFDsLimit = int64(5) func init() { - tmpDir, err := ioutil.TempDir(".", "data_stores_") + tmpDir, err := os.MkdirTemp(".", "data_stores_") if err != nil { panic("Could not create tmp dir") } @@ -1774,8 +1773,8 @@ func TestFSParallelRecovery(t *testing.T) { numRoutines := runtime.NumGoroutine() // Make several channels fail to recover fname := fmt.Sprintf("%s.1.%s", msgFilesPrefix, datSuffix) - ioutil.WriteFile(filepath.Join(testFSDefaultDatastore, "foo.50", fname), []byte("dummy"), 0666) - ioutil.WriteFile(filepath.Join(testFSDefaultDatastore, "foo.51", fname), []byte("dummy"), 0666) + os.WriteFile(filepath.Join(testFSDefaultDatastore, "foo.50", fname), []byte("dummy"), 0666) + os.WriteFile(filepath.Join(testFSDefaultDatastore, "foo.51", fname), []byte("dummy"), 0666) s, err := NewFileStore(testLogger, testFSDefaultDatastore, &testDefaultStoreLimits, ParallelRecovery(10)) if err == nil { _, err = s.Recover() @@ -2089,7 +2088,7 @@ func TestFSServerAndClientFilesVersionError(t *testing.T) { s.Close() os.Remove(fname) - if err := ioutil.WriteFile(fname, []byte(""), 0666); err != nil { + if err := os.WriteFile(fname, []byte(""), 0666); err != nil { t.Fatalf("Error creating file: %v", err) } diff --git a/stores/raftstore_test.go b/stores/raftstore_test.go index 5d1be27e..2a1c6cfb 100644 --- a/stores/raftstore_test.go +++ b/stores/raftstore_test.go @@ -15,7 +15,6 @@ package stores import ( "fmt" - "io/ioutil" "os" "reflect" "testing" @@ -27,7 +26,7 @@ import ( var testRSDefaultDatastore string func init() { - tmpDir, err := ioutil.TempDir(".", "raft_data_stores_") + tmpDir, err := os.MkdirTemp(".", "raft_data_stores_") if err != nil { panic("Could not create tmp dir") } diff --git a/stores/store.go b/stores/store.go index 1c8ee231..4d02b46a 100644 --- a/stores/store.go +++ b/stores/store.go @@ -143,7 +143,6 @@ type Channel struct { // If an implementation has a Store constructor with StoreLimits, it should be // noted that the limits don't apply to any state being recovered, for Store // implementations supporting recovery. -// type Store interface { // GetExclusiveLock is an advisory lock to prevent concurrent // access to the store from multiple instances.