From 5bfff6c56e8d4d911c7a5265bb5462c7122ca495 Mon Sep 17 00:00:00 2001
From: Robin Appelman <icewind@owncloud.com>
Date: Sat, 27 Oct 2012 12:17:35 +0200
Subject: [PATCH] use absolute paths when resolving mount points

---
 lib/files.php                   | 10 ----------
 lib/files/cache/permissions.php |  3 +++
 lib/files/view.php              | 35 ++++++++++++++++++++++++---------
 lib/public/share.php            |  4 ++--
 4 files changed, 31 insertions(+), 21 deletions(-)

diff --git a/lib/files.php b/lib/files.php
index 28df2255809..e6b324f062b 100644
--- a/lib/files.php
+++ b/lib/files.php
@@ -249,13 +249,3 @@ class OC_Files {
 		return false;
 	}
 }
-
-function fileCmp($a, $b) {
-	if ($a['type'] == 'dir' and $b['type'] != 'dir') {
-		return -1;
-	} elseif ($a['type'] != 'dir' and $b['type'] == 'dir') {
-		return 1;
-	} else {
-		return strnatcasecmp($a['name'], $b['name']);
-	}
-}
diff --git a/lib/files/cache/permissions.php b/lib/files/cache/permissions.php
index e3fa63c464a..dd7233abc70 100644
--- a/lib/files/cache/permissions.php
+++ b/lib/files/cache/permissions.php
@@ -50,6 +50,9 @@ class Permissions {
 	 * @return int[]
 	 */
 	static public function getMultiple($fileIds, $user) {
+		if (count($fileIds) === 0) {
+			return array();
+		}
 		$params = $fileIds;
 		$params[] = $user;
 		$inPart = implode(', ', array_fill(0, count($fileIds), '?'));
diff --git a/lib/files/view.php b/lib/files/view.php
index 0a5a6436c27..0f9a5feb5dd 100644
--- a/lib/files/view.php
+++ b/lib/files/view.php
@@ -110,6 +110,7 @@ class View {
 	 */
 	public function getLocalFile($path) {
 		$parent = substr($path, 0, strrpos($path, '/'));
+		$path = $this->getAbsolutePath($path);
 		list($storage, $internalPath) = Filesystem::resolvePath($path);
 		if (Filesystem::isValidPath($parent) and $storage) {
 			return $storage->getLocalFile($internalPath);
@@ -124,6 +125,7 @@ class View {
 	 */
 	public function getLocalFolder($path) {
 		$parent = substr($path, 0, strrpos($path, '/'));
+		$path = $this->getAbsolutePath($path);
 		list($storage, $internalPath) = Filesystem::resolvePath($path);
 		if (Filesystem::isValidPath($parent) and $storage) {
 			return $storage->getLocalFolder($internalPath);
@@ -334,8 +336,8 @@ class View {
 				$mp1 = $this->getMountPoint($path1 . $postFix1);
 				$mp2 = $this->getMountPoint($path2 . $postFix2);
 				if ($mp1 == $mp2) {
-					list($storage, $internalPath1) = Filesystem::resolvePath($path1 . $postFix1);
-					list(, $internalPath2) = Filesystem::resolvePath($path2 . $postFix2);
+					list($storage, $internalPath1) = Filesystem::resolvePath($absolutePath1 . $postFix1);
+					list(, $internalPath2) = Filesystem::resolvePath($absolutePath2 . $postFix2);
 					if ($storage) {
 						$result = $storage->rename($internalPath1, $internalPath2);
 					} else {
@@ -345,7 +347,7 @@ class View {
 					$source = $this->fopen($path1 . $postFix1, 'r');
 					$target = $this->fopen($path2 . $postFix2, 'w');
 					$count = \OC_Helper::streamCopy($source, $target);
-					list($storage1, $internalPath1) = Filesystem::resolvePath($path1 . $postFix1);
+					list($storage1, $internalPath1) = Filesystem::resolvePath($absolutePath1 . $postFix1);
 					$storage1->unlink($internalPath1);
 					$result = $count > 0;
 				}
@@ -417,8 +419,8 @@ class View {
 				$mp1 = $this->getMountPoint($path1 . $postFix1);
 				$mp2 = $this->getMountPoint($path2 . $postFix2);
 				if ($mp1 == $mp2) {
-					list($storage, $internalPath1) = Filesystem::resolvePath($path1 . $postFix1);
-					list(, $internalPath2) = Filesystem::resolvePath($path2 . $postFix2);
+					list($storage, $internalPath1) = Filesystem::resolvePath($absolutePath1 . $postFix1);
+					list(, $internalPath2) = Filesystem::resolvePath($absolutePath2 . $postFix2);
 					if ($storage) {
 						$result = $storage->copy($internalPath1, $internalPath2);
 					} else {
@@ -552,7 +554,7 @@ class View {
 					array(Filesystem::signal_param_path => $path)
 				);
 			}
-			list($storage, $internalPath) = Filesystem::resolvePath($path . $postFix);
+			list($storage, $internalPath) = Filesystem::resolvePath($absolutePath . $postFix);
 			if ($storage) {
 				$result = $storage->hash($type, $internalPath, $raw);
 				$result = \OC_FileProxy::runPostProxies('hash', $absolutePath, $result);
@@ -587,7 +589,7 @@ class View {
 				return false;
 			}
 			$run = $this->runHooks($hooks, $path);
-			list($storage, $internalPath) = Filesystem::resolvePath($path . $postFix);
+			list($storage, $internalPath) = Filesystem::resolvePath($absolutePath . $postFix);
 			if ($run and $storage) {
 				if (!is_null($extraParam)) {
 					$result = $storage->$operation($internalPath, $extraParam);
@@ -747,8 +749,23 @@ class View {
 			$files[$i]['permissions'] = $permissions[$file['fileid']];
 		}
 
-		usort($files, "fileCmp");
-		return $files;
+		if ($mimetype_filter) {
+			foreach ($files as $file) {
+				if (strpos($mimetype_filter, '/')) {
+					if ($file['mimetype'] === $mimetype_filter) {
+						$result[] = $file;
+					}
+				} else {
+					if ($file['mimepart'] === $mimetype_filter) {
+						$result[] = $file;
+					}
+				}
+			}
+		} else {
+			$result = $files;
+		}
+
+		return $result;
 	}
 
 	/**
diff --git a/lib/public/share.php b/lib/public/share.php
index 060f67c9e91..707d5abe440 100644
--- a/lib/public/share.php
+++ b/lib/public/share.php
@@ -534,7 +534,7 @@ class Share {
 		$backend = self::getBackend($itemType);
 		// Get filesystem root to add it to the file target and remove from the file source, match file_source with the file cache
 		if ($itemType == 'file' || $itemType == 'folder') {
-			$root = \OC_Filesystem::getRoot();
+			$root = \OC\Files\Filesystem::getRoot();
 			$where = 'INNER JOIN `*PREFIX*fscache` ON `file_source` = `*PREFIX*fscache`.`id`';
 			if (!isset($item)) {
 				$where .= ' WHERE `file_target` IS NOT NULL';
@@ -621,7 +621,7 @@ class Share {
 			} else {
 				if ($itemType == 'file' || $itemType == 'folder') {
 					$where .= ' `file_target` = ?';
-					$item = \OC_Filesystem::normalizePath($item);
+					$item = \OC\Files\Filesystem::normalizePath($item);
 				} else {
 					$where .= ' `item_target` = ?';
 				}
-- 
GitLab