From 998b646f97e8e9402dacc83cdf323cf9ab44c55d Mon Sep 17 00:00:00 2001 From: Roeland Jago Douma Date: Fri, 19 Oct 2018 12:19:53 +0200 Subject: [PATCH] Do not emit preHooks twice on non-part-storage The old code would emit the hooks twice. Thus having the version written twice. Which is not very performant as it is first read twice as well. Signed-off-by: Roeland Jago Douma --- apps/dav/lib/Connector/Sabre/File.php | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/apps/dav/lib/Connector/Sabre/File.php b/apps/dav/lib/Connector/Sabre/File.php index 49b3debc38..2b3956e2ba 100644 --- a/apps/dav/lib/Connector/Sabre/File.php +++ b/apps/dav/lib/Connector/Sabre/File.php @@ -138,6 +138,8 @@ class File extends Node implements IFile { list($partStorage) = $this->fileView->resolvePath($this->path); $needsPartFile = $this->needsPartFile($partStorage) && (strlen($this->path) > 1); + $view = \OC\Files\Filesystem::getView(); + if ($needsPartFile) { // mark file as partial while uploading (ignored by the scanner) $partFilePath = $this->getPartFileBasePath($this->path) . '.ocTransferId' . rand() . '.part'; @@ -145,11 +147,11 @@ class File extends Node implements IFile { // upload file directly as the final path $partFilePath = $this->path; - $this->emitPreHooks($exists); + if ($view && !$this->emitPreHooks($exists)) { + throw new Exception('Could not write to final file, canceled by hook'); + } } - $view = \OC\Files\Filesystem::getView(); - // the part file and target file might be on a different storage in case of a single file storage (e.g. single file share) /** @var \OC\Files\Storage\Storage $partStorage */ list($partStorage, $internalPartPath) = $this->fileView->resolvePath($partFilePath); @@ -157,9 +159,6 @@ class File extends Node implements IFile { list($storage, $internalPath) = $this->fileView->resolvePath($this->path); try { if (!$needsPartFile) { - if ($view && !$this->emitPreHooks($exists)) { - throw new Exception('Could not write to final file, canceled by hook'); - } $this->changeLock(ILockingProvider::LOCK_EXCLUSIVE); }