From 4b218553c35aa52e94183f4df08b417da949656f Mon Sep 17 00:00:00 2001 From: Oscar Zhou <100548325+oscarzhou-portainer@users.noreply.github.com> Date: Fri, 21 Mar 2025 09:19:25 +1300 Subject: [PATCH] fix(libstack): data loss for stack with relative path [FR-437] (#548) --- api/filesystem/copy.go | 2 +- pkg/libstack/compose/composeplugin.go | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/api/filesystem/copy.go b/api/filesystem/copy.go index abf4d33aa..bc0abb766 100644 --- a/api/filesystem/copy.go +++ b/api/filesystem/copy.go @@ -68,7 +68,7 @@ func copyFile(src, dst string) error { defer from.Close() // has to include 'execute' bit, otherwise fails. MkdirAll follows `mkdir -m` restrictions - if err := os.MkdirAll(filepath.Dir(dst), 0744); err != nil { + if err := os.MkdirAll(filepath.Dir(dst), 0755); err != nil { return err } to, err := os.Create(dst) diff --git a/pkg/libstack/compose/composeplugin.go b/pkg/libstack/compose/composeplugin.go index c83685351..8ebc12062 100644 --- a/pkg/libstack/compose/composeplugin.go +++ b/pkg/libstack/compose/composeplugin.go @@ -98,6 +98,11 @@ func withComposeService( WorkingDir: filepath.Dir(filePaths[0]), } + if options.ProjectDir != "" { + // When relative paths are used in the compose file, the project directory is used as the base path + configDetails.WorkingDir = options.ProjectDir + } + for _, p := range filePaths { configDetails.ConfigFiles = append(configDetails.ConfigFiles, types.ConfigFile{Filename: p}) }