@@ -25,6 +25,7 @@ import (
2525 http2 "net/http"
2626 "os"
2727 "path/filepath"
28+ "slices"
2829 "sort"
2930 "strings"
3031 "time"
@@ -120,13 +121,15 @@ func (self Compose) Create(http *gin.Context) {
120121 }
121122 }
122123
124+ overrideYamlFileName := "dpanel-override.yaml"
125+ if yamlRow .Setting .Type == accessor .ComposeTypeOutPath {
126+ // 外部 compose 的覆盖文件采用同名
127+ overrideYamlFileName = fmt .Sprintf ("dpanel-%s-override.yaml" , yamlRow .Name )
128+ }
129+ overrideYamlFilePath := filepath .Join (filepath .Dir (yamlRow .Setting .GetUriFilePath ()), overrideYamlFileName )
130+ overrideRelPath , _ := filepath .Rel (yamlRow .Setting .GetWorkingDir (), overrideYamlFilePath )
131+
123132 if params .YamlOverride != "" {
124- overrideYamlFileName := "dpanel-override.yaml"
125- if yamlRow .Setting .Type == accessor .ComposeTypeOutPath {
126- // 外部 compose 的覆盖文件采用同名
127- overrideYamlFileName = fmt .Sprintf ("dpanel-%s-override.yaml" , yamlRow .Name )
128- }
129- overrideYamlFilePath := filepath .Join (filepath .Dir (yamlRow .Setting .GetUriFilePath ()), overrideYamlFileName )
130133 err := os .MkdirAll (filepath .Dir (overrideYamlFilePath ), os .ModePerm )
131134 if err != nil {
132135 self .JsonResponseWithError (http , err , 500 )
@@ -137,11 +140,18 @@ func (self Compose) Create(http *gin.Context) {
137140 self .JsonResponseWithError (http , err , 500 )
138141 return
139142 }
140-
141- rel , _ := filepath .Rel (yamlRow .Setting .GetWorkingDir (), overrideYamlFilePath )
142- if ! function .InArray (yamlRow .Setting .Uri , rel ) {
143- yamlRow .Setting .Uri = append (yamlRow .Setting .Uri , rel )
143+ if ! function .InArray (yamlRow .Setting .Uri , overrideRelPath ) {
144+ yamlRow .Setting .Uri = append (yamlRow .Setting .Uri , overrideRelPath )
144145 }
146+ } else {
147+ err = os .Remove (overrideYamlFilePath )
148+ if err != nil {
149+ self .JsonResponseWithError (http , err , 500 )
150+ return
151+ }
152+ yamlRow .Setting .Uri = slices .DeleteFunc (yamlRow .Setting .Uri , func (s string ) bool {
153+ return s == overrideRelPath
154+ })
145155 }
146156
147157 if ! function .IsEmptyArray (params .Environment ) {
0 commit comments