From 2c3a89339d50929bb1476aa9949a8fec7709c29c Mon Sep 17 00:00:00 2001 From: Aliaksandr Valialkin Date: Mon, 22 Aug 2022 00:02:19 +0300 Subject: [PATCH] all: use os.ReadDir instead of ioutil.ReadDir The ioutil.ReadDir is deprecated since Go1.16 - see https://tip.golang.org/doc/go1.16#ioutil VictoriaMetrics requires at least Go1.18, so it is time to switch from io.ReadDir to os.ReadDir This is a follow-up for 02ca2342ab01627eb5fdbb3174792b86fc1de7a9 --- lib/fs/fs.go | 10 +++++----- lib/persistentqueue/persistentqueue.go | 9 ++++----- 2 files changed, 9 insertions(+), 10 deletions(-) diff --git a/lib/fs/fs.go b/lib/fs/fs.go index 8dd6d008b..c638028a2 100644 --- a/lib/fs/fs.go +++ b/lib/fs/fs.go @@ -269,20 +269,20 @@ func SymlinkRelative(srcPath, dstPath string) error { // CopyDirectory copies all the files in srcPath to dstPath. func CopyDirectory(srcPath, dstPath string) error { - fis, err := ioutil.ReadDir(srcPath) + des, err := os.ReadDir(srcPath) if err != nil { return err } if err := MkdirAllIfNotExist(dstPath); err != nil { return err } - for _, fi := range fis { - if !fi.Mode().IsRegular() { + for _, de := range des { + if !de.Type().IsRegular() { // Skip non-files continue } - src := filepath.Join(srcPath, fi.Name()) - dst := filepath.Join(dstPath, fi.Name()) + src := filepath.Join(srcPath, de.Name()) + dst := filepath.Join(dstPath, de.Name()) if err := copyFile(src, dst); err != nil { return err } diff --git a/lib/persistentqueue/persistentqueue.go b/lib/persistentqueue/persistentqueue.go index 6351b49aa..31a17f171 100644 --- a/lib/persistentqueue/persistentqueue.go +++ b/lib/persistentqueue/persistentqueue.go @@ -4,7 +4,6 @@ import ( "encoding/json" "fmt" "io" - "io/ioutil" "os" "regexp" "strconv" @@ -221,14 +220,14 @@ func tryOpeningQueue(path, name string, chunkFileSize, maxBlockSize, maxPendingB } // Locate reader and writer chunks in the path. - fis, err := ioutil.ReadDir(path) + des, err := os.ReadDir(path) if err != nil { return nil, fmt.Errorf("cannot read contents of the directory %q: %w", path, err) } - for _, fi := range fis { - fname := fi.Name() + for _, de := range des { + fname := de.Name() filepath := path + "/" + fname - if fi.IsDir() { + if de.IsDir() { logger.Errorf("skipping unknown directory %q", filepath) continue }