MCPcopy
hub / github.com/kopia/kopia / outputJSON

Method outputJSON

cli/command_snapshot_list.go:151–185  ·  view source on GitHub ↗
(ctx context.Context, rep repo.Repository, manifests []*snapshot.Manifest)

Source from the content-addressed store, hash-verified

149}
150
151func (c *commandSnapshotList) outputJSON(ctx context.Context, rep repo.Repository, manifests []*snapshot.Manifest) error {
152 var jl jsonList
153
154 jl.begin(&c.jo)
155 defer jl.end()
156
157 for _, snapshotGroup := range snapshot.GroupBySource(manifests) {
158 snapshotGroup = snapshot.SortByTime(snapshotGroup, c.reverseSort)
159
160 if c.maxResultsPerPath > 0 && len(snapshotGroup) > c.maxResultsPerPath {
161 snapshotGroup = snapshotGroup[len(snapshotGroup)-c.maxResultsPerPath:]
162 }
163
164 if c.snapshotListShowRetentionReasons {
165 src := snapshotGroup[0].Source
166 // compute retention reason
167 pol, _, _, err := policy.GetEffectivePolicy(ctx, rep, src)
168 if err != nil {
169 log(ctx).Errorf("unable to determine effective policy for %v", src)
170 } else {
171 pol.RetentionPolicy.ComputeRetentionReasons(snapshotGroup)
172 }
173 }
174
175 if err := c.iterateSnapshotsMaybeWithStorageStats(ctx, rep, snapshotGroup, func(m *snapshot.Manifest) error {
176 wm := SnapshotManifest{Manifest: m, RetentionReasons: m.RetentionReasons}
177 jl.emit(wm)
178 return nil
179 }); err != nil {
180 return errors.Wrap(err, "unable to iterate snapshots")
181 }
182 }
183
184 return nil
185}
186
187func (c *commandSnapshotList) shouldOutputSnapshotSource(rep repo.Repository, src snapshot.SourceInfo) bool {
188 if c.snapshotListShowAll {

Callers 1

runMethod · 0.95

Calls 9

beginMethod · 0.95
endMethod · 0.95
emitMethod · 0.95
GroupBySourceFunction · 0.92
SortByTimeFunction · 0.92
GetEffectivePolicyFunction · 0.92
ErrorfMethod · 0.80

Tested by

no test coverage detected