config/apply: only request the []FileDef, not the full config

This commit is contained in:
Mikaël Cluseau 2024-01-20 16:34:54 +01:00
parent 39b9b401ba
commit 29595df7b8

View File

@ -12,7 +12,7 @@ import (
) )
// Files writes the files from the given config // Files writes the files from the given config
func Files(cfg *config.Config, prefix string, filters ...string) error { func Files(cfgFiles []config.FileDef, prefix string, filters ...string) error {
accept := func(n string) bool { return true } accept := func(n string) bool { return true }
if len(filters) > 0 { if len(filters) > 0 {
@ -30,7 +30,7 @@ func Files(cfg *config.Config, prefix string, filters ...string) error {
failed := 0 failed := 0
for _, file := range cfg.Files { for _, file := range cfgFiles {
if !accept(file.Path) { if !accept(file.Path) {
continue continue
} }
@ -52,7 +52,6 @@ func Files(cfg *config.Config, prefix string, filters ...string) error {
content, content,
mode, mode,
0755, 0755,
cfg,
) )
if err != nil { if err != nil {
@ -69,7 +68,7 @@ func Files(cfg *config.Config, prefix string, filters ...string) error {
return nil return nil
} }
func writeFile(log zerolog.Logger, path string, content []byte, fileMode, dirMode os.FileMode, cfg *config.Config) (err error) { func writeFile(log zerolog.Logger, path string, content []byte, fileMode, dirMode os.FileMode) (err error) {
if err = os.MkdirAll(filepath.Dir(path), dirMode); err != nil { if err = os.MkdirAll(filepath.Dir(path), dirMode); err != nil {
log.Error().Err(err).Msg("failed to create parent dir") log.Error().Err(err).Msg("failed to create parent dir")
return return