all repos — searchix @ abef2e5b0db37c771464469c3f83890b4cc0a297

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

feat(storage): respect --replace flag

Alan Pearce
commit

abef2e5b0db37c771464469c3f83890b4cc0a297

parent

5afd91c0b78982e8d1dfd41a911cf85d108979d9

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

changed files
M internal/storage/store.gointernal/storage/store.go
@@ -20,8 +20,9 @@
var BatchSize = 10000 type Options struct { - Root *file.Root - Logger *log.Logger + Replace bool + Root *file.Root + Logger *log.Logger } type Store struct {
@@ -36,6 +37,15 @@ func New(opts *Options) (*Store, error) {
exists, err := opts.Root.Exists(filename) if err != nil { return nil, fault.Wrap(err, fmsg.With("failed to check if file exists")) + } + + if opts.Replace && exists { + err = opts.Root.Remove(filename) + if err != nil { + return nil, fault.Wrap(err, fmsg.With("failed to remove existing file")) + } + + exists = false } //nolint:forbidigo // external package