(ctx context.Context, rep repo.Repository, manifests []*snapshot.Manifest)
| 149 | } |
| 150 | |
| 151 | func (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 | |
| 187 | func (c *commandSnapshotList) shouldOutputSnapshotSource(rep repo.Repository, src snapshot.SourceInfo) bool { |
| 188 | if c.snapshotListShowAll { |
no test coverage detected