A couple of fixes.

GetChildrenRecursively is no longer threaded so it's more consistent
Fixed GetFileAtPath, specifically when getting the root dir
This commit is contained in:
Caleb Gardner
2021-01-15 10:57:03 -06:00
parent 9cf92c4916
commit 4187598783
3 changed files with 32 additions and 35 deletions
+7 -14
View File
@@ -142,21 +142,14 @@ func (f *File) GetChildrenRecursively() (children []*File, err error) {
childFolders = append(childFolders, child)
}
}
foldChil := make(chan []*File)
errChan := make(chan error)
for _, folds := range childFolders {
go func(fil *File) {
childs, childsErr := fil.GetChildrenRecursively()
errChan <- childsErr
foldChil <- childs
}(folds)
}
for range childFolders {
err = <-errChan
var childs []*File
childs, err = folds.GetChildrenRecursively()
if err != nil {
fmt.Println(err)
return
}
children = append(children, <-foldChil...)
children = append(children, childs...)
}
return
}
@@ -173,11 +166,11 @@ func (f *File) Path() string {
//Returns nil if called on something other then a folder, OR if the path goes oustide the archive.
//Allows wildcards supported by path.Match (namely * and ?) and will return the FIRST file that matches.
func (f *File) GetFileAtPath(dirPath string) *File {
if dirPath == "" {
return f
}
dirPath = path.Clean(dirPath)
dirPath = strings.TrimPrefix(dirPath, "/")
if dirPath == "" || dirPath == "." {
return f
}
if dirPath != "." && !f.IsDir() {
return nil
}