]> source.dussan.org Git - nextcloud-server.git/commitdiff
Give storages the option to implement the getById behaviour for View->getPath
authorRobin Appelman <icewind@owncloud.com>
Thu, 27 Mar 2014 15:43:34 +0000 (16:43 +0100)
committerRobin Appelman <icewind@owncloud.com>
Fri, 28 Mar 2014 14:15:56 +0000 (15:15 +0100)
lib/private/files/cache/cache.php
lib/private/files/view.php

index abc11e76470f0a6c7498c62dac717d72eec38568..42fee4f336d802ee27e51244ff2718ce3a6c4ff7 100644 (file)
@@ -593,6 +593,22 @@ class Cache {
                }
        }
 
+       /**
+        * get the storage id of the storage for a file and the internal path of the file
+        *
+        * @param int $id
+        * @return string | null
+        */
+       public function getPathById($id) {
+               $sql = 'SELECT `path` FROM `*PREFIX*filecache` WHERE `fileid` = ? AND `storage` = ?';
+               $result = \OC_DB::executeAudited($sql, array($id, $this->getNumericStorageId()));
+               if ($row = $result->fetchRow()) {
+                       return $row['path'];
+               } else {
+                       return null;
+               }
+       }
+
        /**
         * get the storage id of the storage for a file and the internal path of the file
         *
index f06c2fcd66c463c54af5d1efa83326b5fdbd161e..90b0da09c379948862bab20e493b5c826dbe9e2d 100644 (file)
@@ -1129,15 +1129,22 @@ class View {
         * @return string
         */
        public function getPath($id) {
-               list($storage, $internalPath) = Cache\Cache::getById($id);
-               $mounts = Filesystem::getMountByStorageId($storage);
+               $manager = Filesystem::getMountManager();
+               $mounts = $manager->findIn($this->fakeRoot);
+               $mounts[] = $manager->find($this->fakeRoot);
+               // reverse the array so we start with the storage this view is in
+               // which is the most likely to contain the file we're looking for
+               $mounts = array_reverse($mounts);
                foreach ($mounts as $mount) {
                        /**
-                        * @var \OC\Files\Mount $mount
+                        * @var \OC\Files\Mount\Mount $mount
                         */
-                       $fullPath = $mount->getMountPoint() . $internalPath;
-                       if (!is_null($path = $this->getRelativePath($fullPath))) {
-                               return $path;
+                       $cache = $mount->getStorage()->getCache();
+                       if ($internalPath = $cache->getPathById($id)) {
+                               $fullPath = $mount->getMountPoint() . $internalPath;
+                               if (!is_null($path = $this->getRelativePath($fullPath))) {
+                                       return $path;
+                               }
                        }
                }
                return null;