From 617acbd6f9e93254c31987639cc4915dceb7c4c0 Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Mon, 13 Jan 2014 14:28:49 +0100 Subject: Add a FileInfo class which holds all info of a file and return that from getFileInfo, getDirectoryContent and search --- lib/public/files/fileinfo.php | 87 +++++++++++++++++++++++++++++++++++++++++++ lib/public/util.php | 2 +- 2 files changed, 88 insertions(+), 1 deletion(-) create mode 100644 lib/public/files/fileinfo.php (limited to 'lib/public') diff --git a/lib/public/files/fileinfo.php b/lib/public/files/fileinfo.php new file mode 100644 index 00000000000..a11378c2ee5 --- /dev/null +++ b/lib/public/files/fileinfo.php @@ -0,0 +1,87 @@ + Date: Mon, 13 Jan 2014 14:42:14 +0100 Subject: Extends phpdoc for \OCP\File\FileInfo --- lib/public/files/fileinfo.php | 41 +++++++++++++++++++++++++++++++++++++---- 1 file changed, 37 insertions(+), 4 deletions(-) (limited to 'lib/public') diff --git a/lib/public/files/fileinfo.php b/lib/public/files/fileinfo.php index a11378c2ee5..09c194fe96d 100644 --- a/lib/public/files/fileinfo.php +++ b/lib/public/files/fileinfo.php @@ -22,65 +22,98 @@ interface FileInfo extends \ArrayAccess, \JsonSerializable { public function jsonSerialize(); /** + * Get the Etag of the file or folder + * * @return string */ public function getEtag(); /** + * Get the size in bytes for the file or folder + * * @return int */ public function getSize(); /** + * Get the last modified date as timestamp for the file or folder + * * @return int */ public function getMtime(); /** + * Get the name of the file or folder + * * @return string */ public function getName(); /** + * Get the path relative to the storage + * * @return string */ public function getInternalPath(); /** + * Get the absolute path + * * @return string */ public function getPath(); /** + * Get the full mimetype of the file or folder i.e. 'image/png' + * * @return string */ public function getMimetype(); /** + * Get the first part of the mimetype of the file or folder i.e. 'image' + * + * @return string + */ + public function getMimePart(); + + /** + * Get the storage the file or folder is storage on + * * @return \OCP\Files\Storage */ public function getStorage(); /** + * Get the file id of the file or folder + * * @return int */ public function getId(); /** - * @return string - */ - public function getMimePart(); - /** + * Check whether the file is encrypted + * * @return bool */ public function isEncrypted(); /** + * Get the permissions of the file or folder as bitmasked combination of the following constants + * \OCP\PERMISSION_CREATE + * \OCP\PERMISSION_READ + * \OCP\PERMISSION_UPDATE + * \OCP\PERMISSION_DELETE + * \OCP\PERMISSION_SHARE + * \OCP\PERMISSION_ALL + * * @return int */ public function getPermissions(); /** + * Check whether this is a file or a folder + * * @return \OCP\Files\FileInfo::TYPE_FILE | \OCP\Files\FileInfo::TYPE_FOLDER */ public function getType(); -- cgit v1.2.3 From 82762bb4627364241c69a8b39b1d7840a1d71614 Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Mon, 13 Jan 2014 15:13:45 +0100 Subject: remove ArrayAccess, JsonSerializable from the public part of FileInfo --- lib/private/files/fileinfo.php | 4 ++-- lib/public/files/fileinfo.php | 20 +++++--------------- 2 files changed, 7 insertions(+), 17 deletions(-) (limited to 'lib/public') diff --git a/lib/private/files/fileinfo.php b/lib/private/files/fileinfo.php index 24d99627aaf..8e9b6a8b72c 100644 --- a/lib/private/files/fileinfo.php +++ b/lib/private/files/fileinfo.php @@ -1,6 +1,6 @@ + * Copyright (c) 2014 Robin Appelman * This file is licensed under the Affero General Public License version 3 or * later. * See the COPYING-README file. @@ -8,7 +8,7 @@ namespace OC\Files; -class FileInfo implements \OCP\Files\FileInfo { +class FileInfo implements \OCP\Files\FileInfo, \ArrayAccess, \JsonSerializable { /** * @var array $data */ diff --git a/lib/public/files/fileinfo.php b/lib/public/files/fileinfo.php index 09c194fe96d..cbe216023da 100644 --- a/lib/public/files/fileinfo.php +++ b/lib/public/files/fileinfo.php @@ -1,26 +1,16 @@ + * This file is licensed under the Affero General Public License version 3 or + * later. + * See the COPYING-README file. */ namespace OCP\Files; -interface FileInfo extends \ArrayAccess, \JsonSerializable { +interface FileInfo { const TYPE_FILE = 'file'; const TYPE_FOLDER = 'folder'; - public function offsetSet($offset, $value); - - public function offsetGet($offset); - - public function offsetUnset($offset); - - public function offsetExists($offset); - - public function jsonSerialize(); - /** * Get the Etag of the file or folder * -- cgit v1.2.3 From fc5f20112efe03b203978c4b1045ed70c2ce5e74 Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Fri, 24 Jan 2014 15:54:40 +0100 Subject: Add isReadable, isUpdateable, isDeletable, isShareable --- lib/private/files/fileinfo.php | 38 +++++++++++++++++++++++++++++++++++++- lib/public/files/fileinfo.php | 28 ++++++++++++++++++++++++++++ 2 files changed, 65 insertions(+), 1 deletion(-) (limited to 'lib/public') diff --git a/lib/private/files/fileinfo.php b/lib/private/files/fileinfo.php index b80873d1d00..7edea13df96 100644 --- a/lib/private/files/fileinfo.php +++ b/lib/private/files/fileinfo.php @@ -122,7 +122,7 @@ class FileInfo implements \OCP\Files\FileInfo, \ArrayAccess, \JsonSerializable { /** * @return int */ - public function getMtime() { + public function getMTime() { return $this->data['mtime']; } @@ -150,4 +150,40 @@ class FileInfo implements \OCP\Files\FileInfo, \ArrayAccess, \JsonSerializable { public function getData(){ return $this->data; } + + /** + * @param int $permissions + * @return bool + */ + protected function checkPermissions($permissions) { + return ($this->getPermissions() & $permissions) === $permissions; + } + + /** + * @return bool + */ + public function isReadable() { + return $this->checkPermissions(\OCP\PERMISSION_READ); + } + + /** + * @return bool + */ + public function isUpdateable() { + return $this->checkPermissions(\OCP\PERMISSION_UPDATE); + } + + /** + * @return bool + */ + public function isDeletable() { + return $this->checkPermissions(\OCP\PERMISSION_DELETE); + } + + /** + * @return bool + */ + public function isShareable() { + return $this->checkPermissions(\OCP\PERMISSION_SHARE); + } } diff --git a/lib/public/files/fileinfo.php b/lib/public/files/fileinfo.php index cbe216023da..68ce45d3fa1 100644 --- a/lib/public/files/fileinfo.php +++ b/lib/public/files/fileinfo.php @@ -107,4 +107,32 @@ interface FileInfo { * @return \OCP\Files\FileInfo::TYPE_FILE | \OCP\Files\FileInfo::TYPE_FOLDER */ public function getType(); + + /** + * Check if the file or folder is readable + * + * @return bool + */ + public function isReadable(); + + /** + * Check if a file is writable + * + * @return bool + */ + public function isUpdateable(); + + /** + * Check if a file or folder can be deleted + * + * @return bool + */ + public function isDeletable(); + + /** + * Check if a file or folder can be shared + * + * @return bool + */ + public function isShareable(); } -- cgit v1.2.3 From 3c1ab66edac1ba2f1b398c859cd933c410ea3d8d Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Mon, 27 Jan 2014 15:56:57 +0100 Subject: Reuse the calculated free_space in buildFileStorageStatistics --- apps/files/lib/helper.php | 8 ++++---- lib/private/helper.php | 9 ++++++--- lib/public/util.php | 7 ++++--- 3 files changed, 14 insertions(+), 10 deletions(-) (limited to 'lib/public') diff --git a/apps/files/lib/helper.php b/apps/files/lib/helper.php index eaff28178ea..87939d26921 100644 --- a/apps/files/lib/helper.php +++ b/apps/files/lib/helper.php @@ -5,14 +5,14 @@ namespace OCA\Files; class Helper { public static function buildFileStorageStatistics($dir) { + // information about storage capacities + $storageInfo = \OC_Helper::getStorageInfo($dir); + $l = new \OC_L10N('files'); - $maxUploadFilesize = \OCP\Util::maxUploadFilesize($dir); + $maxUploadFilesize = \OCP\Util::maxUploadFilesize($dir, $storageInfo['free']); $maxHumanFilesize = \OCP\Util::humanFileSize($maxUploadFilesize); $maxHumanFilesize = $l->t('Upload') . ' max. ' . $maxHumanFilesize; - // information about storage capacities - $storageInfo = \OC_Helper::getStorageInfo($dir); - return array('uploadMaxFilesize' => $maxUploadFilesize, 'maxHumanFilesize' => $maxHumanFilesize, 'usedSpacePercent' => (int)$storageInfo['relative']); diff --git a/lib/private/helper.php b/lib/private/helper.php index 1c8d01c141f..12784c9a5eb 100644 --- a/lib/private/helper.php +++ b/lib/private/helper.php @@ -824,13 +824,16 @@ class OC_Helper { /** * @brief calculates the maximum upload size respecting system settings, free space and user quota * - * @param $dir the current folder where the user currently operates + * @param string $dir the current folder where the user currently operates + * @param int $free the number of bytes free on the storage holding $dir, if not set this will be received from the storage directly * @return number of bytes representing */ - public static function maxUploadFilesize($dir) { + public static function maxUploadFilesize($dir, $freeSpace = null) { $upload_max_filesize = OCP\Util::computerFileSize(ini_get('upload_max_filesize')); $post_max_size = OCP\Util::computerFileSize(ini_get('post_max_size')); - $freeSpace = \OC\Files\Filesystem::free_space($dir); + if (is_null($freeSpace)) { + $freeSpace = \OC\Files\Filesystem::free_space($dir); + } if ((int)$upload_max_filesize === 0 and (int)$post_max_size === 0) { $maxUploadFilesize = \OC\Files\SPACE_UNLIMITED; } elseif ((int)$upload_max_filesize === 0 or (int)$post_max_size === 0) { diff --git a/lib/public/util.php b/lib/public/util.php index 6317f10a66f..52874bcc954 100644 --- a/lib/public/util.php +++ b/lib/public/util.php @@ -456,10 +456,11 @@ class Util { /** * calculates the maximum upload size respecting system settings, free space and user quota * - * @param $dir the current folder where the user currently operates + * @param string $dir the current folder where the user currently operates + * @param int $free the number of bytes free on the storage holding $dir, if not set this will be received from the storage directly * @return number of bytes representing */ - public static function maxUploadFilesize($dir) { - return \OC_Helper::maxUploadFilesize($dir); + public static function maxUploadFilesize($dir, $free = null) { + return \OC_Helper::maxUploadFilesize($dir, $free); } } -- cgit v1.2.3 From 788c8540aa6aac50795c37b088eeaa561d44b86c Mon Sep 17 00:00:00 2001 From: Vincent Petry Date: Tue, 4 Feb 2014 19:58:49 +0100 Subject: Added isLocal() method to storage, used for xsendfile Added isLocal() method to Storage to find out whether the storage is local or not. This method is used for the x-sendfile logic to find out whether to add the headers. --- lib/private/files.php | 2 +- lib/private/files/storage/common.php | 9 +++++++++ lib/private/files/storage/local.php | 7 +++++++ lib/private/files/storage/wrapper/wrapper.php | 8 ++++++++ lib/public/files/storage.php | 11 +++++++++++ 5 files changed, 36 insertions(+), 1 deletion(-) (limited to 'lib/public') diff --git a/lib/private/files.php b/lib/private/files.php index 8ce632013cf..24fca4a5df3 100644 --- a/lib/private/files.php +++ b/lib/private/files.php @@ -131,7 +131,7 @@ class OC_Files { } if ($xsendfile) { list($storage) = \OC\Files\Filesystem::resolvePath(\OC\Files\Filesystem::getView()->getAbsolutePath($filename)); - if ($storage instanceof \OC\Files\Storage\Local) { + if ($storage->isLocal()) { self::addSendfileHeader(\OC\Files\Filesystem::getLocalFile($filename)); } } diff --git a/lib/private/files/storage/common.php b/lib/private/files/storage/common.php index 678bf419023..55b1471593d 100644 --- a/lib/private/files/storage/common.php +++ b/lib/private/files/storage/common.php @@ -370,4 +370,13 @@ abstract class Common implements \OC\Files\Storage\Storage { public function free_space($path) { return \OC\Files\SPACE_UNKNOWN; } + + /** + * {@inheritdoc} + */ + public function isLocal() { + // the common implementation returns a temporary file by + // default, which is not local + return false; + } } diff --git a/lib/private/files/storage/local.php b/lib/private/files/storage/local.php index db3c6bfca3a..fa0788f2377 100644 --- a/lib/private/files/storage/local.php +++ b/lib/private/files/storage/local.php @@ -298,5 +298,12 @@ if (\OC_Util::runningOnWindows()) { public function hasUpdated($path, $time) { return $this->filemtime($path) > $time; } + + /** + * {@inheritdoc} + */ + public function isLocal() { + return true; + } } } diff --git a/lib/private/files/storage/wrapper/wrapper.php b/lib/private/files/storage/wrapper/wrapper.php index f9adda80314..11ea9f71da7 100644 --- a/lib/private/files/storage/wrapper/wrapper.php +++ b/lib/private/files/storage/wrapper/wrapper.php @@ -432,4 +432,12 @@ class Wrapper implements \OC\Files\Storage\Storage { public function test() { return $this->storage->test(); } + + /** + * Returns the wrapped storage's value for isLocal() + * @return bool wrapped storage's isLocal() value + */ + public function isLocal() { + return $this->storage->isLocal(); + } } diff --git a/lib/public/files/storage.php b/lib/public/files/storage.php index 194b42a6481..fe30f8f50af 100644 --- a/lib/public/files/storage.php +++ b/lib/public/files/storage.php @@ -315,4 +315,15 @@ interface Storage { * @return string */ public function getETag($path); + + /** + * Returns whether the storage is local, which means that files + * are stored on the local filesystem instead of remotely. + * Calling getLocalFile() for local storages should always + * return the local files, whereas for non-local storages + * it might return a temporary file. + * + * @return bool true if the files are stored locally, false otherwise + */ + public function isLocal(); } -- cgit v1.2.3 From a8943ad02207afbf142ec48f4b53cbe1be943253 Mon Sep 17 00:00:00 2001 From: Bjoern Schiessle Date: Thu, 6 Feb 2014 16:01:42 +0100 Subject: replace 'size' with 'unencrypted_size' if encryption is enabled --- apps/files_sharing/lib/cache.php | 15 +++++++++++++-- apps/files_sharing/lib/share/file.php | 9 ++++++++- lib/public/share.php | 2 +- 3 files changed, 22 insertions(+), 4 deletions(-) (limited to 'lib/public') diff --git a/apps/files_sharing/lib/cache.php b/apps/files_sharing/lib/cache.php index 86e324409fe..1b102f9e5f8 100644 --- a/apps/files_sharing/lib/cache.php +++ b/apps/files_sharing/lib/cache.php @@ -92,12 +92,11 @@ class Shared_Cache extends Cache { } else { $query = \OC_DB::prepare( 'SELECT `fileid`, `storage`, `path`, `parent`, `name`, `mimetype`, `mimepart`,' - .' `size`, `mtime`, `encrypted`' + .' `size`, `mtime`, `encrypted`, `unencrypted_size`' .' FROM `*PREFIX*filecache` WHERE `fileid` = ?'); $result = $query->execute(array($file)); $data = $result->fetchRow(); $data['fileid'] = (int)$data['fileid']; - $data['size'] = (int)$data['size']; $data['mtime'] = (int)$data['mtime']; $data['storage_mtime'] = (int)$data['storage_mtime']; $data['encrypted'] = (bool)$data['encrypted']; @@ -106,6 +105,12 @@ class Shared_Cache extends Cache { if ($data['storage_mtime'] === 0) { $data['storage_mtime'] = $data['mtime']; } + if ($data['encrypted'] or ($data['unencrypted_size'] > 0 and $data['mimetype'] === 'httpd/unix-directory')) { + $data['encrypted_size'] = (int)$data['size']; + $data['size'] = (int)$data['unencrypted_size']; + } else { + $data['size'] = (int)$data['size']; + } return $data; } return false; @@ -334,6 +339,12 @@ class Shared_Cache extends Cache { } $row['mimetype'] = $this->getMimetype($row['mimetype']); $row['mimepart'] = $this->getMimetype($row['mimepart']); + if ($row['encrypted'] or ($row['unencrypted_size'] > 0 and $row['mimetype'] === 'httpd/unix-directory')) { + $row['encrypted_size'] = $row['size']; + $row['size'] = $row['unencrypted_size']; + } else { + $row['size'] = $row['size']; + } $files[] = $row; } } diff --git a/apps/files_sharing/lib/share/file.php b/apps/files_sharing/lib/share/file.php index c956c55a1df..ec0f368386f 100644 --- a/apps/files_sharing/lib/share/file.php +++ b/apps/files_sharing/lib/share/file.php @@ -91,10 +91,17 @@ class OC_Share_Backend_File implements OCP\Share_Backend_File_Dependent { $file['name'] = basename($item['file_target']); $file['mimetype'] = $item['mimetype']; $file['mimepart'] = $item['mimepart']; - $file['size'] = $item['size']; $file['mtime'] = $item['mtime']; $file['encrypted'] = $item['encrypted']; $file['etag'] = $item['etag']; + $storage = \OC\Files\Filesystem::getStorage('/'); + $cache = $storage->getCache(); + if ($item['encrypted'] or ($item['unencrypted_size'] > 0 and $cache->getMimetype($item['mimetype']) === 'httpd/unix-directory')) { + $file['size'] = $item['unencrypted_size']; + $file['encrypted_size'] = $item['size']; + } else { + $file['size'] = $item['size']; + } $files[] = $file; } return $files; diff --git a/lib/public/share.php b/lib/public/share.php index f832d04a70f..ae7d29e8b87 100644 --- a/lib/public/share.php +++ b/lib/public/share.php @@ -1152,7 +1152,7 @@ class Share { $select = '`*PREFIX*share`.`id`, `item_type`, `item_source`, `*PREFIX*share`.`parent`, `uid_owner`, ' .'`share_type`, `share_with`, `file_source`, `path`, `file_target`, ' .'`permissions`, `expiration`, `storage`, `*PREFIX*filecache`.`parent` as `file_parent`, ' - .'`name`, `mtime`, `mimetype`, `mimepart`, `size`, `encrypted`, `etag`, `mail_send`'; + .'`name`, `mtime`, `mimetype`, `mimepart`, `size`, `unencrypted_size`, `encrypted`, `etag`, `mail_send`'; } else { $select = '`*PREFIX*share`.`id`, `item_type`, `item_source`, `item_target`, `*PREFIX*share`.`parent`, `share_type`, `share_with`, `uid_owner`, -- cgit v1.2.3