From 6fb553e92cd62926134f4f77a3069fa4439835fe Mon Sep 17 00:00:00 2001
From: Vincent Petry <pvince81@owncloud.com>
Date: Wed, 21 Jan 2015 22:27:59 +0100
Subject: [PATCH] Do not call wrapStorage if storate with same name added twice

---
 lib/private/files/filesystem.php             | 5 ++++-
 lib/private/files/storage/storagefactory.php | 6 ++++++
 lib/public/files/storage/istoragefactory.php | 2 ++
 3 files changed, 12 insertions(+), 1 deletion(-)

diff --git a/lib/private/files/filesystem.php b/lib/private/files/filesystem.php
index f90b2738d0..0a0c5c3612 100644
--- a/lib/private/files/filesystem.php
+++ b/lib/private/files/filesystem.php
@@ -175,7 +175,10 @@ class Filesystem {
 	 * @param callable $wrapper
 	 */
 	public static function addStorageWrapper($wrapperName, $wrapper) {
-		self::getLoader()->addStorageWrapper($wrapperName, $wrapper);
+		if (!self::getLoader()->addStorageWrapper($wrapperName, $wrapper)) {
+			// do not re-wrap if storage with this name already existed
+			return;
+		}
 
 		$mounts = self::getMountManager()->getAll();
 		foreach ($mounts as $mount) {
diff --git a/lib/private/files/storage/storagefactory.php b/lib/private/files/storage/storagefactory.php
index c9e8d422f9..9c1c7325b7 100644
--- a/lib/private/files/storage/storagefactory.php
+++ b/lib/private/files/storage/storagefactory.php
@@ -23,9 +23,15 @@ class StorageFactory implements IStorageFactory {
 	 *
 	 * @param string $wrapperName
 	 * @param callable $callback
+	 * @return true if the wrapper was added, false if there was already a wrapper with this
+	 * name registered
 	 */
 	public function addStorageWrapper($wrapperName, $callback) {
+		if (isset($this->storageWrappers[$wrapperName])) {
+			return false;
+		}
 		$this->storageWrappers[$wrapperName] = $callback;
+		return true;
 	}
 
 	/**
diff --git a/lib/public/files/storage/istoragefactory.php b/lib/public/files/storage/istoragefactory.php
index 769d7011de..48c12e44cd 100644
--- a/lib/public/files/storage/istoragefactory.php
+++ b/lib/public/files/storage/istoragefactory.php
@@ -19,6 +19,8 @@ interface IStorageFactory {
 	 *
 	 * @param string $wrapperName
 	 * @param callable $callback
+	 * @return true if the wrapper was added, false if there was already a wrapper with this
+	 * name registered
 	 */
 	public function addStorageWrapper($wrapperName, $callback);
 
-- 
GitLab