diff --git a/lib/private/files/view.php b/lib/private/files/view.php index 99db05f65c..483dc61052 100644 --- a/lib/private/files/view.php +++ b/lib/private/files/view.php @@ -535,25 +535,40 @@ class View { ) { $path = $this->getRelativePath($absolutePath); + $this->lockFile($path, ILockingProvider::LOCK_SHARED); + $exists = $this->file_exists($path); $run = true; if ($this->shouldEmitHooks($path)) { $this->emit_file_hooks_pre($exists, $path, $run); } if (!$run) { + $this->unlockFile($path, ILockingProvider::LOCK_SHARED); return false; } - $target = $this->fopen($path, 'w'); + + $this->changeLock($path, ILockingProvider::LOCK_EXCLUSIVE); + + /** @var \OC\Files\Storage\Storage $storage */ + list($storage, $internalPath) = $this->resolvePath($path); + $target = $storage->fopen($internalPath, 'w'); if ($target) { - list ($count, $result) = \OC_Helper::streamCopy($data, $target); + list (, $result) = \OC_Helper::streamCopy($data, $target); fclose($target); fclose($data); + + $this->changeLock($path, ILockingProvider::LOCK_SHARED); + $this->updater->update($path); + + $this->unlockFile($path, ILockingProvider::LOCK_SHARED); + if ($this->shouldEmitHooks($path) && $result !== false) { $this->emit_file_hooks_post($exists, $path); } return $result; } else { + $this->unlockFile($path, ILockingProvider::LOCK_EXCLUSIVE); return false; } } else {