From 292c71b47182070ee05161eccd4f68b3326f2eed Mon Sep 17 00:00:00 2001 From: Roy Crihfield Date: Wed, 3 Jul 2024 18:17:55 +0800 Subject: [PATCH] clean up copy --- chains/chaindata.go | 22 +++++++--------------- 1 file changed, 7 insertions(+), 15 deletions(-) diff --git a/chains/chaindata.go b/chains/chaindata.go index 592cf4f..e83cb65 100644 --- a/chains/chaindata.go +++ b/chains/chaindata.go @@ -2,6 +2,7 @@ package chains import ( "errors" + "fmt" "io" "os" "path/filepath" @@ -70,22 +71,16 @@ func copyDir(src, dest string) error { return err } - srcDir, err := os.Open(src) - if err != nil { - return err - } - defer srcDir.Close() - - fileInfos, err := srcDir.Readdir(-1) + entries, err := os.ReadDir(src) if err != nil { return err } - for _, fileInfo := range fileInfos { - srcPath := filepath.Join(src, fileInfo.Name()) - destPath := filepath.Join(dest, fileInfo.Name()) + for _, entry := range entries { + srcPath := filepath.Join(src, entry.Name()) + destPath := filepath.Join(dest, entry.Name()) - if fileInfo.IsDir() { + if entry.IsDir() { if err := copyDir(srcPath, destPath); err != nil { return err } @@ -112,8 +107,5 @@ func copyFile(src, dest string) error { defer destFile.Close() _, err = io.Copy(destFile, srcFile) - if err != nil { - return err - } - return nil + return err }