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 <roeland@famdouma.nl>
This commit is contained in:
Roeland Jago Douma 2018-10-19 12:19:53 +02:00
parent e3a2b9e3e6
commit 998b646f97
No known key found for this signature in database
GPG Key ID: F941078878347C0C
1 changed files with 5 additions and 6 deletions

View File

@ -138,6 +138,8 @@ class File extends Node implements IFile {
list($partStorage) = $this->fileView->resolvePath($this->path); list($partStorage) = $this->fileView->resolvePath($this->path);
$needsPartFile = $this->needsPartFile($partStorage) && (strlen($this->path) > 1); $needsPartFile = $this->needsPartFile($partStorage) && (strlen($this->path) > 1);
$view = \OC\Files\Filesystem::getView();
if ($needsPartFile) { if ($needsPartFile) {
// mark file as partial while uploading (ignored by the scanner) // mark file as partial while uploading (ignored by the scanner)
$partFilePath = $this->getPartFileBasePath($this->path) . '.ocTransferId' . rand() . '.part'; $partFilePath = $this->getPartFileBasePath($this->path) . '.ocTransferId' . rand() . '.part';
@ -145,10 +147,10 @@ class File extends Node implements IFile {
// upload file directly as the final path // upload file directly as the final path
$partFilePath = $this->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) // 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 */ /** @var \OC\Files\Storage\Storage $partStorage */
@ -157,9 +159,6 @@ class File extends Node implements IFile {
list($storage, $internalPath) = $this->fileView->resolvePath($this->path); list($storage, $internalPath) = $this->fileView->resolvePath($this->path);
try { try {
if (!$needsPartFile) { if (!$needsPartFile) {
if ($view && !$this->emitPreHooks($exists)) {
throw new Exception('Could not write to final file, canceled by hook');
}
$this->changeLock(ILockingProvider::LOCK_EXCLUSIVE); $this->changeLock(ILockingProvider::LOCK_EXCLUSIVE);
} }