250511.1 · 3d5486c8bf7e4791ef453e91f1fa993d21420b9d
fastwalk: add new DirEntry.Depth method
The new DirEntry Depth method returns the depth at which the entry was generated relative to the root being walked. This is useful for programs that wish to limit traversal depth.
reading declarations
Changes to dirent.go. All files
@@ -53,3 +53,21 @@ func StatDirEntry(path string, de fs.DirEntry) (fs.FileInfo, error) { } return os.Stat(path) }++// DirEntryDepth returns the depth at which entry de was generated relative+// to the root being walked or -1 if de does not have type [fastwalk.DirEntry].+//+// This is a helper function that saves the user from having to cast the+// [fs.DirEntry] argument to their walk function to a [fastwalk.DirEntry]+// and is equivalent to the below code:+//+// if d, _ := de.(DirEntry); d != nil {+// return d.Depth()+// }+// return -1+func DirEntryDepth(de fs.DirEntry) int {+ if d, _ := de.(DirEntry); d != nil {+ return d.Depth()+ }+ return -1+}