Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nextcloud/server.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRobin Appelman <icewind@owncloud.com>2013-01-27 03:13:16 +0400
committerRobin Appelman <icewind@owncloud.com>2013-01-27 03:13:50 +0400
commit17bcea15855784f00791ab19984d520a773aa0ca (patch)
tree0d81518e44be5ec63d38a7bb9d7f1b742a8a7370
parent9e2a066c7bf04dfcc3e2dcc539e1b33053ba70ed (diff)
Filesystem: add View->getPath to the cache api
-rw-r--r--lib/files/view.php15
-rw-r--r--tests/lib/files/view.php23
2 files changed, 38 insertions, 0 deletions
diff --git a/lib/files/view.php b/lib/files/view.php
index e6b52fb35b6..c2038f222a0 100644
--- a/lib/files/view.php
+++ b/lib/files/view.php
@@ -932,4 +932,19 @@ class View {
return null;
}
}
+
+ /**
+ * Get the path of a file by id, relative to the view
+ *
+ * Note that the resulting path is not guarantied to be unique for the id, multiple paths can point to the same file
+ *
+ * @param int $id
+ * @return string
+ */
+ public function getPath($id) {
+ list($storage, $internalPath) = Cache\Cache::getById($id);
+ $mount = Mount::findById($storage);
+ $fullPath = $mount->getMountPoint() . $internalPath;
+ return $this->getRelativePath($fullPath);
+ }
}
diff --git a/tests/lib/files/view.php b/tests/lib/files/view.php
index 586ad178425..a064e44f3ef 100644
--- a/tests/lib/files/view.php
+++ b/tests/lib/files/view.php
@@ -98,6 +98,29 @@ class View extends \PHPUnit_Framework_TestCase {
$this->assertEquals(array(), $rootView->getDirectoryContent('/non/existing'));
}
+ function testGetPath() {
+ $storage1 = $this->getTestStorage();
+ $storage2 = $this->getTestStorage();
+ $storage3 = $this->getTestStorage();
+ \OC\Files\Filesystem::mount($storage1, array(), '/');
+ \OC\Files\Filesystem::mount($storage2, array(), '/substorage');
+ \OC\Files\Filesystem::mount($storage3, array(), '/folder/anotherstorage');
+
+ $rootView = new \OC\Files\View('');
+
+ $cachedData = $rootView->getFileInfo('/foo.txt');
+ $id1 = $cachedData['fileid'];
+ $this->assertEquals('/foo.txt', $rootView->getPath($id1));
+
+ $cachedData = $rootView->getFileInfo('/substorage/foo.txt');
+ $id2 = $cachedData['fileid'];
+ $this->assertEquals('/substorage/foo.txt', $rootView->getPath($id2));
+
+ $folderView = new \OC\Files\View('/substorage');
+ $this->assertEquals('/foo.txt', $folderView->getPath($id2));
+ $this->assertNull($folderView->getPath($id1));
+ }
+
function testMountPointOverwrite() {
$storage1 = $this->getTestStorage(false);
$storage2 = $this->getTestStorage();