From bcebfbfbe229b5fdb1cfc1c058e11e78550ff088 Mon Sep 17 00:00:00 2001
From: Robin Appelman <icewind@owncloud.com>
Date: Wed, 8 Feb 2012 17:29:54 +0100
Subject: [PATCH] bugfix in searching files by mimetype

---
 lib/filecache.php | 22 +++++++++++++++-------
 1 file changed, 15 insertions(+), 7 deletions(-)

diff --git a/lib/filecache.php b/lib/filecache.php
index 964099c7fc..a053e4cbc1 100644
--- a/lib/filecache.php
+++ b/lib/filecache.php
@@ -466,6 +466,7 @@ class OC_FileCache{
 	 * fine files by mimetype
 	 * @param string $part1
 	 * @param string $part2 (optional)
+	 * @param string root (optional)
 	 * @return array of file paths
 	 *
 	 * $part1 and $part2 together form the complete mimetype.
@@ -474,17 +475,24 @@ class OC_FileCache{
 	 * seccond mimetype part can be ommited
 	 * e.g. searchByMime('audio')
 	 */
-	public static function searchByMime($part1,$part2=''){
-		if($part2){
-			$query=OC_DB::prepare('SELECT path FROM *PREFIX*fscache WHERE mimepart=?');
-			$result=$query->execute(array($part1));
+	public static function searchByMime($part1,$part2='',$root=''){
+		if(!$root){
+			$root=OC_Filesystem::getRoot();
+		}elseif($root='/'){
+			$root='';
+		}
+		$rootLen=strlen($root);
+		$user=OC_User::getUser();
+		if(!$part2){
+			$query=OC_DB::prepare('SELECT path FROM *PREFIX*fscache WHERE mimepart=? AND user=?');
+			$result=$query->execute(array($part1,$user));
 		}else{
-			$query=OC_DB::prepare('SELECT path FROM *PREFIX*fscache WHERE mimetype=?');
-			$result=$query->execute(array($part1.'/'.$part2));
+			$query=OC_DB::prepare('SELECT path FROM *PREFIX*fscache WHERE mimetype=? AND user=?');
+			$result=$query->execute(array($part1.'/'.$part2,$user));
 		}
 		$names=array();
 		while($row=$result->fetchRow()){
-			$names[]=$row['path'];
+			$names[]=substr($row['path'],$rootLen);
 		}
 		return $names;
 	}
-- 
GitLab