fix(clone): replace the clone suffix instead of adding one for each clone

Cloning a clone added another "-clone-<id>" to the name, so after about
seven clones the name was longer than 255 characters and the insert failed.

Closes #9976
This commit is contained in:
Andras Bacsai
2026-10-27 17:06:52 +01:00
parent 1440ea83d3
commit bb1fada600
9 changed files with 58 additions and 5 deletions
+1 -1
View File
@@ -695,7 +695,7 @@ function clone_service(Service $source, StandaloneDocker|SwarmDocker $destinatio
'created_at',
'updated_at',
])->fill([
'name' => $source->name.'-clone-'.$uuid,
'name' => clone_resource_name($source->name, $uuid),
...$overrides,
'uuid' => $uuid,
'destination_id' => $destination->id,
+12
View File
@@ -134,6 +134,18 @@ function new_public_id(int $length = 24): string
return Str::lower(Str::random($length));
}
/**
* The name of a clone: the source name without the "-clone-<id>" suffixes of earlier clones, then a new suffix.
* Without this, each clone of a clone adds a suffix, and the name soon becomes longer than the 255 characters of the column.
*/
function clone_resource_name(string $name, string $uuid): string
{
$suffix = '-clone-'.$uuid;
$baseName = preg_replace('/(-clone-[a-z0-9]{7,})+$/i', '', $name);
return Str::limit($baseName, 255 - strlen($suffix), '').$suffix;
}
/**
* Validate that a path or identifier is safe for use in shell commands.
*