diff --git a/apps/files_sharing/lib_share.php b/apps/files_sharing/lib_share.php
index b03720b75372d18a0d04a7f8e7ddace6f5c29b50..77b0bc4a70c1e99e5770d471ad528907fc8d98a0 100644
--- a/apps/files_sharing/lib_share.php
+++ b/apps/files_sharing/lib_share.php
@@ -82,6 +82,8 @@ class OC_SHARE {
 	 * @return source path
 	 */
 	public static function getSource($target) {
+		// Remove any trailing '/'
+		$target = rtrim($target, "/");
 		$query = OC_DB::prepare("SELECT source FROM *PREFIX*sharing WHERE target = ? AND uid_shared_with = ? LIMIT 1");
 		$result = $query->execute(array($target, $_SESSION['user_id']))->fetchAll();
 		if (count($result) > 0) {
@@ -89,7 +91,7 @@ class OC_SHARE {
 		} else {
 			// Check if the parent directory of this target is shared
 			$parentDir = dirname($target);
-			if ($parentDir != ".") {
+			if ($parentDir != "" && $parentDir != "/" && $parentDir != ".") {
 				$result = OC_SHARE::getSource($parentDir);
 				if ($result) {
 					return $result."/".basename($target);
diff --git a/apps/files_sharing/sharedstorage.php b/apps/files_sharing/sharedstorage.php
index e17685a09e7a19440eb22ca470995d66871fd60d..0303cce79fb22979ecead5efd517233ce0362673 100644
--- a/apps/files_sharing/sharedstorage.php
+++ b/apps/files_sharing/sharedstorage.php
@@ -43,22 +43,13 @@ class OC_FILESTORAGE_SHARED {
 	}
 	
 	public function getSource($target) {
-		if ($target == "") {
-			return false;
-		} elseif (array_key_exists($target, $this->sourcePaths)) {
+		$target = OC_FILESYSTEM::getStorageMountPoint($this).$target;
+		if (array_key_exists($target, $this->sourcePaths)) {
 			return $this->sourcePaths[$target];
 		} else {
-			$parentDir = dirname($target);
-			if ($parentDir != ".") {
-				$source = $this->getSource($parentDir);
-				return $source."/".basename($target);
-			} else {
-				$source = OC_SHARE::getSource($target);
-				if ($source) {
-					$this->sourcePaths[$target] = $source;
-				}
-				return $source;
-			}
+			$source = OC_SHARE::getSource($target);
+			$this->sourcePaths[$target] = $source;
+			return $source;
 		}
 	}
 	
diff --git a/lib/filesystem.php b/lib/filesystem.php
index 4116cb931643ebbf406c9abd6f645c7a9bed0870..c7e2070fa0a8b422cd683cc9a56374b633c5a799 100644
--- a/lib/filesystem.php
+++ b/lib/filesystem.php
@@ -214,6 +214,16 @@ class OC_FILESYSTEM{
 		}
 		return $foundMountPoint;
 	}
+	
+	/**
+	* get the mountpoint of the storage object
+	* @param OC_FILESTORAGE storage
+	* @return string
+	*/
+	static public function getStorageMountPoint($storage){
+		return array_search($storage, self::$storages);
+	}
+	
 	/**
 	* return the path to a local version of the file
 	* we need this because we can't know if a file is stored local or not from outside the filestorage and for some purposes a local file is needed