Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Corrected bug introduced in init modernization #4

Merged
merged 1 commit into from
Nov 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 17 additions & 13 deletions io/io.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -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
Expand All @@ -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
}
}
}
Expand Down
5 changes: 2 additions & 3 deletions util/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand All @@ -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
}

Expand Down