@@ -72,43 +72,18 @@ function getPostScript(): string
7272 if ($ indirect != "" ) {
7373 file_put_contents ("$ folder/indirect " , $ indirect );
7474 if (!findComposeFile ($ indirect )) {
75- file_put_contents ("$ indirect/compose.yaml " , "services: \n" );
75+ file_put_contents ("$ indirect/ " . COMPOSE_FILE_NAMES [ 0 ] , "services: \n" );
7676 clientDebug ("[stack] Indirect compose file not found at path: $ indirect. Created stack with empty compose file. " , null , 'daemon ' , 'warning ' );
7777 }
7878 } else {
79- file_put_contents ("$ folder/compose.yaml " , "services: \n" );
79+ file_put_contents ("$ folder/ " . COMPOSE_FILE_NAMES [ 0 ] , "services: \n" );
8080 clientDebug ("[ $ stackName] Compose file not found at path: $ folder. Created stack with empty compose file. " , null , 'daemon ' , 'warning ' );
8181 }
8282
83- // Create initial override file if it doesn't exist (for UI labels)
84- // Override filename must match the compose filename (e.g. compose.yaml -> compose.override.yaml)
85- // Overrides are stored in the project folder ($folder) even for indirect stacks.
86- $ composeSource = $ indirect != "" ? $ indirect : $ folder ;
87- $ foundCompose = findComposeFile ($ composeSource );
88- $ composeBaseName = $ foundCompose !== false ? basename ($ foundCompose ) : 'docker-compose.yml ' ;
89- $ overrideName = preg_replace ('/(\.[^.]+)$/ ' , '.override$1 ' , $ composeBaseName );
90- $ overrideFile = "$ folder/ $ overrideName " ;
91-
92- // Migrate legacy override filename if present in either project folder or indirect path
93- $ legacyInProject = "$ folder/docker-compose.override.yml " ;
94- $ legacyInIndirect = ($ indirect != "" ) ? "$ indirect/docker-compose.override.yml " : null ;
95- if (!is_file ($ overrideFile )) {
96- if (is_file ($ legacyInProject ) && realpath ($ legacyInProject ) !== realpath ($ overrideFile )) {
97- @rename ($ legacyInProject , $ overrideFile );
98- clientDebug ("[override] Migrated legacy override $ legacyInProject -> $ overrideFile " , null , 'daemon ' , 'info ' );
99- } elseif ($ legacyInIndirect && is_file ($ legacyInIndirect ) && realpath ($ legacyInIndirect ) !== realpath ($ overrideFile )) {
100- @rename ($ legacyInIndirect , $ overrideFile );
101- clientDebug ("[override] Migrated legacy override $ legacyInIndirect -> $ overrideFile " , null , 'daemon ' , 'info ' );
102- }
103- }
104-
105- if (!is_file ($ overrideFile )) {
106- $ overrideContent = "# Override file for UI labels (icon, webui, shell) \n" ;
107- $ overrideContent .= "# This file is managed by Compose Manager \n" ;
108- $ overrideContent .= "services: {} \n" ;
109- file_put_contents ($ overrideFile , $ overrideContent );
110- }
83+ // Init override info to ensure override file is created for new stack (if not indirect) and to avoid errors when accessing settings before the override file is created
84+ OverrideInfo::fromStack ($ compose_root , $ stackName );
11185
86+ // Save stack name (which may differ from folder name) for display purposes
11287 file_put_contents ("$ folder/name " , $ stackName );
11388
11489 // Save description if provided
@@ -172,7 +147,7 @@ function getPostScript(): string
172147 $ script = getPostScript ();
173148 $ basePath = getPath ("$ compose_root/ $ script " );
174149 $ foundComposeFile = findComposeFile ($ basePath );
175- $ composeFilePath = $ foundComposeFile !== false ? $ foundComposeFile : "$ basePath/docker- compose.yml " ;
150+ $ composeFilePath = $ foundComposeFile !== false ? $ foundComposeFile : "$ basePath/compose.yaml " ;
176151 $ fileName = basename ($ composeFilePath );
177152
178153 if ($ foundComposeFile !== false ) {
@@ -221,36 +196,8 @@ function getPostScript(): string
221196 $ script = getPostScript ();
222197 $ projectPath = "$ compose_root/ $ script " ;
223198
224- // If indirect exists, use it to discover the compose filename, but
225- // overrides are stored in the project folder ($projectPath).
226- $ indirectPath = is_file ("$ projectPath/indirect " ) ? file_get_contents ("$ projectPath/indirect " ) : "" ;
227- $ indirectPath = str_replace ("\r" , "" , $ indirectPath );
228- $ composeSource = $ indirectPath !== "" ? $ indirectPath : $ projectPath ;
229-
230- $ foundCompose = findComposeFile ($ composeSource );
231- $ composeBaseName = $ foundCompose !== false ? basename ($ foundCompose ) : 'docker-compose.yml ' ;
232- $ fileName = preg_replace ('/(\.[^.]+)$/ ' , '.override$1 ' , $ composeBaseName );
233-
234- $ overridePath = "$ projectPath/ $ fileName " ;
235- $ legacyProject = "$ projectPath/docker-compose.override.yml " ;
236- $ legacyIndirect = ($ indirectPath !== "" ) ? "$ indirectPath/docker-compose.override.yml " : null ;
237-
238- // Prefer correctly-named indirect override if present (do NOT move/rename indirect files)
239- if ($ indirectPath !== "" && is_file ("$ indirectPath/ $ fileName " )) {
240- $ overridePath = "$ indirectPath/ $ fileName " ;
241- } else {
242- // If indirect has a legacy-named override, warn the user and fall back to project override
243- if ($ indirectPath !== "" && $ legacyIndirect && is_file ($ legacyIndirect )) {
244- clientDebug ("[override] Indirect override exists with non-matching name ( $ legacyIndirect). Using project fallback. " , null , 'daemon ' , 'warning ' );
245- }
246-
247- // Migrate legacy project override to computed name if present (project-only migration)
248- if (!is_file ($ projectPath .'/ ' .$ fileName ) && is_file ($ legacyProject ) && realpath ($ legacyProject ) !== realpath ($ projectPath .'/ ' .$ fileName )) {
249- @rename ($ legacyProject , $ projectPath .'/ ' .$ fileName );
250- clientDebug ("[override] Migrated legacy project override $ legacyProject -> $ projectPath/ $ fileName " , null , 'daemon ' , 'info ' );
251- }
252- $ overridePath = "$ projectPath/ $ fileName " ;
253- }
199+ // Get Override file path and ensure project override exists (create blank if not)
200+ $ overridePath = OverrideInfo::fromStack ($ compose_root , $ script )->getOverridePath ();
254201
255202 $ scriptContents = is_file ($ overridePath ) ? file_get_contents ($ overridePath ) : "" ;
256203 $ scriptContents = str_replace ("\r" , "" , $ scriptContents );
@@ -287,38 +234,8 @@ function getPostScript(): string
287234 $ scriptContents = isset ($ _POST ['scriptContents ' ]) ? $ _POST ['scriptContents ' ] : "" ;
288235 $ projectPath = "$ compose_root/ $ script " ;
289236
290- // Determine compose source (indirect or project) for filename, but
291- // always store override in project folder.
292- $ indirectPath = is_file ("$ projectPath/indirect " ) ? file_get_contents ("$ projectPath/indirect " ) : "" ;
293- $ indirectPath = str_replace ("\r" , "" , $ indirectPath );
294- $ composeSource = $ indirectPath !== "" ? $ indirectPath : $ projectPath ;
295-
296- $ foundCompose = findComposeFile ($ composeSource );
297- $ composeBaseName = $ foundCompose !== false ? basename ($ foundCompose ) : 'docker-compose.yml ' ;
298- $ fileName = preg_replace ('/(\.[^.]+)$/ ' , '.override$1 ' , $ composeBaseName );
299-
300- // Determine where to save: if indirect has a correctly-named override, save there (do NOT rename/move indirect files).
301- $ indirectOverridePath = ($ indirectPath !== "" ) ? "$ indirectPath/ $ fileName " : null ;
302- $ legacyIndirect = ($ indirectPath !== "" ) ? "$ indirectPath/docker-compose.override.yml " : null ;
303- $ legacyProject = "$ projectPath/docker-compose.override.yml " ;
304-
305- if ($ indirectOverridePath && is_file ($ indirectOverridePath )) {
306- // Save back to the indirect override file the user provided (preserve external file)
307- $ overridePath = $ indirectOverridePath ;
308- } else {
309- // If an indirect legacy-named override exists, warn and save to project fallback (do not move it)
310- if ($ legacyIndirect && is_file ($ legacyIndirect )) {
311- clientDebug ("[override] Indirect override exists with non-matching name ( $ legacyIndirect). Saving to project override instead. " , null , 'daemon ' , 'warning ' );
312- }
313-
314- // Migrate legacy project override to computed name if present (project-only migration)
315- if (!is_file ("$ projectPath/ $ fileName " ) && is_file ($ legacyProject ) && realpath ($ legacyProject ) !== realpath ("$ projectPath/ $ fileName " )) {
316- @rename ($ legacyProject , "$ projectPath/ $ fileName " );
317- clientDebug ("[override] Migrated legacy project override $ legacyProject -> $ projectPath/ $ fileName " , null , 'daemon ' , 'info ' );
318- }
319-
320- $ overridePath = "$ projectPath/ $ fileName " ;
321- }
237+ // Get Override file path and ensure project override exists (create blank if not)
238+ $ overridePath = OverrideInfo::fromStack ($ compose_root , $ script )->getOverridePath ();
322239
323240 file_put_contents ($ overridePath , $ scriptContents );
324241 echo "$ overridePath saved " ;
0 commit comments