diff options
Diffstat (limited to 'lib/files/storage')
-rw-r--r-- | lib/files/storage/common.php | 8 | ||||
-rw-r--r-- | lib/files/storage/commontest.php | 2 | ||||
-rw-r--r-- | lib/files/storage/local.php | 2 | ||||
-rw-r--r-- | lib/files/storage/wrapper/quota.php | 104 | ||||
-rw-r--r-- | lib/files/storage/wrapper/wrapper.php | 2 |
5 files changed, 111 insertions, 7 deletions
diff --git a/lib/files/storage/common.php b/lib/files/storage/common.php index 3da13ac4df0..01560f34fde 100644 --- a/lib/files/storage/common.php +++ b/lib/files/storage/common.php @@ -142,7 +142,7 @@ abstract class Common implements \OC\Files\Storage\Storage { return false; } else { $directoryHandle = $this->opendir($directory); - while ($contents = readdir($directoryHandle)) { + while (($contents = readdir($directoryHandle)) !== false) { if (!\OC\Files\Filesystem::isIgnoredDir($contents)) { $path = $directory . '/' . $contents; if ($this->is_dir($path)) { @@ -225,7 +225,7 @@ abstract class Common implements \OC\Files\Storage\Storage { private function addLocalFolder($path, $target) { if ($dh = $this->opendir($path)) { - while ($file = readdir($dh)) { + while (($file = readdir($dh)) !== false) { if ($file !== '.' and $file !== '..') { if ($this->is_dir($path . '/' . $file)) { mkdir($target . '/' . $file); @@ -243,7 +243,7 @@ abstract class Common implements \OC\Files\Storage\Storage { $files = array(); $dh = $this->opendir($dir); if ($dh) { - while ($item = readdir($dh)) { + while (($item = readdir($dh)) !== false) { if ($item == '.' || $item == '..') continue; if (strstr(strtolower($item), strtolower($query)) !== false) { $files[] = $dir . '/' . $item; @@ -366,6 +366,6 @@ abstract class Common implements \OC\Files\Storage\Storage { * @return int */ public function free_space($path) { - return \OC\Files\FREE_SPACE_UNKNOWN; + return \OC\Files\SPACE_UNKNOWN; } } diff --git a/lib/files/storage/commontest.php b/lib/files/storage/commontest.php index fbdb7fbf110..c3f1eb31955 100644 --- a/lib/files/storage/commontest.php +++ b/lib/files/storage/commontest.php @@ -77,4 +77,4 @@ class CommonTest extends \OC\Files\Storage\Common{ public function touch($path, $mtime=null) { return $this->storage->touch($path, $mtime); } -}
\ No newline at end of file +} diff --git a/lib/files/storage/local.php b/lib/files/storage/local.php index b08fd73ce19..5209fabc30a 100644 --- a/lib/files/storage/local.php +++ b/lib/files/storage/local.php @@ -265,7 +265,7 @@ if (\OC_Util::runningOnWindows()) { public function free_space($path) { $space = @disk_free_space($this->datadir . $path); if ($space === false) { - return \OC\Files\FREE_SPACE_UNKNOWN; + return \OC\Files\SPACE_UNKNOWN; } return $space; } diff --git a/lib/files/storage/wrapper/quota.php b/lib/files/storage/wrapper/quota.php new file mode 100644 index 00000000000..e2da8cf2e05 --- /dev/null +++ b/lib/files/storage/wrapper/quota.php @@ -0,0 +1,104 @@ +<?php +/** + * Copyright (c) 2013 Robin Appelman <icewind@owncloud.com> + * This file is licensed under the Affero General Public License version 3 or + * later. + * See the COPYING-README file. + */ + +namespace OC\Files\Storage\Wrapper; + +class Quota extends Wrapper { + + /** + * @var int $quota + */ + protected $quota; + + /** + * @param array $parameters + */ + public function __construct($parameters) { + $this->storage = $parameters['storage']; + $this->quota = $parameters['quota']; + } + + protected function getSize($path) { + $cache = $this->getCache(); + $data = $cache->get($path); + if (is_array($data) and isset($data['size'])) { + return $data['size']; + } else { + return \OC\Files\SPACE_NOT_COMPUTED; + } + } + + /** + * Get free space as limited by the quota + * + * @param string $path + * @return int + */ + public function free_space($path) { + if ($this->quota < 0) { + return $this->storage->free_space($path); + } else { + $used = $this->getSize(''); + if ($used < 0) { + return \OC\Files\SPACE_NOT_COMPUTED; + } else { + $free = $this->storage->free_space($path); + return min($free, (max($this->quota - $used, 0))); + } + } + } + + /** + * see http://php.net/manual/en/function.file_put_contents.php + * + * @param string $path + * @param string $data + * @return bool + */ + public function file_put_contents($path, $data) { + $free = $this->free_space(''); + if ($free < 0 or strlen($data) < $free) { + return $this->storage->file_put_contents($path, $data); + } else { + return false; + } + } + + /** + * see http://php.net/manual/en/function.copy.php + * + * @param string $source + * @param string $target + * @return bool + */ + public function copy($source, $target) { + $free = $this->free_space(''); + if ($free < 0 or $this->getSize($source) < $free) { + return $this->storage->copy($source, $target); + } else { + return false; + } + } + + /** + * see http://php.net/manual/en/function.fopen.php + * + * @param string $path + * @param string $mode + * @return resource + */ + public function fopen($path, $mode) { + $source = $this->storage->fopen($path, $mode); + $free = $this->free_space(''); + if ($free >= 0) { + return \OC\Files\Stream\Quota::wrap($source, $free); + } else { + return $source; + } + } +} diff --git a/lib/files/storage/wrapper/wrapper.php b/lib/files/storage/wrapper/wrapper.php index 4feb0520f12..0336c27efa1 100644 --- a/lib/files/storage/wrapper/wrapper.php +++ b/lib/files/storage/wrapper/wrapper.php @@ -395,7 +395,7 @@ class Wrapper implements \OC\Files\Storage\Storage { * @return \OC\Files\Cache\Permissions */ public function getPermissionsCache($path = '') { - return $this->storage->getPermissions($path); + return $this->storage->getPermissionsCache($path); } /** |