From e3588d05a6901810b62c07f7a37b4b4f8e8e5ff2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D7=A0=CF=85=CE=B1=CE=B7=20=D7=A0=CF=85=CE=B1=CE=B7=D1=95?= =?UTF-8?q?=CF=83=CE=B7?= Date: Fri, 10 Nov 2023 13:42:55 -0800 Subject: [PATCH] Corrected bug introduced in init modernization --- io/io.go | 30 +++++++++++++++++------------- util/util.go | 5 ++--- 2 files changed, 19 insertions(+), 16 deletions(-) diff --git a/io/io.go b/io/io.go index e137915..5782955 100644 --- a/io/io.go +++ b/io/io.go @@ -33,12 +33,12 @@ import ( // From: https://gist.github.com/m4ng0squ4sh/92462b38df26839a3ca324697c8cba04 -// File copies the contents of the file named src to the file named +// CopyFile copies the contents of the file named src to the file named // by dst. The file will be created if it does not already exist. If the // destination file exists, all it's contents will be replaced by the contents // of the source file. The file mode will be copied from the source and // the copied data is synced/flushed to stable storage. -func File(src, dst string) (err error) { +func CopyFile(src, dst string) (err error) { in, err := os.Open(src) if err != nil { return @@ -77,10 +77,10 @@ func File(src, dst string) (err error) { return } -// Dir recursively copies a directory tree, attempting to preserve permissions. +// CopyDir recursively copies a directory tree, attempting to preserve permissions. // Source directory must exist, destination directory must *not* exist. // Symlinks are ignored and skipped. -func Dir(src string, dst string) (err error) { +func CopyDir(src string, dst string) (err error) { src = filepath.Clean(src) dst = filepath.Clean(dst) @@ -110,13 +110,17 @@ func Dir(src string, dst string) (err error) { return } - var fileInfo os.FileInfo for _, entry := range entries { - srcPath := filepath.Join(src, entry.Name()) - dstPath := filepath.Join(dst, entry.Name()) + fileInfo, err := entry.Info() + if err != nil { + return err + } + fmt.Println(fileInfo) + srcPath := filepath.Join(src, fileInfo.Name()) + dstPath := filepath.Join(dst, fileInfo.Name()) - // If the entry is a symlink, we copy the contents - if entry.Type()&os.ModeSymlink != 0 { + // If a symlink, we copy the contents + if fileInfo.Mode()&os.ModeSymlink != 0 { target, err := filepath.EvalSymlinks(srcPath) if err != nil { return err @@ -129,14 +133,14 @@ func Dir(src string, dst string) (err error) { } if fileInfo.IsDir() { - err = Dir(srcPath, dstPath) + err = CopyDir(srcPath, dstPath) if err != nil { - return + return err } } else { - err = File(srcPath, dstPath) + err = CopyFile(srcPath, dstPath) if err != nil { - return + return err } } } diff --git a/util/util.go b/util/util.go index 9ee7eb6..7d9523d 100644 --- a/util/util.go +++ b/util/util.go @@ -107,7 +107,7 @@ func CopyFile(src string, dst string) error { ) fmt.Println(msg) - if err := io.File(src, dst); err != nil { + if err := io.CopyFile(src, dst); err != nil { return err } @@ -125,8 +125,7 @@ func CopyDir(src string, dst string) error { ) fmt.Println(msg) - if err := io.Dir(src, dst); err != nil { - fmt.Println(err) + if err := io.CopyDir(src, dst); err != nil { return err }