diff --git a/apps/files_sharing/lib/cache.php b/apps/files_sharing/lib/cache.php
index bb62e8078ad24d254d0d53f9ff03b72c9649b1f3..c25dc92409f04e890750d086fa9c5c86a05e6532 100644
--- a/apps/files_sharing/lib/cache.php
+++ b/apps/files_sharing/lib/cache.php
@@ -60,7 +60,7 @@ class Shared_Cache extends Cache {
 		if ($target === false || $target === $this->storage->getMountPoint()) {
 			$target = '';
 		}
-		$source = \OC_Share_Backend_File::getSource($target, $this->storage->getMountPoint(), $this->storage->getItemType());
+		$source = \OC_Share_Backend_File::getSource($target, $this->storage->getShare());
 		if (isset($source['path']) && isset($source['fileOwner'])) {
 			\OC\Files\Filesystem::initMountPoints($source['fileOwner']);
 			$mounts = \OC\Files\Filesystem::getMountByNumericId($source['storage']);
@@ -242,7 +242,7 @@ class Shared_Cache extends Cache {
 	 */
 	protected function getMoveInfo($path) {
 		$cache = $this->getSourceCache($path);
-		$file = \OC_Share_Backend_File::getSource($path, $this->storage->getMountPoint(), $this->storage->getItemType());
+		$file = \OC_Share_Backend_File::getSource($path, $this->storage->getShare());
 		return [$cache->getNumericStorageId(), $file['path']];
 	}
 
diff --git a/apps/files_sharing/lib/share/file.php b/apps/files_sharing/lib/share/file.php
index 9c09e05408b4eab9517d5120f9c1459afc5ef405..7bbc2083702bb322ed5e2b93bbaa6e22848a1d02 100644
--- a/apps/files_sharing/lib/share/file.php
+++ b/apps/files_sharing/lib/share/file.php
@@ -206,27 +206,15 @@ class OC_Share_Backend_File implements OCP\Share_Backend_File_Dependent {
 
 	/**
 	 * @param string $target
-	 * @param string $mountPoint
-	 * @param string $itemType
+	 * @param array $share
 	 * @return array|false source item
 	 */
-	public static function getSource($target, $mountPoint, $itemType) {
-		if ($itemType === 'folder') {
-			$source = \OCP\Share::getItemSharedWith('folder', $mountPoint, \OC_Share_Backend_File::FORMAT_SHARED_STORAGE);
-			if ($source && $target !== '') {
-				// note: in case of ext storage mount points the path might be empty
-				// which would cause a leading slash to appear
-				$source['path'] = ltrim($source['path'] . '/' . $target, '/');
-			}
-		} else {
-			$source = \OCP\Share::getItemSharedWith('file', $mountPoint, \OC_Share_Backend_File::FORMAT_SHARED_STORAGE);
-		}
-		if ($source) {
-			return self::resolveReshares($source);
+	public static function getSource($target, $share) {
+		if ($share['item_type'] === 'folder' && $target !== '') {
+			// note: in case of ext storage mount points the path might be empty
+			// which would cause a leading slash to appear
+			$share['path'] = ltrim($share['path'] . '/' . $target, '/');
 		}
-
-		\OCP\Util::writeLog('files_sharing', 'File source not found for: '.$target, \OCP\Util::DEBUG);
-		return false;
+		return self::resolveReshares($share);
 	}
-
 }
diff --git a/apps/files_sharing/lib/sharedstorage.php b/apps/files_sharing/lib/sharedstorage.php
index ff01489d77b355444b4dafd59ccf6106be78b228..66803db1425b8f80351a45c45d2ee5e32cdacc83 100644
--- a/apps/files_sharing/lib/sharedstorage.php
+++ b/apps/files_sharing/lib/sharedstorage.php
@@ -83,14 +83,14 @@ class Shared extends \OC\Files\Storage\Common implements ISharedStorage {
 		if (!isset($this->files[$target])) {
 			// Check for partial files
 			if (pathinfo($target, PATHINFO_EXTENSION) === 'part') {
-				$source = \OC_Share_Backend_File::getSource(substr($target, 0, -5), $this->getMountPoint(), $this->getItemType());
+				$source = \OC_Share_Backend_File::getSource(substr($target, 0, -5), $this->getShare());
 				if ($source) {
 					$source['path'] .= '.part';
 					// All partial files have delete permission
 					$source['permissions'] |= \OCP\Constants::PERMISSION_DELETE;
 				}
 			} else {
-				$source = \OC_Share_Backend_File::getSource($target, $this->getMountPoint(), $this->getItemType());
+				$source = \OC_Share_Backend_File::getSource($target, $this->getShare());
 			}
 			$this->files[$target] = $source;
 		}
diff --git a/apps/files_sharing/tests/sharedstorage.php b/apps/files_sharing/tests/sharedstorage.php
index 7c28d0431e11316d0361630ec4d3d38100327808..de510cf1eec362771d2e5471bd3d9b85a070515b 100644
--- a/apps/files_sharing/tests/sharedstorage.php
+++ b/apps/files_sharing/tests/sharedstorage.php
@@ -441,4 +441,43 @@ class Test_Files_Sharing_Storage extends OCA\Files_sharing\Tests\TestCase {
 		self::loginHelper(self::TEST_FILES_SHARING_API_USER1);
 		$this->view->unlink($this->folder);
 	}
+
+	public function testNameConflict() {
+		self::loginHelper(self::TEST_FILES_SHARING_API_USER1);
+		$view1 = new \OC\Files\View('/' . self::TEST_FILES_SHARING_API_USER1 . '/files');
+		$view1->mkdir('foo');
+		$folderInfo1 = $view1->getFileInfo('foo');
+
+		self::loginHelper(self::TEST_FILES_SHARING_API_USER3);
+		$view3 = new \OC\Files\View('/' . self::TEST_FILES_SHARING_API_USER3 . '/files');
+		$view3->mkdir('foo');
+		$folderInfo2 = $view3->getFileInfo('foo');
+
+		// share a folder with the same name from two different users to the same user
+		self::loginHelper(self::TEST_FILES_SHARING_API_USER1);
+
+		\OCP\Share::shareItem('folder', $folderInfo1['fileid'], \OCP\Share::SHARE_TYPE_GROUP,
+			self::TEST_FILES_SHARING_API_GROUP1, 31);
+
+		self::loginHelper(self::TEST_FILES_SHARING_API_USER2);
+
+		self::loginHelper(self::TEST_FILES_SHARING_API_USER3);
+
+		\OCP\Share::shareItem('folder', $folderInfo2['fileid'], \OCP\Share::SHARE_TYPE_GROUP,
+			self::TEST_FILES_SHARING_API_GROUP1, 31);
+
+		self::loginHelper(self::TEST_FILES_SHARING_API_USER2);
+		$view2 = new \OC\Files\View('/' . self::TEST_FILES_SHARING_API_USER2 . '/files');
+
+		$this->assertTrue($view2->file_exists('/foo'));
+		$this->assertTrue($view2->file_exists('/foo (2)'));
+
+		$mount = $view2->getMount('/foo');
+		$this->assertInstanceOf('\OCA\Files_Sharing\SharedMount', $mount);
+		/** @var \OC\Files\Storage\Shared $storage */
+		$storage = $mount->getStorage();
+
+		$source = $storage->getFile('');
+		$this->assertEquals(self::TEST_FILES_SHARING_API_USER1, $source['uid_owner']);
+	}
 }