all repos — searchix @ 1d518f42e04712c84dfc168cc7a286aabb56e2ed

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

feat: limit file operations using os.Root

Alan Pearce
commit

1d518f42e04712c84dfc168cc7a286aabb56e2ed

parent

dec2c516100350a78f0b7116bc6f9d76325e7760

1 file changed, 13 insertions(+), 2 deletions(-)

changed files
M cmd/searchix-web/main.gocmd/searchix-web/main.go
@@ -16,6 +16,7 @@
"alin.ovh/searchix/frontend" "alin.ovh/searchix/internal/components" "alin.ovh/searchix/internal/config" + "alin.ovh/searchix/internal/file" "alin.ovh/searchix/internal/importer" "alin.ovh/searchix/internal/index" "alin.ovh/searchix/internal/manpages"
@@ -76,6 +77,7 @@ os.Exit(0)
} if *cpuprofile != "" { + //nolint:forbidigo // admin specifies profile file location f, err := os.Create(*cpuprofile) if err != nil { panic("can't create CPU profile: " + err.Error())
@@ -98,9 +100,15 @@ log.SetLevel(cfg.LogLevel)
ctx, cancel := signal.NotifyContext(context.Background(), os.Interrupt) defer cancel() + + root, err := file.CreateAndOpenRoot(cfg.DataPath) + if err != nil { + logger.Fatal("Failed to open data root", "error", err) + } + defer root.Close() read, write, exists, err := index.OpenOrCreate( - cfg.DataPath, + root, *replace, &index.Options{ LowMemory: cfg.Importer.LowMemory,
@@ -112,7 +120,10 @@ if err != nil {
logger.Fatal("Failed to open or create index", "error", err) } - mdb := manpages.New(cfg, logger.Named("manpages")) + mdb := manpages.New(&manpages.Options{ + Logger: logger.Named("manpages"), + Root: root, + }) s, err := web.New(cfg, logger, &server.Options{ ReadIndex: read,