Skip to content

Commit

Permalink
refactor isMaxDepth for readability
Browse files Browse the repository at this point in the history
  • Loading branch information
ayoisaiah committed Sep 3, 2024
1 parent 560fe30 commit 8ca4293
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions find/find.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,21 +79,21 @@ func skipFileIfHidden(

// isMaxDepth reports whether the configured max depth has been reached.
func isMaxDepth(rootPath, currentPath string, maxDepth int) bool {
if rootPath == filepath.Dir(currentPath) {
if rootPath == filepath.Dir(currentPath) || maxDepth == 0 {
return false
}

if maxDepth == -1 {
return true
}

p := strings.Replace(currentPath, rootPath+string(os.PathSeparator), "", 1)

if strings.Count(p, string(os.PathSeparator)) > maxDepth && maxDepth != 0 {
return true
}
relativePath := strings.TrimPrefix(
currentPath,
rootPath+string(os.PathSeparator),
)
depthCount := strings.Count(relativePath, string(os.PathSeparator))

return false
return depthCount > maxDepth
}

func createFileChange(dirPath string, fileInfo fs.FileInfo) *file.Change {
Expand Down

0 comments on commit 8ca4293

Please sign in to comment.