| 227 | } |
| 228 | |
| 229 | func runCheck(ctx context.Context, opts CheckOptions, gopts global.Options, args []string, term ui.Terminal) (checkSummary, error) { |
| 230 | summary := checkSummary{MessageType: "summary"} |
| 231 | |
| 232 | var printer progress.Printer |
| 233 | if !gopts.JSON { |
| 234 | printer = ui.NewProgressPrinter(gopts.JSON, gopts.Verbosity, term) |
| 235 | } else { |
| 236 | printer = newJSONErrorPrinter(term) |
| 237 | } |
| 238 | |
| 239 | cleanup := prepareCheckCache(opts, &gopts, printer) |
| 240 | defer cleanup() |
| 241 | |
| 242 | if !gopts.NoLock { |
| 243 | printer.P("create exclusive lock for repository\n") |
| 244 | } |
| 245 | ctx, repo, unlock, err := openWithExclusiveLock(ctx, gopts, gopts.NoLock, printer) |
| 246 | if err != nil { |
| 247 | return summary, err |
| 248 | } |
| 249 | defer unlock() |
| 250 | |
| 251 | chkr := checker.New(repo, opts.CheckUnused) |
| 252 | err = chkr.LoadSnapshots(ctx, &opts.SnapshotFilter, args) |
| 253 | if err != nil { |
| 254 | return summary, err |
| 255 | } |
| 256 | |
| 257 | printer.P("load indexes\n") |
| 258 | hints, errs := chkr.LoadIndex(ctx, printer) |
| 259 | if ctx.Err() != nil { |
| 260 | return summary, ctx.Err() |
| 261 | } |
| 262 | |
| 263 | errorsFound := false |
| 264 | salvagePacks := restic.NewIDSet() |
| 265 | |
| 266 | for _, hint := range hints { |
| 267 | switch hint := hint.(type) { |
| 268 | case *repository.ErrIncompletePackEntry: |
| 269 | printer.E("%s", hint.Error()) |
| 270 | salvagePacks.Insert(hint.PackID) |
| 271 | errorsFound = true |
| 272 | summary.NumErrors++ |
| 273 | case *repository.ErrDuplicatePacks: |
| 274 | printer.S("%s", hint.Error()) |
| 275 | summary.HintRepairIndex = true |
| 276 | case *repository.ErrMixedPack: |
| 277 | printer.S("%s", hint.Error()) |
| 278 | summary.HintPrune = true |
| 279 | default: |
| 280 | printer.E("error: %v\n", hint) |
| 281 | errorsFound = true |
| 282 | } |
| 283 | } |
| 284 | |
| 285 | if summary.HintRepairIndex { |
| 286 | printer.S("Duplicate packs are non-critical, you can run `restic repair index' to correct this.\n") |