From 92b60e36de8d89e8ea7c4781a8c5d5fa4371b7c3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20M=C3=BCller?= Date: Mon, 20 Apr 2015 14:25:39 +0200 Subject: [PATCH 1/4] Introduce Storage::getData() to allow storage implementations more control over the data array --- lib/private/files/cache/scanner.php | 13 +++-------- lib/private/files/storage/common.php | 17 ++++++++++++++ lib/private/files/storage/storage.php | 6 +++++ .../files/storage/wrapper/encryption.php | 23 +++++++++++++++++++ lib/private/files/storage/wrapper/wrapper.php | 8 +++++++ 5 files changed, 57 insertions(+), 10 deletions(-) diff --git a/lib/private/files/cache/scanner.php b/lib/private/files/cache/scanner.php index 0878b6c60a..c1ba7c0146 100644 --- a/lib/private/files/cache/scanner.php +++ b/lib/private/files/cache/scanner.php @@ -109,17 +109,10 @@ class Scanner extends BasicEmitter { \OCP\Util::writeLog('OC\Files\Cache\Scanner', "!!! Path '$path' is not accessible or present !!!", \OCP\Util::DEBUG); return null; } - $data = array(); - $data['mimetype'] = $this->storage->getMimeType($path); - $data['mtime'] = $this->storage->filemtime($path); - if ($data['mimetype'] == 'httpd/unix-directory') { - $data['size'] = -1; //unknown - } else { - $data['size'] = $this->storage->filesize($path); - } - $data['etag'] = $this->storage->getETag($path); - $data['storage_mtime'] = $data['mtime']; + + $data = $this->storage->getData($path); $data['permissions'] = $permissions; + return $data; } diff --git a/lib/private/files/storage/common.php b/lib/private/files/storage/common.php index 66ed713e22..0294fc4b5b 100644 --- a/lib/private/files/storage/common.php +++ b/lib/private/files/storage/common.php @@ -580,4 +580,21 @@ abstract class Common implements Storage { } return $result; } + + /** + * @inheritdoc + */ + public function getData($path) { + $data = []; + $data['mimetype'] = $this->getMimeType($path); + $data['mtime'] = $this->filemtime($path); + if ($data['mimetype'] == 'httpd/unix-directory') { + $data['size'] = -1; //unknown + } else { + $data['size'] = $this->filesize($path); + } + $data['etag'] = $this->getETag($path); + $data['storage_mtime'] = $data['mtime']; + return $data; + } } diff --git a/lib/private/files/storage/storage.php b/lib/private/files/storage/storage.php index 4b75fa9da8..9fda743afc 100644 --- a/lib/private/files/storage/storage.php +++ b/lib/private/files/storage/storage.php @@ -70,4 +70,10 @@ interface Storage extends \OCP\Files\Storage { */ public function getStorageCache(); + /** + * @param $path + * @return array + */ + public function getData($path); + } diff --git a/lib/private/files/storage/wrapper/encryption.php b/lib/private/files/storage/wrapper/encryption.php index 01bd861e3a..df91b7189d 100644 --- a/lib/private/files/storage/wrapper/encryption.php +++ b/lib/private/files/storage/wrapper/encryption.php @@ -110,6 +110,29 @@ class Encryption extends Wrapper { return $this->storage->filesize($path); } + /** + * @param $path + * @return array + */ + public function getData($path) { + $data = $this->storage->getData($path); + $fullPath = $this->getFullPath($path); + + if (isset($this->unencryptedSize[$fullPath])) { + $size = $this->unencryptedSize[$fullPath]; + + $data['encrypted'] = true; + $data['size'] = $size; + } else { + $info = $this->getCache()->get($path); + if (isset($info['fileid']) && $info['encrypted']) { + $data['encrypted'] = true; + $data['size'] = $info['size']; + } + } + + return $data; + } /** * see http://php.net/manual/en/function.file_get_contents.php * diff --git a/lib/private/files/storage/wrapper/wrapper.php b/lib/private/files/storage/wrapper/wrapper.php index 2552c926e0..0bea457c87 100644 --- a/lib/private/files/storage/wrapper/wrapper.php +++ b/lib/private/files/storage/wrapper/wrapper.php @@ -525,4 +525,12 @@ class Wrapper implements \OC\Files\Storage\Storage { public function moveFromStorage(\OCP\Files\Storage $sourceStorage, $sourceInternalPath, $targetInternalPath) { return $this->storage->moveFromStorage($sourceStorage, $sourceInternalPath, $targetInternalPath); } + + /** + * @param $path + * @return array + */ + public function getData($path) { + return $this->storage->getData($path); + } } From 23f1bdc3d4682dbb2e8d1a82921d62dbe0b213be Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20M=C3=BCller?= Date: Mon, 20 Apr 2015 14:54:54 +0200 Subject: [PATCH 2/4] Introduce Storage::getMetaData() to allow storage implementations more control over the data array --- lib/private/files/cache/scanner.php | 2 +- lib/private/files/storage/common.php | 2 +- lib/private/files/storage/storage.php | 4 ++-- lib/private/files/storage/wrapper/encryption.php | 6 +++--- lib/private/files/storage/wrapper/wrapper.php | 6 +++--- 5 files changed, 10 insertions(+), 10 deletions(-) diff --git a/lib/private/files/cache/scanner.php b/lib/private/files/cache/scanner.php index c1ba7c0146..713dcda3ac 100644 --- a/lib/private/files/cache/scanner.php +++ b/lib/private/files/cache/scanner.php @@ -110,7 +110,7 @@ class Scanner extends BasicEmitter { return null; } - $data = $this->storage->getData($path); + $data = $this->storage->getMetaData($path); $data['permissions'] = $permissions; return $data; diff --git a/lib/private/files/storage/common.php b/lib/private/files/storage/common.php index 0294fc4b5b..7667821805 100644 --- a/lib/private/files/storage/common.php +++ b/lib/private/files/storage/common.php @@ -584,7 +584,7 @@ abstract class Common implements Storage { /** * @inheritdoc */ - public function getData($path) { + public function getMetaData($path) { $data = []; $data['mimetype'] = $this->getMimeType($path); $data['mtime'] = $this->filemtime($path); diff --git a/lib/private/files/storage/storage.php b/lib/private/files/storage/storage.php index 9fda743afc..07b5633c90 100644 --- a/lib/private/files/storage/storage.php +++ b/lib/private/files/storage/storage.php @@ -71,9 +71,9 @@ interface Storage extends \OCP\Files\Storage { public function getStorageCache(); /** - * @param $path + * @param string $path * @return array */ - public function getData($path); + public function getMetaData($path); } diff --git a/lib/private/files/storage/wrapper/encryption.php b/lib/private/files/storage/wrapper/encryption.php index df91b7189d..125e5f0f57 100644 --- a/lib/private/files/storage/wrapper/encryption.php +++ b/lib/private/files/storage/wrapper/encryption.php @@ -111,11 +111,11 @@ class Encryption extends Wrapper { } /** - * @param $path + * @param string $path * @return array */ - public function getData($path) { - $data = $this->storage->getData($path); + public function getMetaData($path) { + $data = $this->storage->getMetaData($path); $fullPath = $this->getFullPath($path); if (isset($this->unencryptedSize[$fullPath])) { diff --git a/lib/private/files/storage/wrapper/wrapper.php b/lib/private/files/storage/wrapper/wrapper.php index 0bea457c87..f3dc09db13 100644 --- a/lib/private/files/storage/wrapper/wrapper.php +++ b/lib/private/files/storage/wrapper/wrapper.php @@ -527,10 +527,10 @@ class Wrapper implements \OC\Files\Storage\Storage { } /** - * @param $path + * @param string $path * @return array */ - public function getData($path) { - return $this->storage->getData($path); + public function getMetaData($path) { + return $this->storage->getMetaData($path); } } From a637bd7f2b82bf52515a198071d74b776d492f28 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20M=C3=BCller?= Date: Mon, 20 Apr 2015 14:56:51 +0200 Subject: [PATCH 3/4] Avoid function name collision in dropbox external storage --- apps/files_external/lib/dropbox.php | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/apps/files_external/lib/dropbox.php b/apps/files_external/lib/dropbox.php index b685f635ae..78219f8f06 100644 --- a/apps/files_external/lib/dropbox.php +++ b/apps/files_external/lib/dropbox.php @@ -77,7 +77,7 @@ class Dropbox extends \OC\Files\Storage\Common { * @return mixed directory contents if $list is true, file metadata if $list is * false, null if the file doesn't exist or "false" if the operation failed */ - private function getMetaData($path, $list = false) { + private function getDropBoxMetaData($path, $list = false) { $path = $this->root.$path; if ( ! $list && isset($this->metaData[$path])) { return $this->metaData[$path]; @@ -150,7 +150,7 @@ class Dropbox extends \OC\Files\Storage\Common { } public function opendir($path) { - $contents = $this->getMetaData($path, true); + $contents = $this->getDropBoxMetaData($path, true); if ($contents !== false) { $files = array(); foreach ($contents as $file) { @@ -163,7 +163,7 @@ class Dropbox extends \OC\Files\Storage\Common { } public function stat($path) { - $metaData = $this->getMetaData($path); + $metaData = $this->getDropBoxMetaData($path); if ($metaData) { $stat['size'] = $metaData['bytes']; $stat['atime'] = time(); @@ -177,7 +177,7 @@ class Dropbox extends \OC\Files\Storage\Common { if ($path == '' || $path == '/') { return 'dir'; } else { - $metaData = $this->getMetaData($path); + $metaData = $this->getDropBoxMetaData($path); if ($metaData) { if ($metaData['is_dir'] == 'true') { return 'dir'; @@ -193,7 +193,7 @@ class Dropbox extends \OC\Files\Storage\Common { if ($path == '' || $path == '/') { return true; } - if ($this->getMetaData($path)) { + if ($this->getDropBoxMetaData($path)) { return true; } return false; @@ -213,7 +213,7 @@ class Dropbox extends \OC\Files\Storage\Common { public function rename($path1, $path2) { try { // overwrite if target file exists and is not a directory - $destMetaData = $this->getMetaData($path2); + $destMetaData = $this->getDropBoxMetaData($path2); if (isset($destMetaData) && $destMetaData !== false && !$destMetaData['is_dir']) { $this->unlink($path2); } @@ -297,7 +297,7 @@ class Dropbox extends \OC\Files\Storage\Common { if ($this->filetype($path) == 'dir') { return 'httpd/unix-directory'; } else { - $metaData = $this->getMetaData($path); + $metaData = $this->getDropBoxMetaData($path); if ($metaData) { return $metaData['mime_type']; } From 32995ace1c1ea453e08b1afd6f6d43cf68f2e3b1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20M=C3=BCller?= Date: Mon, 20 Apr 2015 16:50:12 +0200 Subject: [PATCH 4/4] move permission related code into getMetaData() --- lib/private/files/cache/scanner.php | 12 +++--------- lib/private/files/storage/common.php | 8 ++++++++ .../files/storage/wrapper/encryption.php | 17 ++++++++++------- 3 files changed, 21 insertions(+), 16 deletions(-) diff --git a/lib/private/files/cache/scanner.php b/lib/private/files/cache/scanner.php index 713dcda3ac..d253afbfa1 100644 --- a/lib/private/files/cache/scanner.php +++ b/lib/private/files/cache/scanner.php @@ -103,16 +103,10 @@ class Scanner extends BasicEmitter { * @return array an array of metadata of the file */ public function getData($path) { - $permissions = $this->storage->getPermissions($path); - if (!$permissions & \OCP\PERMISSION_READ) { - //cant read, nothing we can do - \OCP\Util::writeLog('OC\Files\Cache\Scanner', "!!! Path '$path' is not accessible or present !!!", \OCP\Util::DEBUG); - return null; - } - $data = $this->storage->getMetaData($path); - $data['permissions'] = $permissions; - + if (is_null($data)) { + \OCP\Util::writeLog('OC\Files\Cache\Scanner', "!!! Path '$path' is not accessible or present !!!", \OCP\Util::DEBUG); + } return $data; } diff --git a/lib/private/files/storage/common.php b/lib/private/files/storage/common.php index 7667821805..06c61fe693 100644 --- a/lib/private/files/storage/common.php +++ b/lib/private/files/storage/common.php @@ -585,6 +585,12 @@ abstract class Common implements Storage { * @inheritdoc */ public function getMetaData($path) { + $permissions = $this->getPermissions($path); + if (!$permissions & \OCP\Constants::PERMISSION_READ) { + //cant read, nothing we can do + return null; + } + $data = []; $data['mimetype'] = $this->getMimeType($path); $data['mtime'] = $this->filemtime($path); @@ -595,6 +601,8 @@ abstract class Common implements Storage { } $data['etag'] = $this->getETag($path); $data['storage_mtime'] = $data['mtime']; + $data['permissions'] = $this->getPermissions($path); + return $data; } } diff --git a/lib/private/files/storage/wrapper/encryption.php b/lib/private/files/storage/wrapper/encryption.php index 125e5f0f57..e5c96286f0 100644 --- a/lib/private/files/storage/wrapper/encryption.php +++ b/lib/private/files/storage/wrapper/encryption.php @@ -23,6 +23,8 @@ namespace OC\Files\Storage\Wrapper; use OC\Encryption\Exceptions\ModuleDoesNotExistsException; +use OC\Encryption\File; +use OC\Files\Filesystem; use OC\Files\Storage\LocalTempFileTrait; use OCP\Files\Mount\IMountPoint; @@ -48,7 +50,7 @@ class Encryption extends Wrapper { /** @var array */ private $unencryptedSize; - /** @var \OC\Encryption\File */ + /** @var File */ private $fileHelper; /** @var IMountPoint */ @@ -59,7 +61,7 @@ class Encryption extends Wrapper { * @param \OC\Encryption\Manager $encryptionManager * @param \OC\Encryption\Util $util * @param \OC\Log $logger - * @param \OC\Encryption\File $fileHelper + * @param File $fileHelper * @param string $uid user who perform the read/write operation (null for public access) */ public function __construct( @@ -67,7 +69,7 @@ class Encryption extends Wrapper { \OC\Encryption\Manager $encryptionManager = null, \OC\Encryption\Util $util = null, \OC\Log $logger = null, - \OC\Encryption\File $fileHelper = null, + File $fileHelper = null, $uid = null ) { @@ -116,13 +118,14 @@ class Encryption extends Wrapper { */ public function getMetaData($path) { $data = $this->storage->getMetaData($path); + if (is_null($data)) { + return null; + } $fullPath = $this->getFullPath($path); if (isset($this->unencryptedSize[$fullPath])) { - $size = $this->unencryptedSize[$fullPath]; - $data['encrypted'] = true; - $data['size'] = $size; + $data['size'] = $this->unencryptedSize[$fullPath]; } else { $info = $this->getCache()->get($path); if (isset($info['fileid']) && $info['encrypted']) { @@ -383,7 +386,7 @@ class Encryption extends Wrapper { * @return string full path including mount point */ protected function getFullPath($path) { - return \OC\Files\Filesystem::normalizePath($this->mountPoint . '/' . $path); + return Filesystem::normalizePath($this->mountPoint . '/' . $path); } /**