From a137eebb8295c8a085a8bbeba602c4985ed47161 Mon Sep 17 00:00:00 2001 From: Julius Knorr Date: Tue, 10 Sep 2024 09:43:42 +0200 Subject: [PATCH] fix: Only write once to template instead of create/copy Signed-off-by: Julius Knorr --- lib/private/Files/Template/TemplateManager.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/private/Files/Template/TemplateManager.php b/lib/private/Files/Template/TemplateManager.php index 8b20e86930a47..e61b47202890f 100644 --- a/lib/private/Files/Template/TemplateManager.php +++ b/lib/private/Files/Template/TemplateManager.php @@ -144,11 +144,9 @@ public function createFromTemplate(string $filePath, string $templateId = '', st throw new GenericFileException($this->l10n->t('Invalid path')); } $folder = $userFolder->get(dirname($filePath)); - $targetFile = $folder->newFile(basename($filePath)); $template = null; if ($templateType === 'user' && $templateId !== '') { $template = $userFolder->get($templateId); - $template->copy($targetFile->getPath()); } else { $matchingProvider = array_filter($this->getRegisteredProviders(), function (ICustomTemplateProvider $provider) use ($templateType) { return $templateType === get_class($provider); @@ -156,9 +154,11 @@ public function createFromTemplate(string $filePath, string $templateId = '', st $provider = array_shift($matchingProvider); if ($provider) { $template = $provider->getCustomTemplate($templateId); - $template->copy($targetFile->getPath()); } } + + $targetFile = $folder->newFile(basename($filePath), ($template instanceof File ? $template->fopen('rb') : null)); + $this->eventDispatcher->dispatchTyped(new FileCreatedFromTemplateEvent($template, $targetFile, $templateFields)); return $this->formatFile($userFolder->get($filePath)); } catch (\Exception $e) {