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, 19 insertions(+), 3 deletions(-)

changed files
M internal/fetcher/main.gointernal/fetcher/main.go
@@ -5,13 +5,16 @@ "context"
"io" "alin.ovh/searchix/internal/config" + "alin.ovh/searchix/internal/file" "alin.ovh/searchix/internal/index" "alin.ovh/x/log" "github.com/Southclaws/fault" + "github.com/Southclaws/fault/fmsg" ) type Options struct { Logger *log.Logger + Root *file.Root } type FetchedFiles struct {
@@ -28,13 +31,26 @@ func New(
source *config.Source, opts *Options, ) (fetcher Fetcher, err error) { + target := source.JoinPath("") + exists, err := opts.Root.Exists(target) + if err != nil { + return nil, fault.Wrap(err, fmsg.With("failed to check if directory exists")) + } + + if !exists { + err = opts.Root.MkdirAll(target) + if err != nil { + return nil, fault.Wrap(err, fmsg.With("failed to create directory")) + } + } + switch source.Fetcher { case config.ChannelNixpkgs: - fetcher, err = NewNixpkgsChannelFetcher(source, opts.Logger) + fetcher, err = NewNixpkgsChannelFetcher(source, opts) case config.Channel: - fetcher, err = NewChannelFetcher(source, opts.Logger) + fetcher, err = NewChannelFetcher(source, opts) case config.Download: - fetcher, err = NewDownloadFetcher(source, opts.Logger) + fetcher, err = NewDownloadFetcher(source, opts) default: err = fault.Newf("unsupported fetcher type %s", source.Fetcher.String()) }