MCPcopy Create free account
hub / github.com/CPChain/chain / deletePattern

Function deletePattern

cmd/cpchain/cmd_chain.go:455–487  ·  view source on GitHub ↗
(ctx *cli.Context)

Source from the content-addressed store, hash-verified

453}
454
455func deletePattern(ctx *cli.Context) (err error) {
456 if len(ctx.Args()) != 1 {
457 log.Fatal("This command requires argument <delete-key-substring>.")
458 }
459
460 cfg, stack := newConfigNode(ctx)
461 _, chainDb := commons.OpenChain(ctx, stack, &cfg.Cpc)
462 defer chainDb.Close()
463
464 if db, ok := chainDb.(*database.LDBDatabase); ok {
465 iter := db.LDB().NewIterator(nil, nil)
466
467 log.Warn("This requires a few minutes to finish, please do not interrupt!")
468
469 for iter.Next() {
470 key := iter.Key()
471
472 // if matches, delete
473 if bytes.Contains(key, []byte(ctx.Args()[0])) {
474 err = db.Delete(key)
475 if err != nil {
476 log.Error("Error occurs when deleting key", "key", key)
477 }
478 }
479 }
480 iter.Release()
481 err = iter.Error()
482
483 log.Warn("Finished deleting!")
484 }
485
486 return err
487}
488
489// hashish returns true for strings that look like hashes.
490func hashish(x string) bool {

Callers

nothing calls this directly

Calls 10

newConfigNodeFunction · 0.85
NewIteratorMethod · 0.80
LDBMethod · 0.80
FatalMethod · 0.65
CloseMethod · 0.65
WarnMethod · 0.65
ContainsMethod · 0.65
DeleteMethod · 0.65
ErrorMethod · 0.65
NextMethod · 0.45

Tested by

no test coverage detected