mirror of
https://github.com/coollabsio/coolify.git
synced 2026-11-06 13:10:37 -04:00
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:
@@ -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,
|
||||
|
||||
@@ -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.
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user