MCPcopy
hub / github.com/perkeep/perkeep / NewKeyValueMaybeWipe

Function NewKeyValueMaybeWipe

pkg/sorted/kv.go:255–272  ·  view source on GitHub ↗

NewKeyValueMaybeWipe calls NewKeyValue and wipes the KeyValue if, and only if, NewKeyValue has returned a NeedWipeError.

(cfg jsonconfig.Obj)

Source from the content-addressed store, hash-verified

253// NewKeyValueMaybeWipe calls NewKeyValue and wipes the KeyValue if, and only
254// if, NewKeyValue has returned a NeedWipeError.
255func NewKeyValueMaybeWipe(cfg jsonconfig.Obj) (KeyValue, error) {
256 kv, err := NewKeyValue(cfg)
257 if err == nil {
258 return kv, nil
259 }
260 if _, ok := err.(NeedWipeError); !ok {
261 return nil, err
262 }
263 wiper, ok := kv.(Wiper)
264 if !ok {
265 return nil, fmt.Errorf("storage type %T needs wiping because %v. But it doesn't support sorted.Wiper", err, kv)
266 }
267 we := err
268 if err := wiper.Wipe(); err != nil {
269 return nil, fmt.Errorf("sorted key/value type %T needed wiping because %v. But could not wipe: %v", kv, we, err)
270 }
271 return kv, nil
272}
273
274// Foreach runs fn for each key/value pair in kv. If fn returns an error,
275// that same error is returned from Foreach and iteration stops.

Callers 6

newIndexFunction · 0.92
newFromConfigFunction · 0.92
newFromConfigFunction · 0.92
newFromConfigFunction · 0.92
newSyncFromConfigFunction · 0.92
newKVOrNilFunction · 0.92

Calls 2

NewKeyValueFunction · 0.85
WipeMethod · 0.65

Tested by

no test coverage detected