diff options
author | Robin Appelman <icewind@owncloud.com> | 2015-12-02 14:59:13 +0100 |
---|---|---|
committer | Robin Appelman <icewind@owncloud.com> | 2016-01-14 12:54:42 +0100 |
commit | 6d321f5f6b4e22f0c8124572662361a1f53e7c3a (patch) | |
tree | aeea16e4d4174e6491a7de9ad0d207a3cd83c927 /lib | |
parent | 5d0451b84862c2c905b7d1a8d5943ac53d87f990 (diff) | |
download | nextcloud-server-6d321f5f6b4e22f0c8124572662361a1f53e7c3a.tar.gz nextcloud-server-6d321f5f6b4e22f0c8124572662361a1f53e7c3a.zip |
Return a class from cache operations instead of an array
Diffstat (limited to 'lib')
-rw-r--r-- | lib/private/files/cache/cache.php | 64 | ||||
-rw-r--r-- | lib/private/files/cache/cacheentry.php | 4 | ||||
-rw-r--r-- | lib/private/files/cache/homecache.php | 4 | ||||
-rw-r--r-- | lib/private/files/cache/scanner.php | 3 | ||||
-rw-r--r-- | lib/private/files/cache/wrapper/cachewrapper.php | 15 | ||||
-rw-r--r-- | lib/private/files/fileinfo.php | 3 | ||||
-rw-r--r-- | lib/private/files/storage/wrapper/encryption.php | 4 | ||||
-rw-r--r-- | lib/private/files/view.php | 7 | ||||
-rw-r--r-- | lib/public/files/cache/icache.php | 32 | ||||
-rw-r--r-- | lib/public/files/cache/icacheentry.php (renamed from lib/public/files/cache/icachenetry.php) | 0 |
10 files changed, 56 insertions, 80 deletions
diff --git a/lib/private/files/cache/cache.php b/lib/private/files/cache/cache.php index bb2da63fc46..527c8b76e52 100644 --- a/lib/private/files/cache/cache.php +++ b/lib/private/files/cache/cache.php @@ -34,6 +34,7 @@ namespace OC\Files\Cache; use OCP\Files\Cache\ICache; +use OCP\Files\Cache\ICacheEntry; use \OCP\Files\IMimeTypeLoader; use OCP\IDBConnection; @@ -48,11 +49,6 @@ use OCP\IDBConnection; * - ChangePropagator: updates the mtime and etags of parent folders whenever a change to the cache is made to the cache by the updater */ class Cache implements ICache { - const NOT_FOUND = 0; - const PARTIAL = 1; //only partial data available, file not cached in the database - const SHALLOW = 2; //folder in cache, but not all child files are completely scanned - const COMPLETE = 3; - /** * @var array partial data for the cache */ @@ -106,28 +102,8 @@ class Cache implements ICache { /** * get the stored metadata of a file or folder * - * the returned cache entry contains at least the following values: - * [ - * 'fileid' => int, the numeric id of a file (see getId) - * 'storage' => int, the numeric id of the storage the file is stored on - * 'path' => string, the path of the file within the storage ('foo/bar.txt') - * 'name' => string, the basename of a file ('bar.txt) - * 'mimetype' => string, the full mimetype of the file ('text/plain') - * 'mimepart' => string, the first half of the mimetype ('text') - * 'size' => int, the size of the file or folder in bytes - * 'mtime' => int, the last modified date of the file as unix timestamp as shown in the ui - * 'storage_mtime' => int, the last modified date of the file as unix timestamp as stored on the storage - * Note that when a file is updated we also update the mtime of all parent folders to make it visible to the user which folder has had updates most recently - * This can differ from the mtime on the underlying storage which usually only changes when a direct child is added, removed or renamed - * 'etag' => string, the etag for the file - * An etag is used for change detection of files and folders, an etag of a file changes whenever the content of the file changes - * Etag for folders change whenever a file in the folder has changed - * 'permissions' int, the permissions for the file stored as bitwise combination of \OCP\PERMISSION_READ, \OCP\PERMISSION_CREATE - * \OCP\PERMISSION_UPDATE, \OCP\PERMISSION_DELETE and \OCP\PERMISSION_SHARE - * ] - * * @param string | int $file either the path of a file or folder or the file id for a file or folder - * @return array|false the cache entry as array of false if the file is not found in the cache + * @return ICacheEntry|false the cache entry as array of false if the file is not found in the cache */ public function get($file) { if (is_string($file) or $file == '') { @@ -157,6 +133,7 @@ class Cache implements ICache { if (isset($this->partial[$file])) { $data = $this->partial[$file]; } + return $data; } else { //fix types $data['fileid'] = (int)$data['fileid']; @@ -172,16 +149,15 @@ class Cache implements ICache { $data['storage_mtime'] = $data['mtime']; } $data['permissions'] = (int)$data['permissions']; + return new CacheEntry($data); } - - return $data; } /** * get the metadata of all files stored in $folder * * @param string $folder - * @return array + * @return ICacheEntry[] */ public function getFolderContents($folder) { $fileId = $this->getId($folder); @@ -192,7 +168,7 @@ class Cache implements ICache { * get the metadata of all files stored in $folder * * @param int $fileId the file id of the folder - * @return array + * @return ICacheEntry[] */ public function getFolderContentsById($fileId) { if ($fileId > -1) { @@ -212,7 +188,9 @@ class Cache implements ICache { $file['storage_mtime'] = (int)$file['storage_mtime']; $file['size'] = 0 + $file['size']; } - return $files; + return array_map(function (array $data) { + return new CacheEntry($data); + }, $files); } else { return array(); } @@ -393,7 +371,7 @@ class Cache implements ICache { return -1; } else { $parent = $this->getParentPath($file); - return (int) $this->getId($parent); + return (int)$this->getId($parent); } } @@ -482,12 +460,12 @@ class Cache implements ICache { /** * Move a file or folder in the cache * - * @param \OC\Files\Cache\Cache $sourceCache + * @param \OCP\Files\Cache\ICache $sourceCache * @param string $sourcePath * @param string $targetPath * @throws \OC\DatabaseException */ - public function moveFromCache(Cache $sourceCache, $sourcePath, $targetPath) { + public function moveFromCache(ICache $sourceCache, $sourcePath, $targetPath) { // normalize source and target $sourcePath = $this->normalize($sourcePath); $targetPath = $this->normalize($targetPath); @@ -572,7 +550,7 @@ class Cache implements ICache { * search for files matching $pattern * * @param string $pattern the search pattern using SQL search syntax (e.g. '%searchstring%') - * @return array an array of cache entries where the name matches the search pattern + * @return ICacheEntry[] an array of cache entries where the name matches the search pattern */ public function search($pattern) { // normalize pattern @@ -595,7 +573,9 @@ class Cache implements ICache { $row['mimepart'] = $this->mimetypeLoader->getMimetypeById($row['mimepart']); $files[] = $row; } - return $files; + return array_map(function(array $data) { + return new CacheEntry($data); + }, $files); } /** @@ -603,7 +583,7 @@ class Cache implements ICache { * * @param string $mimetype either a full mimetype to search ('text/plain') or only the first part of a mimetype ('image') * where it will search for all mimetypes in the group ('image/*') - * @return array an array of cache entries where the mimetype matches the search + * @return ICacheEntry[] an array of cache entries where the mimetype matches the search */ public function searchByMime($mimetype) { if (strpos($mimetype, '/')) { @@ -621,7 +601,9 @@ class Cache implements ICache { $row['mimepart'] = $this->mimetypeLoader->getMimetypeById($row['mimepart']); $files[] = $row; } - return $files; + return array_map(function (array $data) { + return new CacheEntry($data); + }, $files); } /** @@ -631,7 +613,7 @@ class Cache implements ICache { * * @param string|int $tag name or tag id * @param string $userId owner of the tags - * @return array file data + * @return ICacheEntry[] file data */ public function searchByTag($tag, $userId) { $sql = 'SELECT `fileid`, `storage`, `path`, `parent`, `name`, ' . @@ -666,7 +648,9 @@ class Cache implements ICache { while ($row = $result->fetch()) { $files[] = $row; } - return $files; + return array_map(function (array $data) { + return new CacheEntry($data); + }, $files); } /** diff --git a/lib/private/files/cache/cacheentry.php b/lib/private/files/cache/cacheentry.php index 10ea949cab2..3db3b3f8aa0 100644 --- a/lib/private/files/cache/cacheentry.php +++ b/lib/private/files/cache/cacheentry.php @@ -107,4 +107,8 @@ class CacheEntry implements ICacheEntry, \ArrayAccess { public function isEncrypted() { return isset($this->data['encrypted']) && $this->data['encrypted']; } + + public function getData() { + return $this->data; + } } diff --git a/lib/private/files/cache/homecache.php b/lib/private/files/cache/homecache.php index 693896fccfb..ae92504ddd6 100644 --- a/lib/private/files/cache/homecache.php +++ b/lib/private/files/cache/homecache.php @@ -26,6 +26,8 @@ namespace OC\Files\Cache; +use OCP\Files\Cache\ICacheEntry; + class HomeCache extends Cache { /** * get the size of a folder and set it in the cache @@ -67,7 +69,7 @@ class HomeCache extends Cache { /** * @param string $path - * @return array + * @return ICacheEntry */ public function get($path) { $data = parent::get($path); diff --git a/lib/private/files/cache/scanner.php b/lib/private/files/cache/scanner.php index 79f749394f1..fa12378ae94 100644 --- a/lib/private/files/cache/scanner.php +++ b/lib/private/files/cache/scanner.php @@ -160,6 +160,7 @@ class Scanner extends BasicEmitter { $data['parent'] = $parentId; } if (is_null($cacheData)) { + /** @var CacheEntry $cacheData */ $cacheData = $this->cache->get($file); } if ($cacheData and $reuseExisting and isset($cacheData['fileid'])) { @@ -182,7 +183,7 @@ class Scanner extends BasicEmitter { } } // Only update metadata that has changed - $newData = array_diff_assoc($data, $cacheData); + $newData = array_diff_assoc($data, $cacheData->getData()); } else { $newData = $data; $fileId = -1; diff --git a/lib/private/files/cache/wrapper/cachewrapper.php b/lib/private/files/cache/wrapper/cachewrapper.php index f401b7482eb..39a6b63205b 100644 --- a/lib/private/files/cache/wrapper/cachewrapper.php +++ b/lib/private/files/cache/wrapper/cachewrapper.php @@ -25,6 +25,7 @@ namespace OC\Files\Cache\Wrapper; use OC\Files\Cache\Cache; +use OCP\Files\Cache\ICacheEntry; class CacheWrapper extends Cache { /** @@ -42,8 +43,8 @@ class CacheWrapper extends Cache { /** * Make it easy for wrappers to modify every returned cache entry * - * @param array $entry - * @return array + * @param ICacheEntry $entry + * @return ICacheEntry */ protected function formatCacheEntry($entry) { return $entry; @@ -53,7 +54,7 @@ class CacheWrapper extends Cache { * get the stored metadata of a file or folder * * @param string /int $file - * @return array|false + * @return ICacheEntry|false */ public function get($file) { $result = $this->cache->get($file); @@ -67,7 +68,7 @@ class CacheWrapper extends Cache { * get the metadata of all files stored in $folder * * @param string $folder - * @return array + * @return ICacheEntry[] */ public function getFolderContents($folder) { // cant do a simple $this->cache->.... call here since getFolderContentsById needs to be called on this @@ -178,7 +179,7 @@ class CacheWrapper extends Cache { * search for files matching $pattern * * @param string $pattern - * @return array an array of file data + * @return ICacheEntry[] an array of file data */ public function search($pattern) { $results = $this->cache->search($pattern); @@ -189,7 +190,7 @@ class CacheWrapper extends Cache { * search for files by mimetype * * @param string $mimetype - * @return array + * @return ICacheEntry[] */ public function searchByMime($mimetype) { $results = $this->cache->searchByMime($mimetype); @@ -201,7 +202,7 @@ class CacheWrapper extends Cache { * * @param string|int $tag name or tag id * @param string $userId owner of the tags - * @return array file data + * @return ICacheEntry[] file data */ public function searchByTag($tag, $userId) { $results = $this->cache->searchByTag($tag, $userId); diff --git a/lib/private/files/fileinfo.php b/lib/private/files/fileinfo.php index 3e5e894eed4..1e6fe474f7b 100644 --- a/lib/private/files/fileinfo.php +++ b/lib/private/files/fileinfo.php @@ -29,6 +29,7 @@ namespace OC\Files; +use OCP\Files\Cache\ICacheEntry; use OCP\IUser; class FileInfo implements \OCP\Files\FileInfo, \ArrayAccess { @@ -71,7 +72,7 @@ class FileInfo implements \OCP\Files\FileInfo, \ArrayAccess { * @param string|boolean $path * @param Storage\Storage $storage * @param string $internalPath - * @param array $data + * @param array|ICacheEntry $data * @param \OCP\Files\Mount\IMountPoint $mount * @param \OCP\IUser|null $owner */ diff --git a/lib/private/files/storage/wrapper/encryption.php b/lib/private/files/storage/wrapper/encryption.php index fda28079d0f..69438ef0c7c 100644 --- a/lib/private/files/storage/wrapper/encryption.php +++ b/lib/private/files/storage/wrapper/encryption.php @@ -28,6 +28,7 @@ namespace OC\Files\Storage\Wrapper; use OC\Encryption\Exceptions\ModuleDoesNotExistsException; use OC\Encryption\Update; use OC\Encryption\Util; +use OC\Files\Cache\CacheEntry; use OC\Files\Filesystem; use OC\Files\Mount\Manager; use OC\Files\Storage\LocalTempFileTrait; @@ -123,13 +124,14 @@ class Encryption extends Wrapper { public function filesize($path) { $fullPath = $this->getFullPath($path); + /** @var CacheEntry $info */ $info = $this->getCache()->get($path); if (isset($this->unencryptedSize[$fullPath])) { $size = $this->unencryptedSize[$fullPath]; // update file cache $info['encrypted'] = true; $info['size'] = $size; - $this->getCache()->put($path, $info); + $this->getCache()->put($path, $info->getData()); return $size; } diff --git a/lib/private/files/view.php b/lib/private/files/view.php index 7b0f1d37255..6f8a6db9f99 100644 --- a/lib/private/files/view.php +++ b/lib/private/files/view.php @@ -47,6 +47,7 @@ use OC\Files\Cache\Updater; use OC\Files\Mount\MoveableMount; use OC\Files\Storage\Storage; use OC\User\User; +use OCP\Files\Cache\ICacheEntry; use OCP\Files\FileNameTooLongException; use OCP\Files\InvalidCharacterInPathException; use OCP\Files\InvalidPathException; @@ -1274,7 +1275,7 @@ class View { if ($storage) { $data = $this->getCacheEntry($storage, $internalPath, $relativePath); - if (!is_array($data)) { + if (!$data instanceof ICacheEntry) { return false; } @@ -1334,7 +1335,7 @@ class View { $data = $this->getCacheEntry($storage, $internalPath, $directory); - if (!is_array($data) || !isset($data['fileid'])) { + if (!$data instanceof ICacheEntry || !isset($data['fileid'])) { return []; } @@ -1345,7 +1346,7 @@ class View { /** * @var \OC\Files\FileInfo[] $files */ - $files = array_map(function (array $content) use ($path, $storage, $mount, $sharingDisabled) { + $files = array_map(function (ICacheEntry $content) use ($path, $storage, $mount, $sharingDisabled) { if ($sharingDisabled) { $content['permissions'] = $content['permissions'] & ~\OCP\Constants::PERMISSION_SHARE; } diff --git a/lib/public/files/cache/icache.php b/lib/public/files/cache/icache.php index 5e8ca50273e..f75bcbcc8e9 100644 --- a/lib/public/files/cache/icache.php +++ b/lib/public/files/cache/icache.php @@ -47,28 +47,8 @@ interface ICache { /** * get the stored metadata of a file or folder * - * the returned cache entry contains at least the following values: - * [ - * 'fileid' => int, the numeric id of a file (see getId) - * 'storage' => int, the numeric id of the storage the file is stored on - * 'path' => string, the path of the file within the storage ('foo/bar.txt') - * 'name' => string, the basename of a file ('bar.txt) - * 'mimetype' => string, the full mimetype of the file ('text/plain') - * 'mimepart' => string, the first half of the mimetype ('text') - * 'size' => int, the size of the file or folder in bytes - * 'mtime' => int, the last modified date of the file as unix timestamp as shown in the ui - * 'storage_mtime' => int, the last modified date of the file as unix timestamp as stored on the storage - * Note that when a file is updated we also update the mtime of all parent folders to make it visible to the user which folder has had updates most recently - * This can differ from the mtime on the underlying storage which usually only changes when a direct child is added, removed or renamed - * 'etag' => string, the etag for the file - * An etag is used for change detection of files and folders, an etag of a file changes whenever the content of the file changes - * Etag for folders change whenever a file in the folder has changed - * 'permissions' int, the permissions for the file stored as bitwise combination of \OCP\PERMISSION_READ, \OCP\PERMISSION_CREATE - * \OCP\PERMISSION_UPDATE, \OCP\PERMISSION_DELETE and \OCP\PERMISSION_SHARE - * ] - * * @param string | int $file either the path of a file or folder or the file id for a file or folder - * @return array|false the cache entry as array of false if the file is not found in the cache + * @return ICacheEntry[]|false the cache entry or false if the file is not found in the cache */ public function get($file); @@ -76,7 +56,7 @@ interface ICache { * get the metadata of all files stored in $folder * * @param string $folder - * @return array + * @return ICacheEntry[] */ public function getFolderContents($folder); @@ -84,7 +64,7 @@ interface ICache { * get the metadata of all files stored in $folder * * @param int $fileId the file id of the folder - * @return array + * @return ICacheEntry[] */ public function getFolderContentsById($fileId); @@ -185,7 +165,7 @@ interface ICache { * search for files matching $pattern * * @param string $pattern the search pattern using SQL search syntax (e.g. '%searchstring%') - * @return array an array of cache entries where the name matches the search pattern + * @return ICacheEntry[] an array of cache entries where the name matches the search pattern */ public function search($pattern); @@ -194,7 +174,7 @@ interface ICache { * * @param string $mimetype either a full mimetype to search ('text/plain') or only the first part of a mimetype ('image') * where it will search for all mimetypes in the group ('image/*') - * @return array an array of cache entries where the mimetype matches the search + * @return ICacheEntry[] an array of cache entries where the mimetype matches the search */ public function searchByMime($mimetype); @@ -205,7 +185,7 @@ interface ICache { * * @param string|int $tag name or tag id * @param string $userId owner of the tags - * @return array file data + * @return ICacheEntry[] file data */ public function searchByTag($tag, $userId); diff --git a/lib/public/files/cache/icachenetry.php b/lib/public/files/cache/icacheentry.php index 62b25ebc280..62b25ebc280 100644 --- a/lib/public/files/cache/icachenetry.php +++ b/lib/public/files/cache/icacheentry.php |