NewKeyValueMaybeWipe calls NewKeyValue and wipes the KeyValue if, and only if, NewKeyValue has returned a NeedWipeError.
(cfg jsonconfig.Obj)
| 253 | // NewKeyValueMaybeWipe calls NewKeyValue and wipes the KeyValue if, and only |
| 254 | // if, NewKeyValue has returned a NeedWipeError. |
| 255 | func 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. |
no test coverage detected