From 8635699db932959ac147193473b014406b0e9e09 Mon Sep 17 00:00:00 2001
From: Robin Appelman <icewind@owncloud.com>
Date: Tue, 11 Dec 2012 01:06:21 +0100
Subject: [PATCH] fix cache behaviour for non existing files

---
 lib/files/view.php              | 28 +++++++++++++++-------------
 tests/lib/files/cache/cache.php |  5 +++++
 tests/lib/files/view.php        |  3 +++
 3 files changed, 23 insertions(+), 13 deletions(-)

diff --git a/lib/files/view.php b/lib/files/view.php
index 468808566a..994dbcc85c 100644
--- a/lib/files/view.php
+++ b/lib/files/view.php
@@ -691,20 +691,22 @@ class View {
 
 			$data = $cache->get($internalPath);
 
-			if ($data['mimetype'] === 'httpd/unix-directory') {
-				//add the sizes of other mountpoints to the folder
-				$mountPoints = Filesystem::getMountPoints($path);
-				foreach ($mountPoints as $mountPoint) {
-					$subStorage = Filesystem::getStorage($mountPoint);
-					$subCache = $subStorage->getCache();
-					$rootEntry = $subCache->get('');
-
-					$data['size'] += $rootEntry['size'];
+			if ($data) {
+				if ($data['mimetype'] === 'httpd/unix-directory') {
+					//add the sizes of other mountpoints to the folder
+					$mountPoints = Filesystem::getMountPoints($path);
+					foreach ($mountPoints as $mountPoint) {
+						$subStorage = Filesystem::getStorage($mountPoint);
+						$subCache = $subStorage->getCache();
+						$rootEntry = $subCache->get('');
+
+						$data['size'] += $rootEntry['size'];
+					}
 				}
-			}
 
-			$permissionsCache = $storage->getPermissionsCache();
-			$data['permissions'] = $permissionsCache->get($data['fileid'], \OC_User::getUser());
+				$permissionsCache = $storage->getPermissionsCache();
+				$data['permissions'] = $permissionsCache->get($data['fileid'], \OC_User::getUser());
+			}
 		}
 		return $data;
 	}
@@ -888,7 +890,7 @@ class View {
 	 * @param string $path
 	 * @return string
 	 */
-	public function getETag($path){
+	public function getETag($path) {
 		/**
 		 * @var Storage\Storage $storage
 		 * @var string $internalPath
diff --git a/tests/lib/files/cache/cache.php b/tests/lib/files/cache/cache.php
index e9105cd5ab..a2b131ac0a 100644
--- a/tests/lib/files/cache/cache.php
+++ b/tests/lib/files/cache/cache.php
@@ -192,6 +192,11 @@ class Cache extends \UnitTestCase {
 		$this->assertEquals($file3, $this->cache->getIncomplete());
 	}
 
+	function testNonExisting() {
+		$this->assertFalse($this->cache->get('foo.txt'));
+		$this->assertEquals(array(), $this->cache->getFolderContents('foo'));
+	}
+
 	public function tearDown() {
 		$this->cache->clear();
 	}
diff --git a/tests/lib/files/view.php b/tests/lib/files/view.php
index ed08dcc114..1b8f6dc1e8 100644
--- a/tests/lib/files/view.php
+++ b/tests/lib/files/view.php
@@ -92,6 +92,9 @@ class View extends \PHPUnit_Framework_TestCase {
 		$cachedData = $rootView->getFileInfo('/foo.txt');
 		$this->assertTrue($cachedData['encrypted']);
 		$this->assertEquals($cachedData['fileid'], $id);
+
+		$this->assertFalse($rootView->getFileInfo('/non/existing'));
+		$this->assertEquals(array(), $rootView->getDirectoryContent('/non/existing'));
 	}
 
 	public function testAutoScan() {
-- 
GitLab