all repos — searchix @ bdb5a54c661407c39668096074a1f4a57898eb77

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

feat: store fetched files in data directory

Alan Pearce
commit

bdb5a54c661407c39668096074a1f4a57898eb77

parent

3e928369c3af69d0ef24a2f5d20c938689b15aa1

1 file changed, 7 insertions(+), 27 deletions(-)

changed files
M internal/manpages/manpages.gointernal/manpages/manpages.go
@@ -4,7 +4,6 @@ import (
"context" "encoding/json" "fmt" - "io" "time" "alin.ovh/searchix/internal/config"
@@ -49,32 +48,29 @@ if source.Manpages.Path == "" {
return fault.New("manpages repo source path not configured") } + fetcher := http.NewFetcher(&http.Options{ + Logger: m.logger.Named("http"), + Root: m.root, + }) + url, err := makeManpageURL(source) if err != nil { return fault.Wrap(err, fmsg.With("failed to join manpages URL")) } m.logger.Debug("fetching manpages URL map", "url", url) - r, mtime, err := http.FetchFileIfNeeded(ctx, m.logger.Named("http"), m.mtime, url) + r, err := fetcher.FetchFileIfNeeded(ctx, basename, url) if err != nil { return fault.Wrap(err, fmsg.With("failed to fetch manpages")) } defer r.Close() - if err := m.save(r); err != nil { - return fault.Wrap(err, fmsg.With("failed to save manpages")) - } - - m.mtime = mtime - return nil } // Open loads the manpage URLs from the JSON file func (m *URLMap) Open() error { - m.logger.Debug("opening manpages file", "path", basename) - - stat, err := m.root.Stat(basename) + stat, err := m.root.StatIfExists(basename) if err != nil { return fault.Wrap(err, fmsg.Withf("failed to stat manpages file: %s", basename)) }
@@ -92,22 +88,6 @@ return fault.Wrap(err, fmsg.With("failed to parse manpages JSON"))
} m.logger.Debug("loaded manpages data", "urls", len(m.urlMap)) - - return nil -} - -func (m *URLMap) save(r io.Reader) error { - m.logger.Debug("saving manpages file", "path", basename) - - f, err := m.root.Create(basename) - if err != nil { - return fault.Wrap(err, fmsg.With("failed to create manpages file")) - } - defer f.Close() - - if _, err := io.Copy(f, r); err != nil { - return fault.Wrap(err, fmsg.With("failed to write manpages file")) - } return nil }