From c487f0f13823322d7290d90e37e20bf0c317efb5 Mon Sep 17 00:00:00 2001
From: Robin Appelman <icewind@owncloud.com>
Date: Wed, 4 Nov 2015 14:45:10 +0100
Subject: [PATCH] when a file is locked use old cache data

---
 lib/private/files/view.php | 66 +++++++++++++++++++++-----------------
 1 file changed, 37 insertions(+), 29 deletions(-)

diff --git a/lib/private/files/view.php b/lib/private/files/view.php
index 57cd32cefe7..887b18530d7 100644
--- a/lib/private/files/view.php
+++ b/lib/private/files/view.php
@@ -1194,23 +1194,27 @@ class View {
 			$data = $cache->get($internalPath);
 			$watcher = $storage->getWatcher($internalPath);
 
-			// if the file is not in the cache or needs to be updated, trigger the scanner and reload the data
-			if (!$data) {
-				$this->lockFile($relativePath, ILockingProvider::LOCK_SHARED);
-				if (!$storage->file_exists($internalPath)) {
+			try {
+				// if the file is not in the cache or needs to be updated, trigger the scanner and reload the data
+				if (!$data) {
+					$this->lockFile($relativePath, ILockingProvider::LOCK_SHARED);
+					if (!$storage->file_exists($internalPath)) {
+						$this->unlockFile($relativePath, ILockingProvider::LOCK_SHARED);
+						return false;
+					}
+					$scanner = $storage->getScanner($internalPath);
+					$scanner->scan($internalPath, Cache\Scanner::SCAN_SHALLOW);
+					$data = $cache->get($internalPath);
+					$this->unlockFile($relativePath, ILockingProvider::LOCK_SHARED);
+				} else if (!Cache\Scanner::isPartialFile($internalPath) && $watcher->needsUpdate($internalPath, $data)) {
+					$this->lockFile($relativePath, ILockingProvider::LOCK_SHARED);
+					$watcher->update($internalPath, $data);
+					$this->updater->propagate($path);
+					$data = $cache->get($internalPath);
 					$this->unlockFile($relativePath, ILockingProvider::LOCK_SHARED);
-					return false;
 				}
-				$scanner = $storage->getScanner($internalPath);
-				$scanner->scan($internalPath, Cache\Scanner::SCAN_SHALLOW);
-				$data = $cache->get($internalPath);
-				$this->unlockFile($relativePath, ILockingProvider::LOCK_SHARED);
-			} else if (!Cache\Scanner::isPartialFile($internalPath) && $watcher->needsUpdate($internalPath, $data)) {
-				$this->lockFile($relativePath, ILockingProvider::LOCK_SHARED);
-				$watcher->update($internalPath, $data);
-				$this->updater->propagate($path);
-				$data = $cache->get($internalPath);
-				$this->unlockFile($relativePath, ILockingProvider::LOCK_SHARED);
+			} catch (LockedException $e) {
+				// if the file is locked we just use the old cache info
 			}
 
 			if ($data and isset($data['fileid'])) {
@@ -1278,22 +1282,26 @@ class View {
 
 			$data = $cache->get($internalPath);
 			$watcher = $storage->getWatcher($internalPath);
-			if (!$data or $data['size'] === -1) {
-				$this->lockFile($directory, ILockingProvider::LOCK_SHARED);
-				if (!$storage->file_exists($internalPath)) {
+			try {
+				if (!$data or $data['size'] === -1) {
+					$this->lockFile($directory, ILockingProvider::LOCK_SHARED);
+					if (!$storage->file_exists($internalPath)) {
+						$this->unlockFile($directory, ILockingProvider::LOCK_SHARED);
+						return array();
+					}
+					$scanner = $storage->getScanner($internalPath);
+					$scanner->scan($internalPath, Cache\Scanner::SCAN_SHALLOW);
+					$data = $cache->get($internalPath);
+					$this->unlockFile($directory, ILockingProvider::LOCK_SHARED);
+				} else if ($watcher->needsUpdate($internalPath, $data)) {
+					$this->lockFile($directory, ILockingProvider::LOCK_SHARED);
+					$watcher->update($internalPath, $data);
+					$this->updater->propagate($path);
+					$data = $cache->get($internalPath);
 					$this->unlockFile($directory, ILockingProvider::LOCK_SHARED);
-					return array();
 				}
-				$scanner = $storage->getScanner($internalPath);
-				$scanner->scan($internalPath, Cache\Scanner::SCAN_SHALLOW);
-				$data = $cache->get($internalPath);
-				$this->unlockFile($directory, ILockingProvider::LOCK_SHARED);
-			} else if ($watcher->needsUpdate($internalPath, $data)) {
-				$this->lockFile($directory, ILockingProvider::LOCK_SHARED);
-				$watcher->update($internalPath, $data);
-				$this->updater->propagate($path);
-				$data = $cache->get($internalPath);
-				$this->unlockFile($directory, ILockingProvider::LOCK_SHARED);
+			} catch (LockedException $e) {
+				// if the file is locked we just use the old cache info
 			}
 
 			$folderId = $data['fileid'];
-- 
GitLab