Skip to content

Commit

Permalink
Corrected bug introduced in init modernization
Browse files Browse the repository at this point in the history
  • Loading branch information
retr0h committed Nov 10, 2023
1 parent 761db58 commit e3588d0
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 16 deletions.
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

0 comments on commit e3588d0

Please sign in to comment.