Skip to content

Commit

Permalink
Linding rules and info.IsDir() PR comments
Browse files Browse the repository at this point in the history
Signed-off-by: David F D Reis <[email protected]>
  • Loading branch information
davidfdr committed Mar 26, 2024
1 parent 3494ea6 commit 24c0766
Showing 1 changed file with 8 additions and 11 deletions.
19 changes: 8 additions & 11 deletions internal/util/copy.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,28 +66,25 @@ func CopyIndexFiles(logger *log.CmdLogger, src, dest string) error {
}

opt := copy.Options{
Skip: func(_ os.FileInfo, src, _ string) (bool, error) {
Skip: func(info os.FileInfo, src, _ string) (bool, error) {
logger.Debugf("Checking source copy path: %s", src)
fileInfo, err := os.Lstat(src)

if err != nil {
return true, fmt.Errorf(
"failed to create CouchDB index definitions from folder %s: %w",
src,
err,
)
}
if fileInfo.IsDir() { // copy it recursively

if info.IsDir() {
logger.Debugf("This is a folder, copying: %s", src)

return false, nil
} else { // any non JSON will be skipped
isJsonFile := strings.HasSuffix(src, ".json")
if isJsonFile {
logger.Debugf("This is a JSON file, copying: %s", src)
} else {
logger.Debugf("This is NOT a JSON file, skipping copy: %s", src)
}
return !isJsonFile, nil
}
logger.Debugf("Checking if it is a JSON file: %s", src)

return !strings.HasSuffix(src, ".json"), nil
},
}

Expand Down

0 comments on commit 24c0766

Please sign in to comment.