IterateEntries reads the contents of a provided directory using ObjectID of a directory (if any) to cache the results. The given callback is invoked on each item in the directory.
(ctx context.Context, d fs.Directory, w EntryWrapper, callback func(context.Context, fs.Entry) error)
| 86 | // IterateEntries reads the contents of a provided directory using ObjectID of a directory (if any) to cache |
| 87 | // the results. The given callback is invoked on each item in the directory. |
| 88 | func (c *Cache) IterateEntries(ctx context.Context, d fs.Directory, w EntryWrapper, callback func(context.Context, fs.Entry) error) error { |
| 89 | if h, ok := d.(object.HasObjectID); ok { |
| 90 | cacheID := h.ObjectID().String() |
| 91 | |
| 92 | entries, err := c.getEntries( |
| 93 | ctx, |
| 94 | cacheID, |
| 95 | dirCacheExpiration, |
| 96 | func(innerCtx context.Context) ([]fs.Entry, error) { |
| 97 | return fs.GetAllEntries(innerCtx, d) |
| 98 | }, |
| 99 | w, |
| 100 | ) |
| 101 | if err != nil { |
| 102 | return err |
| 103 | } |
| 104 | |
| 105 | for _, e := range entries { |
| 106 | err = callback(ctx, e) |
| 107 | if err != nil { |
| 108 | return err |
| 109 | } |
| 110 | } |
| 111 | |
| 112 | return nil |
| 113 | } |
| 114 | |
| 115 | return fs.IterateEntries(ctx, d, callback) //nolint:wrapcheck |
| 116 | } |
| 117 | |
| 118 | func (c *Cache) getEntriesFromCacheLocked(ctx context.Context, id string) []fs.Entry { |
| 119 | if v, ok := c.data[id]; id != "" && ok { |
nothing calls this directly
no test coverage detected