diff --git a/installer/fs.go b/installer/fs.go index 015944a..d09b767 100644 --- a/installer/fs.go +++ b/installer/fs.go @@ -7,7 +7,6 @@ import ( "log/slog" "os" "path/filepath" - "strings" "github.com/livingsilver94/backee/privilege" "github.com/livingsilver94/backee/service" @@ -106,36 +105,6 @@ func (w *CopyWriter) writeDestination(dst string) error { return buff.Flush() } -func writeFiles(files map[string]service.FilePath, baseDir string, repl Template, wr FileWriter) error { - var resolvedDst strings.Builder - for srcFile, dstFile := range files { - err := repl.ReplaceString(dstFile.Path, &resolvedDst) - if err != nil { - return err - } - err = WritePath( - service.FilePath{Path: resolvedDst.String(), Mode: dstFile.Mode}, - filepath.Join(baseDir, srcFile), - wr, - ) - if err != nil { - if !errors.Is(err, fs.ErrPermission) { - return err - } - err = WritePathPrivileged( - service.FilePath{Path: resolvedDst.String(), Mode: dstFile.Mode}, - filepath.Join(baseDir, srcFile), - wr, - ) - if err != nil { - return err - } - } - resolvedDst.Reset() - } - return nil -} - type privilegedPathWriter struct { dst service.FilePath src string diff --git a/installer/step.go b/installer/step.go index 3391bce..981116b 100644 --- a/installer/step.go +++ b/installer/step.go @@ -119,6 +119,40 @@ func runProcess(name string, arg ...string) error { return cmd.Run() } +func writeFiles(files map[string]service.FilePath, baseDir string, repl Template, wr FileWriter) error { + var resolvedDst strings.Builder + for srcFile, dstFile := range files { + err := repl.ReplaceString(dstFile.Path, &resolvedDst) + if err != nil { + return err + } + err = writePath( + service.FilePath{Path: resolvedDst.String(), Mode: dstFile.Mode}, + filepath.Join(baseDir, srcFile), + wr, + ) + if err != nil { + return err + } + resolvedDst.Reset() + } + return nil +} + +func writePath(dst service.FilePath, src string, wr FileWriter) error { + err := WritePath(dst, src, wr) + if err != nil { + if !errors.Is(err, fs.ErrPermission) { + return err + } + err = WritePathPrivileged(dst, src, wr) + if err != nil { + return err + } + } + return nil +} + type UnixID struct { UID uint32 GID uint32