MCPcopy
hub / github.com/restic/restic / runCheck

Function runCheck

cmd/restic/cmd_check.go:229–429  ·  view source on GitHub ↗
(ctx context.Context, opts CheckOptions, gopts global.Options, args []string, term ui.Terminal)

Source from the content-addressed store, hash-verified

227}
228
229func 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")

Callers 7

newCheckCommandFunction · 0.85
applyMigrationsFunction · 0.85
testPruneFunction · 0.85
testEdgeCaseRepoFunction · 0.85
TestListOnceFunction · 0.85
testRunCheckOutputFunction · 0.85

Calls 15

PMethod · 0.95
EMethod · 0.95
InsertMethod · 0.95
SMethod · 0.95
VMethod · 0.95
DoneMethod · 0.95
NewCounterMethod · 0.95
NewProgressPrinterFunction · 0.92
NewFunction · 0.92
NewIDSetFunction · 0.92
FatalFunction · 0.92
AsFunction · 0.92

Tested by 5

testPruneFunction · 0.68
testEdgeCaseRepoFunction · 0.68
TestListOnceFunction · 0.68
testRunCheckOutputFunction · 0.68