From dd1b0799a422bfb2dfe167942953af08c007ba4f Mon Sep 17 00:00:00 2001
From: Robin Appelman <robin@icewind.nl>
Date: Thu, 26 Apr 2018 11:16:51 +0200
Subject: [PATCH] only allow a single concurrent dav write to a file

Signed-off-by: Robin Appelman <robin@icewind.nl>
---
 apps/dav/lib/Connector/Sabre/Directory.php | 11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)

diff --git a/apps/dav/lib/Connector/Sabre/Directory.php b/apps/dav/lib/Connector/Sabre/Directory.php
index a7b8ea1755e..aaf5f54ec26 100644
--- a/apps/dav/lib/Connector/Sabre/Directory.php
+++ b/apps/dav/lib/Connector/Sabre/Directory.php
@@ -28,6 +28,7 @@
  * along with this program.  If not, see <http://www.gnu.org/licenses/>
  *
  */
+
 namespace OCA\DAV\Connector\Sabre;
 
 use OC\Files\View;
@@ -147,8 +148,16 @@ class Directory extends \OCA\DAV\Connector\Sabre\Node
 				$info = new \OC\Files\FileInfo($path, null, null, [], null);
 			}
 			$node = new \OCA\DAV\Connector\Sabre\File($this->fileView, $info);
+
+			// only allow 1 process to upload a file at once but still allow reading the file while writing the part file
 			$node->acquireLock(ILockingProvider::LOCK_SHARED);
-			return $node->put($data);
+			$this->fileView->lockFile($path . '.upload.part', ILockingProvider::LOCK_EXCLUSIVE);
+
+			$result = $node->put($data);
+
+			$this->fileView->unlockFile($path . '.upload.part', ILockingProvider::LOCK_EXCLUSIVE);
+			$node->releaseLock(ILockingProvider::LOCK_SHARED);
+			return $result;
 		} catch (\OCP\Files\StorageNotAvailableException $e) {
 			throw new \Sabre\DAV\Exception\ServiceUnavailable($e->getMessage(), $e->getCode(), $e);
 		} catch (InvalidPathException $ex) {
-- 
GitLab