aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRobin Appelman <icewind@owncloud.com>2012-10-26 12:30:25 +0200
committerRobin Appelman <icewind@owncloud.com>2012-10-26 12:30:25 +0200
commit39adadd3e3e50dcf3bf577a22870aaec52f63052 (patch)
treea2358c00ee236a76c0691bf5211fcfbc4a44c1ab
parent0e2bf8d37396748d29d24b6a0789fa85b4c58f20 (diff)
downloadnextcloud-server-39adadd3e3e50dcf3bf577a22870aaec52f63052.tar.gz
nextcloud-server-39adadd3e3e50dcf3bf577a22870aaec52f63052.zip
move the cache api from OC_Files to filesystem(view)
-rw-r--r--lib/files.php92
-rw-r--r--lib/files/cache/cache.php5
-rw-r--r--lib/files/filesystem.php27
-rw-r--r--lib/files/view.php92
-rw-r--r--tests/lib/files/view.php (renamed from tests/lib/files.php)23
5 files changed, 138 insertions, 101 deletions
diff --git a/lib/files.php b/lib/files.php
index 7ab7c89201a..422e7f4ffe7 100644
--- a/lib/files.php
+++ b/lib/files.php
@@ -28,98 +28,6 @@
class OC_Files {
static $tmpFiles = array();
- /**
- * get the filesystem info
- *
- * @param string $path
- * @return array
- *
- * returns an associative array with the following keys:
- * - size
- * - mtime
- * - mimetype
- * - encrypted
- * - versioned
- */
- public static function getFileInfo($path) {
- $path = \OC\Files\Filesystem::normalizePath($path);
- /**
- * @var \OC\Files\Storage\Storage $storage
- * @var string $path
- */
- list($storage, $internalPath) = \OC\Files\Filesystem::resolvePath($path);
- $cache = $storage->getCache();
-
- if (!$cache->inCache($internalPath)) {
- $scanner = $storage->getScanner();
- $scanner->scan($internalPath, \OC\Files\Cache\Scanner::SCAN_SHALLOW);
- }
-
- $data = $cache->get($internalPath);
-
- if ($data['mimetype'] === 'httpd/unix-directory') {
- //add the sizes of other mountpoints to the folder
- $mountPoints = \OC\Files\Filesystem::getMountPoints($path);
- foreach ($mountPoints as $mountPoint) {
- $subStorage = \OC\Files\Filesystem::getStorage($mountPoint);
- $subCache = $subStorage->getCache();
- $rootEntry = $subCache->get('');
-
- $data['size'] += $rootEntry['size'];
- }
- }
-
- return $data;
- }
-
- /**
- * get the content of a directory
- *
- * @param string $directory path under datadirectory
- * @return array
- */
- public static function getDirectoryContent($directory, $mimetype_filter = '') {
- $path = \OC\Files\Filesystem::normalizePath($directory);
- /**
- * @var \OC\Files\Storage\Storage $storage
- * @var string $path
- */
- list($storage, $internalPath) = \OC\Files\Filesystem::resolvePath($path);
- $cache = $storage->getCache();
-
- if (!$cache->inCache($internalPath)) {
- $scanner = $storage->getScanner();
- $scanner->scan($internalPath, \OC\Files\Cache\Scanner::SCAN_SHALLOW);
- }
-
- $files = $cache->getFolderContents($internalPath); //TODO: mimetype_filter
-
- //add a folder for any mountpoint in this directory and add the sizes of other mountpoints to the folders
- $mountPoints = \OC\Files\Filesystem::getMountPoints($directory);
- $dirLength = strlen($path);
- foreach ($mountPoints as $mountPoint) {
- $subStorage = \OC\Files\Filesystem::getStorage($mountPoint);
- $subCache = $subStorage->getCache();
- $rootEntry = $subCache->get('');
-
- $relativePath = trim(substr($mountPoint, $dirLength), '/');
- if ($pos = strpos($relativePath, '/')) { //mountpoint inside subfolder add size to the correct folder
- $entryName = substr($relativePath, 0, $pos);
- foreach ($files as &$entry) {
- if ($entry['name'] === $entryName) {
- $entry['size'] += $rootEntry['size'];
- }
- }
- } else { //mountpoint in this folder, add an entry for it
- $rootEntry['name'] = $relativePath;
- $files[] = $rootEntry;
- }
- }
-
- usort($files, "fileCmp"); //TODO: remove this once ajax is merged
- return $files;
- }
-
public static function searchByMime($mimetype_filter) {
$files = array();
$dirs_to_check = array('');
diff --git a/lib/files/cache/cache.php b/lib/files/cache/cache.php
index 5ef49246ea5..9b55666f959 100644
--- a/lib/files/cache/cache.php
+++ b/lib/files/cache/cache.php
@@ -8,6 +8,11 @@
namespace OC\Files\Cache;
+/**
+ * Metadata cache for the filesystem
+ *
+ * don't use this class directly if you need to get metadata, use \OC\Files\Filesystem::getFileInfo instead
+ */
class Cache {
const NOT_FOUND = 0;
const PARTIAL = 1; //only partial data available, file not cached in the database
diff --git a/lib/files/filesystem.php b/lib/files/filesystem.php
index b7f8483fbf9..d735cf8626a 100644
--- a/lib/files/filesystem.php
+++ b/lib/files/filesystem.php
@@ -609,6 +609,33 @@ class Filesystem {
}
return $path;
}
+
+ /**
+ * get the filesystem info
+ *
+ * @param string $path
+ * @return array
+ *
+ * returns an associative array with the following keys:
+ * - size
+ * - mtime
+ * - mimetype
+ * - encrypted
+ * - versioned
+ */
+ public static function getFileInfo($path) {
+ return self::$defaultInstance->getFileInfo($path);
+ }
+
+ /**
+ * get the content of a directory
+ *
+ * @param string $directory path under datadirectory
+ * @return array
+ */
+ public static function getDirectoryContent($directory, $mimetype_filter = '') {
+ return self::$defaultInstance->getDirectoryContent($directory, $mimetype_filter);
+ }
}
\OC_Hook::connect('OC_Filesystem', 'post_write', 'OC_Filesystem', 'removeETagHook');
diff --git a/lib/files/view.php b/lib/files/view.php
index 18d9193035e..aaca1618acb 100644
--- a/lib/files/view.php
+++ b/lib/files/view.php
@@ -645,4 +645,96 @@ class View {
public function hasUpdated($path, $time) {
return $this->basicOperation('hasUpdated', $path, array(), $time);
}
+
+ /**
+ * get the filesystem info
+ *
+ * @param string $path
+ * @return array
+ *
+ * returns an associative array with the following keys:
+ * - size
+ * - mtime
+ * - mimetype
+ * - encrypted
+ * - versioned
+ */
+ public function getFileInfo($path) {
+ $path = \OC\Files\Filesystem::normalizePath($this->fakeRoot . '/' . $path);
+ /**
+ * @var \OC\Files\Storage\Storage $storage
+ * @var string $path
+ */
+ list($storage, $internalPath) = \OC\Files\Filesystem::resolvePath($path);
+ $cache = $storage->getCache();
+
+ if (!$cache->inCache($internalPath)) {
+ $scanner = $storage->getScanner();
+ $scanner->scan($internalPath, \OC\Files\Cache\Scanner::SCAN_SHALLOW);
+ }
+
+ $data = $cache->get($internalPath);
+
+ if ($data['mimetype'] === 'httpd/unix-directory') {
+ //add the sizes of other mountpoints to the folder
+ $mountPoints = \OC\Files\Filesystem::getMountPoints($path);
+ foreach ($mountPoints as $mountPoint) {
+ $subStorage = \OC\Files\Filesystem::getStorage($mountPoint);
+ $subCache = $subStorage->getCache();
+ $rootEntry = $subCache->get('');
+
+ $data['size'] += $rootEntry['size'];
+ }
+ }
+
+ return $data;
+ }
+
+ /**
+ * get the content of a directory
+ *
+ * @param string $directory path under datadirectory
+ * @return array
+ */
+ public function getDirectoryContent($directory, $mimetype_filter = '') {
+ $path = \OC\Files\Filesystem::normalizePath($this->fakeRoot . '/' . $directory);
+ /**
+ * @var \OC\Files\Storage\Storage $storage
+ * @var string $path
+ */
+ list($storage, $internalPath) = \OC\Files\Filesystem::resolvePath($path);
+ $cache = $storage->getCache();
+
+ if (!$cache->inCache($internalPath)) {
+ $scanner = $storage->getScanner();
+ $scanner->scan($internalPath, \OC\Files\Cache\Scanner::SCAN_SHALLOW);
+ }
+
+ $files = $cache->getFolderContents($internalPath); //TODO: mimetype_filter
+
+ //add a folder for any mountpoint in this directory and add the sizes of other mountpoints to the folders
+ $mountPoints = \OC\Files\Filesystem::getMountPoints($directory);
+ $dirLength = strlen($path);
+ foreach ($mountPoints as $mountPoint) {
+ $subStorage = \OC\Files\Filesystem::getStorage($mountPoint);
+ $subCache = $subStorage->getCache();
+ $rootEntry = $subCache->get('');
+
+ $relativePath = trim(substr($mountPoint, $dirLength), '/');
+ if ($pos = strpos($relativePath, '/')) { //mountpoint inside subfolder add size to the correct folder
+ $entryName = substr($relativePath, 0, $pos);
+ foreach ($files as &$entry) {
+ if ($entry['name'] === $entryName) {
+ $entry['size'] += $rootEntry['size'];
+ }
+ }
+ } else { //mountpoint in this folder, add an entry for it
+ $rootEntry['name'] = $relativePath;
+ $files[] = $rootEntry;
+ }
+ }
+
+ usort($files, "fileCmp"); //TODO: remove this once ajax is merged
+ return $files;
+ }
}
diff --git a/tests/lib/files.php b/tests/lib/files/view.php
index d978ac3fd13..6e7608f596b 100644
--- a/tests/lib/files.php
+++ b/tests/lib/files/view.php
@@ -5,9 +5,11 @@
* later.
* See the COPYING-README file. */
+namespace Test\Files;
+
use \OC\Files\Filesystem as Filesystem;
-class Test_Files extends PHPUnit_Framework_TestCase {
+class View extends \PHPUnit_Framework_TestCase {
/**
* @var \OC\Files\Storage\Storage[] $storages;
*/
@@ -35,19 +37,21 @@ class Test_Files extends PHPUnit_Framework_TestCase {
$imageSize = filesize(\OC::$SERVERROOT . '/core/img/logo.png');
$storageSize = $textSize * 2 + $imageSize;
- $cachedData = OC_Files::getFileInfo('/foo.txt');
+ $rootView = new \OC\Files\View('');
+
+ $cachedData = $rootView->getFileInfo('/foo.txt');
$this->assertEquals($textSize, $cachedData['size']);
$this->assertEquals('text/plain', $cachedData['mimetype']);
- $cachedData = OC_Files::getFileInfo('/');
+ $cachedData = $rootView->getFileInfo('/');
$this->assertEquals($storageSize * 3, $cachedData['size']);
$this->assertEquals('httpd/unix-directory', $cachedData['mimetype']);
- $cachedData = OC_Files::getFileInfo('/folder');
+ $cachedData = $rootView->getFileInfo('/folder');
$this->assertEquals($storageSize + $textSize, $cachedData['size']);
$this->assertEquals('httpd/unix-directory', $cachedData['mimetype']);
- $folderData = OC_Files::getDirectoryContent('/');
+ $folderData = $rootView->getDirectoryContent('/');
/**
* expected entries:
* folder
@@ -74,20 +78,21 @@ class Test_Files extends PHPUnit_Framework_TestCase {
Filesystem::mount($storage2, array(), '/substorage');
$textSize = strlen("dummy file data\n");
$imageSize = filesize(\OC::$SERVERROOT . '/core/img/logo.png');
- $storageSize = $textSize * 2 + $imageSize;
- $cachedData = \OC_Files::getFileInfo('/');
+ $rootView = new \OC\Files\View('');
+
+ $cachedData = $rootView->getFileInfo('/');
$this->assertEquals('httpd/unix-directory', $cachedData['mimetype']);
$this->assertEquals(-1, $cachedData['size']);
- $folderData = \OC_Files::getDirectoryContent('/substorage/folder');
+ $folderData = $rootView->getDirectoryContent('/substorage/folder');
$this->assertEquals('text/plain', $folderData[0]['mimetype']);
$this->assertEquals($textSize, $folderData[0]['size']);
}
/**
* @param bool $scan
- * @return OC\Files\Storage\Storage
+ * @return \OC\Files\Storage\Storage
*/
private function getTestStorage($scan = true) {
$storage = new \OC\Files\Storage\Temporary(array());