diff --git a/app/Models/LocalFileVolume.php b/app/Models/LocalFileVolume.php index a3bbbc64a..1a5430c5b 100644 --- a/app/Models/LocalFileVolume.php +++ b/app/Models/LocalFileVolume.php @@ -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); + } } diff --git a/bootstrap/helpers/shared.php b/bootstrap/helpers/shared.php index 7dc636587..218ca1b37 100644 --- a/bootstrap/helpers/shared.php +++ b/bootstrap/helpers/shared.php @@ -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), - ], - [ - 'fs_path' => $source, - 'mount_path' => $target, - 'content' => $content, - 'is_directory' => $isDirectory, - '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), - ], - [ - 'fs_path' => $source, - 'mount_path' => $target, - 'content' => $content, - 'is_directory' => $isDirectory, - '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) {