MCPcopy
hub / github.com/kopia/kopia / IterateContents

Method IterateContents

repo/content/content_manager_iterate.go:109–156  ·  view source on GitHub ↗

IterateContents invokes the provided callback for each content starting with a specified prefix and possibly including deleted items.

(ctx context.Context, opts IterateOptions, callback IterateCallback)

Source from the content-addressed store, hash-verified

107// IterateContents invokes the provided callback for each content starting with a specified prefix
108// and possibly including deleted items.
109func (bm *WriteManager) IterateContents(ctx context.Context, opts IterateOptions, callback IterateCallback) error {
110 if opts.Range == (IDRange{}) {
111 // range not specified - default to AllIDs
112 opts.Range = index.AllIDs
113 }
114
115 callback, cleanup := maybeParallelExecutor(opts.Parallel, callback)
116 defer cleanup() //nolint:errcheck
117
118 uncommitted := bm.snapshotUncommittedItems(ctx)
119
120 invokeCallback := func(i Info) error {
121 if !opts.IncludeDeleted {
122 if ci, ok := uncommitted[i.ContentID]; ok {
123 if ci.Deleted {
124 return nil
125 }
126 } else if i.Deleted {
127 return nil
128 }
129 }
130
131 if !opts.Range.Contains(i.ContentID) {
132 return nil
133 }
134
135 return callback(i)
136 }
137
138 if len(uncommitted) == 0 && opts.IncludeDeleted && opts.Range == index.AllIDs && opts.Parallel <= 1 {
139 // fast path, invoke callback directly
140 invokeCallback = callback
141 }
142
143 for _, bi := range uncommitted {
144 _ = invokeCallback(bi)
145 }
146
147 if err := bm.maybeRefreshIndexes(ctx); err != nil {
148 return err
149 }
150
151 if err := bm.committedContents.listContents(opts.Range, invokeCallback); err != nil {
152 return err
153 }
154
155 return cleanup()
156}
157
158// IteratePackOptions are the options used to iterate over packs.
159type IteratePackOptions struct {

Callers 1

IteratePacksMethod · 0.95

Calls 6

maybeRefreshIndexesMethod · 0.95
maybeParallelExecutorFunction · 0.85
callbackFuncType · 0.85
listContentsMethod · 0.80
ContainsMethod · 0.45

Tested by

no test coverage detected