fix(file-storage): double save on compose volumes

This commit is contained in:
Andras Bacsai
2025-03-28 22:10:33 +01:00
parent 0bb47dfa56
commit c2941abe57
2 changed files with 49 additions and 39 deletions

View File

@@ -176,4 +176,19 @@ class LocalFileVolume extends BaseModel
return instant_remote_process($commands, $server);
}
// Accessor for convenient access
protected function plainMountPath(): Attribute
{
return Attribute::make(
get: fn () => $this->mount_path,
set: fn ($value) => $this->mount_path = $value
);
}
// Scope for searching
public function scopeWherePlainMountPath($query, $path)
{
return $query->get()->where('plain_mount_path', $path);
}
}

View File

@@ -1363,21 +1363,15 @@ function parseServiceVolumes($serviceVolumes, $resource, $topLevelVolumes, $pull
$source = $source."-pr-$pull_request_id";
}
if (! $resource?->settings?->is_preserve_repository_enabled || $foundConfig?->is_based_on_git) {
LocalFileVolume::updateOrCreate(
[
'mount_path' => $target,
'resource_id' => $resource->id,
'resource_type' => get_class($resource),
],
[
$volume = LocalFileVolume::wherePlainMountPath($target)->first() ?? new LocalFileVolume;
$volume->fill([
'fs_path' => $source,
'mount_path' => $target,
'content' => $content,
'is_directory' => $isDirectory,
'resource_id' => $resource->id,
'resource_type' => get_class($resource),
]
);
])->save();
}
} elseif ($type->value() === 'volume') {
if ($topLevelVolumes->has($source->value())) {
@@ -1675,21 +1669,28 @@ function parseDockerComposeFile(Service|Application $resource, bool $isNew = fal
if ($source->value() === '/tmp' || $source->value() === '/tmp/') {
return $volume;
}
LocalFileVolume::updateOrCreate(
[
'mount_path' => $target,
'resource_id' => $savedService->id,
'resource_type' => get_class($savedService),
],
[
$existingVolume = LocalFileVolume::wherePlainMountPath($target)->first();
if ($existingVolume) {
$existingVolume->update([
'fs_path' => $source,
'mount_path' => $target,
'content' => $content,
'is_directory' => $isDirectory,
'resource_id' => $savedService->id,
'resource_type' => get_class($savedService),
]
);
]);
} else {
LocalFileVolume::create([
'fs_path' => $source,
'mount_path' => $target,
'content' => $content,
'is_directory' => $isDirectory,
'resource_id' => $savedService->id,
'resource_type' => get_class($savedService),
]);
}
} elseif ($type->value() === 'volume') {
if ($topLevelVolumes->has($source->value())) {
$v = $topLevelVolumes->get($source->value());
@@ -3327,21 +3328,15 @@ function newParser(Application|Service $resource, int $pull_request_id = 0, ?int
if ($isApplication && $isPullRequest) {
$source = $source."-pr-$pullRequestId";
}
LocalFileVolume::updateOrCreate(
[
'mount_path' => $target,
'resource_id' => $originalResource->id,
'resource_type' => get_class($originalResource),
],
[
$volume = LocalFileVolume::wherePlainMountPath($target)->first() ?? new LocalFileVolume;
$volume->fill([
'fs_path' => $source,
'mount_path' => $target,
'content' => $content,
'is_directory' => $isDirectory,
'resource_id' => $originalResource->id,
'resource_type' => get_class($originalResource),
]
);
])->save();
if (isDev()) {
if ((int) $resource->compose_parsing_version >= 4) {
if ($isApplication) {