all repos — searchix @ 6ae7560fb293ff0bc1dbd2cc490040ac2990266e

Search engine for NixOS, nix-darwin, home-manager and NUR users

fix: abort pruning if too many entities selected

Alan Pearce
commit

6ae7560fb293ff0bc1dbd2cc490040ac2990266e

parent

7f7515906b28675a38a9988eb25f9b5b527c9d95

1 file changed, 9 insertions(+), 0 deletions(-)

changed files
M internal/importer/main.gointernal/importer/main.go
@@ -203,6 +203,15 @@ if count == 0 {
return nil } + maxCount, err := tx.Count(obj) + if err != nil { + return fault.Wrap(err, fmsg.With("failed to retrieve entities for pruning")) + } + + if float64(count) > (0.9 * float64(maxCount)) { + return fault.Newf("too many entities to prune: %d/%d (threshold: 90%%)", count, maxCount) + } + objs := make(chan nix.Importable, 1) errs := write.WithBatch(ctx, objs, func(batch *bleve.Batch, obj nix.Importable) error { batch.Delete(obj.GetName())