fix: error saving metadata when re-indexing
2 files changed, 8 insertions(+), 24 deletions(-)
changed files
M internal/file/root.go → internal/file/root.go
@@ -80,10 +80,10 @@ return nil } -func (r *Root) RemoveAll() error { - err := os.RemoveAll(r.Name()) +func (r *Root) RemoveAll(name string) error { + err := os.RemoveAll(r.JoinPath(name)) if err != nil { - return fault.Wrap(err, fmsg.Withf("failed to remove data root %s", r.Name())) + return fault.Wrap(err, fmsg.Withf("failed to remove path %s", r.JoinPath(name))) } return nil
M internal/index/indexer.go → internal/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