WalkFS traverses filesystem fs starting at name up to depth levels. WalkFS will stop when current depth > `depth`. For each visited node, WalkFS calls walkFn. If a visited file system node is a directory and walkFn returns path.SkipDir, walkFS will skip traversal of this node.
(ctx context.Context, depth int, name string, info model.Obj, walkFn func(reqPath string, info model.Obj) error)
| 16 | // WalkFS calls walkFn. If a visited file system node is a directory and |
| 17 | // walkFn returns path.SkipDir, walkFS will skip traversal of this node. |
| 18 | func WalkFS(ctx context.Context, depth int, name string, info model.Obj, walkFn func(reqPath string, info model.Obj) error) error { |
| 19 | // This implementation is based on Walk's code in the standard path/path package. |
| 20 | walkFnErr := walkFn(name, info) |
| 21 | if walkFnErr != nil { |
| 22 | if info.IsDir() && walkFnErr == filepath.SkipDir { |
| 23 | return nil |
| 24 | } |
| 25 | return walkFnErr |
| 26 | } |
| 27 | if !info.IsDir() || depth == 0 { |
| 28 | return nil |
| 29 | } |
| 30 | meta, _ := op.GetNearestMeta(name) |
| 31 | // Read directory names. |
| 32 | objs, err := List(context.WithValue(ctx, conf.MetaKey, meta), name, &ListArgs{}) |
| 33 | if err != nil { |
| 34 | return walkFnErr |
| 35 | } |
| 36 | for _, fileInfo := range objs { |
| 37 | filename := path.Join(name, fileInfo.GetName()) |
| 38 | if err := WalkFS(ctx, depth-1, filename, fileInfo, walkFn); err != nil { |
| 39 | if err == filepath.SkipDir { |
| 40 | break |
| 41 | } |
| 42 | return err |
| 43 | } |
| 44 | } |
| 45 | return nil |
| 46 | } |
no test coverage detected