Skip to content
This repository has been archived by the owner on Sep 19, 2024. It is now read-only.

Commit

Permalink
ignore non-existent path in file loader
Browse files Browse the repository at this point in the history
  • Loading branch information
waynz0r committed Jan 29, 2024
1 parent c1d92de commit ac9ef5f
Showing 1 changed file with 15 additions and 4 deletions.
19 changes: 15 additions & 4 deletions pkg/util/file_content_loader.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ package util

import (
"context"
"io/fs"
"os"
"path/filepath"
"sync"
Expand All @@ -44,12 +45,22 @@ type fileContentLoader struct {
type FileContentLoadedFunc func(map[string][]byte)

func NewFileContentLoader(paths []string, logger logr.Logger) FileContentLoader {
return &fileContentLoader{
paths: paths,
logger: logger.WithValues("paths", paths),
r := &fileContentLoader{
paths: []string{},
mu: sync.Mutex{},
}

mu: sync.Mutex{},
for _, path := range paths {
_, err := os.Lstat(path)
if errors.Is(err, fs.ErrNotExist) {
continue
}
r.paths = append(r.paths, path)
}

r.logger = logger.WithValues("paths", r.paths)

return r
}

func (r *fileContentLoader) Run(ctx context.Context, h FileContentLoadedFunc) error {
Expand Down

0 comments on commit ac9ef5f

Please sign in to comment.