all repos — searchix @ 3e928369c3af69d0ef24a2f5d20c938689b15aa1

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

fix: error saving metadata when re-indexing

Alan Pearce
commit

3e928369c3af69d0ef24a2f5d20c938689b15aa1

parent

c4377589f5f6e97b430d4fabab2aa1bb72b0996d

1 file changed, 5 insertions(+), 21 deletions(-)

changed files
M internal/index/indexer.gointernal/index/indexer.go
@@ -4,9 +4,7 @@ import (
"bytes" "context" "encoding/gob" - "io/fs" "math" - "slices" "alin.ovh/searchix/internal/config" "alin.ovh/searchix/internal/file"
@@ -210,29 +208,15 @@
var expectedDataFiles = []string{ metaBaseName, indexBaseName, - "sources", - "nixpkgs-programs.db", "manpage-urls.json", } func deleteIndex(root *file.Root) error { - dir, err := fs.ReadDir(root.FS(), ".") - if err != nil { - return fault.Wrap(err, fmsg.Withf("could not read data directory")) - } - remainingFiles := slices.DeleteFunc(dir, func(e fs.DirEntry) bool { - return slices.Contains(expectedDataFiles, e.Name()) - }) - if len(remainingFiles) > 0 { - return fault.Newf( - "cowardly refusing to remove data directory as it contains unknown files: %v", - remainingFiles, - ) - } - - err = root.RemoveAll() - if err != nil { - return fault.Wrap(err) + for _, file := range expectedDataFiles { + err := root.RemoveAll(file) + if err != nil { + return fault.Wrap(err, fmsg.Withf("could not remove file %s", file)) + } } return nil