]> source.dussan.org Git - nextcloud-server.git/commitdiff
Do not emit preHooks twice on non-part-storage 11961/head
authorRoeland Jago Douma <roeland@famdouma.nl>
Fri, 19 Oct 2018 10:19:53 +0000 (12:19 +0200)
committerRoeland Jago Douma <roeland@famdouma.nl>
Sun, 21 Oct 2018 11:58:07 +0000 (13:58 +0200)
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 <roeland@famdouma.nl>
apps/dav/lib/Connector/Sabre/File.php

index e46bdcb2984b5653da3cbb8e0b4e056f9ce93be4..9e927ff85e5bf5182e41bdcdd2c095ae0cf36cbf 100644 (file)
@@ -140,6 +140,8 @@ class File extends Node implements IFile {
                list($partStorage) = $this->fileView->resolvePath($this->path);
                $needsPartFile = $partStorage->needsPartFile() && (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';
@@ -147,11 +149,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);
@@ -159,9 +161,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);
                        }