diff options
author | Robin Appelman <icewind@owncloud.com> | 2014-03-27 16:43:34 +0100 |
---|---|---|
committer | Robin Appelman <icewind@owncloud.com> | 2014-04-03 14:48:30 +0200 |
commit | d3926b8d5e43a4fc17c4e46eb142f70b6a939739 (patch) | |
tree | 204d3162b6b2898bfc22ad867f9ae0cc0d86ca1f /lib | |
parent | 140a65e11b4a6e42e1069c1cc5c32a0a7f6aa61b (diff) | |
download | nextcloud-server-d3926b8d5e43a4fc17c4e46eb142f70b6a939739.tar.gz nextcloud-server-d3926b8d5e43a4fc17c4e46eb142f70b6a939739.zip |
Give storages the option to implement the getById behaviour for View->getPath
Diffstat (limited to 'lib')
-rw-r--r-- | lib/files/cache/cache.php | 17 | ||||
-rw-r--r-- | lib/files/view.php | 16 |
2 files changed, 28 insertions, 5 deletions
diff --git a/lib/files/cache/cache.php b/lib/files/cache/cache.php index c8fa27e402b..d62a904648f 100644 --- a/lib/files/cache/cache.php +++ b/lib/files/cache/cache.php @@ -662,6 +662,23 @@ 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 + * + * @param int $id * @return array, first element holding the storage id, second the path */ static public function getById($id) { diff --git a/lib/files/view.php b/lib/files/view.php index 19dea87e3bc..3d5d45703e7 100644 --- a/lib/files/view.php +++ b/lib/files/view.php @@ -1059,15 +1059,21 @@ class View { * @return string */ public function getPath($id) { - list($storage, $internalPath) = Cache\Cache::getById($id); - $mounts = Mount::findByStorageId($storage); + $mounts = Mount::findIn($this->fakeRoot); + $mounts[] = Mount::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 */ - $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; |