From 7330fcf5e81e7d91ed37f01da7cc45833e10f1c4 Mon Sep 17 00:00:00 2001
From: Robin Appelman <icewind@owncloud.com>
Date: Tue, 22 Jan 2013 20:57:15 +0100
Subject: [PATCH] Cache: make mounts overwrite existing folders, prevents
 duplicate entries

---
 lib/files/view.php       |  8 ++++++++
 tests/lib/files/view.php | 12 ++++++++++++
 2 files changed, 20 insertions(+)

diff --git a/lib/files/view.php b/lib/files/view.php
index 0602791012..c50897603e 100644
--- a/lib/files/view.php
+++ b/lib/files/view.php
@@ -794,6 +794,14 @@ class View {
 								$subPermissionsCache->set($rootEntry['fileid'], $user, $permissions);
 							}
 							$rootEntry['permissions'] = $permissions;
+
+							//remove any existing entry with the same name
+							foreach ($files as $i => $file) {
+								if ($file['name'] === $rootEntry['name']) {
+									unset($files[$i]);
+									break;
+								}
+							}
 							$files[] = $rootEntry;
 						}
 					}
diff --git a/tests/lib/files/view.php b/tests/lib/files/view.php
index 5327114267..586ad17842 100644
--- a/tests/lib/files/view.php
+++ b/tests/lib/files/view.php
@@ -98,6 +98,18 @@ class View extends \PHPUnit_Framework_TestCase {
 		$this->assertEquals(array(), $rootView->getDirectoryContent('/non/existing'));
 	}
 
+	function testMountPointOverwrite() {
+		$storage1 = $this->getTestStorage(false);
+		$storage2 = $this->getTestStorage();
+		$storage1->mkdir('substorage');
+		\OC\Files\Filesystem::mount($storage1, array(), '/');
+		\OC\Files\Filesystem::mount($storage2, array(), '/substorage');
+
+		$rootView = new \OC\Files\View('');
+		$folderContent = $rootView->getDirectoryContent('/');
+		$this->assertEquals(4, count($folderContent));
+	}
+
 	function testCacheIncompleteFolder() {
 		$storage1 = $this->getTestStorage(false);
 		\OC\Files\Filesystem::mount($storage1, array(), '/');
-- 
GitLab