From ecb75bb5a8667a04980c49a435976984f559f005 Mon Sep 17 00:00:00 2001 From: Piotr M Date: Fri, 26 May 2017 13:09:48 +0200 Subject: [PATCH] Dont update again if mtime is to be updated, use target storage update instead --- apps/dav/lib/Connector/Sabre/File.php | 49 ++++++++++++++------------- apps/dav/lib/Connector/Sabre/Node.php | 2 ++ 2 files changed, 28 insertions(+), 23 deletions(-) diff --git a/apps/dav/lib/Connector/Sabre/File.php b/apps/dav/lib/Connector/Sabre/File.php index 75cc5779100a..3b03073e0bc0 100644 --- a/apps/dav/lib/Connector/Sabre/File.php +++ b/apps/dav/lib/Connector/Sabre/File.php @@ -82,7 +82,30 @@ public function __construct($view, $info, $shareManager = null, Request $request } parent::__construct($view, $info, $shareManager); } - + + /** + * Handles metadata updates for the target storage (mtime, propagation) + * + * @param Storage $targetStorage + * @param $targetInternalPath + */ + private function handleMetadataUpdate(\OC\Files\Storage\Storage $targetStorage, $targetInternalPath) { + // since we skipped the view we need to scan and emit the hooks ourselves + + // allow sync clients to send the mtime along in a header + if (isset($this->request->server['HTTP_X_OC_MTIME'])) { + $mtime = $this->sanitizeMtime( + $this->request->server ['HTTP_X_OC_MTIME'] + ); + if ($targetStorage->touch($targetInternalPath, $mtime)) { + $this->header('X-OC-MTime: accepted'); + } + $targetStorage->getUpdater()->update($targetInternalPath, $mtime); + } else { + $targetStorage->getUpdater()->update($targetInternalPath); + } + } + /** * Updates the data * @@ -234,8 +257,7 @@ public function put($data) { } } - // since we skipped the view we need to scan and emit the hooks ourselves - $storage->getUpdater()->update($internalPath); + $this->handleMetadataUpdate($storage, $internalPath); try { $this->changeLock(ILockingProvider::LOCK_SHARED); @@ -243,14 +265,6 @@ public function put($data) { throw new FileLocked($e->getMessage(), $e->getCode(), $e); } - // allow sync clients to send the mtime along in a header - if (isset($this->request->server['HTTP_X_OC_MTIME'])) { - $mtime = $this->sanitizeMtime($this->request->server ['HTTP_X_OC_MTIME']); - if ($this->fileView->touch($this->path, $mtime)) { - $this->header('X-OC-MTime: accepted'); - } - } - if ($view) { $this->emitPostHooks($exists); } @@ -539,18 +553,7 @@ private function createFileChunked($data) { $chunk_handler->file_assemble($targetStorage, $targetInternalPath); } - // allow sync clients to send the mtime along in a header - if (isset($this->request->server['HTTP_X_OC_MTIME'])) { - $mtime = $this->sanitizeMtime( - $this->request->server ['HTTP_X_OC_MTIME'] - ); - if ($targetStorage->touch($targetInternalPath, $mtime)) { - $this->header('X-OC-MTime: accepted'); - } - } - - // since we skipped the view we need to scan and emit the hooks ourselves - $targetStorage->getUpdater()->update($targetInternalPath); + $this->handleMetadataUpdate($targetStorage, $targetInternalPath); $this->fileView->changeLock($targetPath, ILockingProvider::LOCK_SHARED); diff --git a/apps/dav/lib/Connector/Sabre/Node.php b/apps/dav/lib/Connector/Sabre/Node.php index 0e3b506eb6d4..e56e2af3a8eb 100644 --- a/apps/dav/lib/Connector/Sabre/Node.php +++ b/apps/dav/lib/Connector/Sabre/Node.php @@ -368,6 +368,8 @@ public function releaseLock($type) { /** * @param int $type \OCP\Lock\ILockingProvider::LOCK_SHARED or \OCP\Lock\ILockingProvider::LOCK_EXCLUSIVE + * + * @throws \OCP\Lock\LockedException */ public function changeLock($type) { $this->fileView->changeLock($this->path, $type);