From 46626915ef6888c958111b259ae6c0d3729b5198 Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Sat, 16 Feb 2013 01:30:44 +0100 Subject: Use a parser to read custom mount configuration instead of including the php files --- lib/files/filesystem.php | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) (limited to 'lib/files/filesystem.php') diff --git a/lib/files/filesystem.php b/lib/files/filesystem.php index f4530868077..89a9ab29212 100644 --- a/lib/files/filesystem.php +++ b/lib/files/filesystem.php @@ -215,9 +215,11 @@ class Filesystem { if ($user == '') { $user = \OC_User::getUser(); } + $parser = new \OC\ArrayParser(); + // Load system mount points if (is_file(\OC::$SERVERROOT . '/config/mount.php')) { - $mountConfig = include 'config/mount.php'; + $mountConfig = $parser->parsePHP(file_get_contents(\OC::$SERVERROOT . '/config/mount.php')); if (isset($mountConfig['global'])) { foreach ($mountConfig['global'] as $mountPoint => $options) { self::mount($options['class'], $options['options'], $mountPoint); @@ -254,7 +256,7 @@ class Filesystem { $root = \OC_User::getHome($user); self::mount('\OC\Files\Storage\Local', array('datadir' => $root), $user); if (is_file($root . '/mount.php')) { - $mountConfig = include $root . '/mount.php'; + $mountConfig = $parser->parsePHP(file_get_contents($root . '/mount.php')); if (isset($mountConfig['user'][$user])) { foreach ($mountConfig['user'][$user] as $mountPoint => $options) { self::mount($options['class'], $options['options'], $mountPoint); @@ -613,11 +615,11 @@ class Filesystem { } /** - * Get the owner for a file or folder - * - * @param string $path - * @return string - */ + * Get the owner for a file or folder + * + * @param string $path + * @return string + */ public static function getOwner($path) { return self::$defaultInstance->getOwner($path); } -- cgit v1.2.3 From 6da2c6c83e48fc3c7f8dd0814fe815d2b772f6eb Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Sat, 16 Feb 2013 01:50:40 +0100 Subject: Create new mountconfig files in json --- apps/files_external/lib/config.php | 45 ++++++++++++-------------------------- lib/files/filesystem.php | 16 ++++++++++---- 2 files changed, 26 insertions(+), 35 deletions(-) (limited to 'lib/files/filesystem.php') diff --git a/apps/files_external/lib/config.php b/apps/files_external/lib/config.php index 6ef7f37f58b..36ef48462a7 100755 --- a/apps/files_external/lib/config.php +++ b/apps/files_external/lib/config.php @@ -281,12 +281,19 @@ class OC_Mount_Config { private static function readData($isPersonal) { $parser = new \OC\ArrayParser(); if ($isPersonal) { - $file = OC_User::getHome(OCP\User::getUser()).'/mount.php'; + $phpFile = OC_User::getHome(OCP\User::getUser()).'/mount.php'; + $jsonFile = OC_User::getHome(OCP\User::getUser()).'/mount.json'; } else { - $file = OC::$SERVERROOT.'/config/mount.php'; + $phpFile = OC::$SERVERROOT.'/config/mount.php'; + $jsonFile = OC::$SERVERROOT.'/config/mount.json'; } - if (is_file($file)) { - $mountPoints = $parser->parsePHP(file_get_contents($file)); + if (is_file($jsonFile)) { + $mountPoints = json_decode(file_get_contents($jsonFile), true); + if (is_array($mountPoints)) { + return $mountPoints; + } + } elseif (is_file($phpFile)) { + $mountPoints = $parser->parsePHP(file_get_contents($phpFile)); if (is_array($mountPoints)) { return $mountPoints; } @@ -301,35 +308,11 @@ class OC_Mount_Config { */ private static function writeData($isPersonal, $data) { if ($isPersonal) { - $file = OC_User::getHome(OCP\User::getUser()).'/mount.php'; + $file = OC_User::getHome(OCP\User::getUser()).'/mount.json'; } else { - $file = OC::$SERVERROOT.'/config/mount.php'; - } - $content = " array (\n"; - foreach ($data[self::MOUNT_TYPE_GROUP] as $group => $mounts) { - $content .= "\t\t'".$group."' => array (\n"; - foreach ($mounts as $mountPoint => $mount) { - $content .= "\t\t\t'".addcslashes($mountPoint, "'")."' => ".str_replace("\n", '', var_export($mount, true)).", \n"; - - } - $content .= "\t\t),\n"; - } - $content .= "\t),\n"; - } - if (isset($data[self::MOUNT_TYPE_USER])) { - $content .= "\t'user' => array (\n"; - foreach ($data[self::MOUNT_TYPE_USER] as $user => $mounts) { - $content .= "\t\t'".$user."' => array (\n"; - foreach ($mounts as $mountPoint => $mount) { - $content .= "\t\t\t'".addcslashes($mountPoint, "'")."' => ".str_replace("\n", '', var_export($mount, true)).",\n"; - } - $content .= "\t\t),\n"; - } - $content .= "\t),\n"; + $file = OC::$SERVERROOT.'/config/mount.json'; } - $content .= ");\n?>"; + $content = json_encode($data); @file_put_contents($file, $content); } diff --git a/lib/files/filesystem.php b/lib/files/filesystem.php index 89a9ab29212..cba469e06c4 100644 --- a/lib/files/filesystem.php +++ b/lib/files/filesystem.php @@ -218,8 +218,12 @@ class Filesystem { $parser = new \OC\ArrayParser(); // Load system mount points - if (is_file(\OC::$SERVERROOT . '/config/mount.php')) { - $mountConfig = $parser->parsePHP(file_get_contents(\OC::$SERVERROOT . '/config/mount.php')); + if (is_file(\OC::$SERVERROOT . '/config/mount.php') or is_file(\OC::$SERVERROOT . '/config/mount.json')) { + if(is_file(\OC::$SERVERROOT . '/config/mount.json')){ + $mountConfig = json_decode(file_get_contents(\OC::$SERVERROOT . '/config/mount.json'), true); + }elseif(is_file(\OC::$SERVERROOT . '/config/mount.php')){ + $mountConfig = $parser->parsePHP(file_get_contents(\OC::$SERVERROOT . '/config/mount.php')); + } if (isset($mountConfig['global'])) { foreach ($mountConfig['global'] as $mountPoint => $options) { self::mount($options['class'], $options['options'], $mountPoint); @@ -255,8 +259,12 @@ class Filesystem { // Load personal mount points $root = \OC_User::getHome($user); self::mount('\OC\Files\Storage\Local', array('datadir' => $root), $user); - if (is_file($root . '/mount.php')) { - $mountConfig = $parser->parsePHP(file_get_contents($root . '/mount.php')); + if (is_file($root . '/mount.php') or is_file($root . '/mount.json')) { + if (is_file($root . '/mount.json')){ + $mountConfig = json_decode(file_get_contents($root . '/mount.json'), true); + } elseif (is_file($root . '/mount.php')){ + $mountConfig = $parser->parsePHP(file_get_contents($root . '/mount.php')); + } if (isset($mountConfig['user'][$user])) { foreach ($mountConfig['user'][$user] as $mountPoint => $options) { self::mount($options['class'], $options['options'], $mountPoint); -- cgit v1.2.3 From d96146a017bd8f7e4573e4555cea2c198fa9fbad Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Sat, 16 Feb 2013 03:27:50 +0100 Subject: Give storage backends the option to define having no known free space When this is the case only the configured max upload size is taking into account for uploading --- apps/files/ajax/upload.php | 2 +- apps/files_external/lib/amazons3.php | 5 ----- apps/files_external/lib/sftp.php | 4 ---- apps/files_external/lib/streamwrapper.php | 4 ---- apps/files_external/lib/swift.php | 4 ---- apps/files_external/lib/webdav.php | 2 +- lib/files/filesystem.php | 2 ++ lib/files/storage/common.php | 9 +++++++++ lib/helper.php | 8 ++++++-- 9 files changed, 19 insertions(+), 21 deletions(-) (limited to 'lib/files/filesystem.php') diff --git a/apps/files/ajax/upload.php b/apps/files/ajax/upload.php index 07977f5ddf1..9031c729eff 100644 --- a/apps/files/ajax/upload.php +++ b/apps/files/ajax/upload.php @@ -48,7 +48,7 @@ $totalSize = 0; foreach ($files['size'] as $size) { $totalSize += $size; } -if ($totalSize > \OC\Files\Filesystem::free_space($dir)) { +if ($totalSize > $maxUploadFilesize) { OCP\JSON::error(array('data' => array('message' => $l->t('Not enough storage available'), 'uploadMaxFilesize' => $maxUploadFilesize, 'maxHumanFilesize' => $maxHumanFilesize))); diff --git a/apps/files_external/lib/amazons3.php b/apps/files_external/lib/amazons3.php index 494885a1dd3..37e53a3a670 100644 --- a/apps/files_external/lib/amazons3.php +++ b/apps/files_external/lib/amazons3.php @@ -229,11 +229,6 @@ class AmazonS3 extends \OC\Files\Storage\Common { return false; } - public function free_space($path) { - // Infinite? - return false; - } - public function touch($path, $mtime = null) { if (is_null($mtime)) { $mtime = time(); diff --git a/apps/files_external/lib/sftp.php b/apps/files_external/lib/sftp.php index 551a5a64ef2..77c08d3b733 100644 --- a/apps/files_external/lib/sftp.php +++ b/apps/files_external/lib/sftp.php @@ -241,10 +241,6 @@ class SFTP extends \OC\Files\Storage\Common { } } - public function free_space($path) { - return -1; - } - public function touch($path, $mtime=null) { try { if (!is_null($mtime)) return false; diff --git a/apps/files_external/lib/streamwrapper.php b/apps/files_external/lib/streamwrapper.php index a631e7ce06a..4685877f26b 100644 --- a/apps/files_external/lib/streamwrapper.php +++ b/apps/files_external/lib/streamwrapper.php @@ -76,10 +76,6 @@ abstract class StreamWrapper extends \OC\Files\Storage\Common{ return fopen($this->constructUrl($path), $mode); } - public function free_space($path) { - return 0; - } - public function touch($path, $mtime=null) { $this->init(); if(is_null($mtime)) { diff --git a/apps/files_external/lib/swift.php b/apps/files_external/lib/swift.php index 0fd6fa143b8..a00316c1f84 100644 --- a/apps/files_external/lib/swift.php +++ b/apps/files_external/lib/swift.php @@ -478,10 +478,6 @@ class SWIFT extends \OC\Files\Storage\Common{ } } - public function free_space($path) { - return 1024*1024*1024*8; - } - public function touch($path, $mtime=null) { $this->init(); $obj=$this->getObject($path); diff --git a/apps/files_external/lib/webdav.php b/apps/files_external/lib/webdav.php index 039a07b1ef2..91cc22779e6 100644 --- a/apps/files_external/lib/webdav.php +++ b/apps/files_external/lib/webdav.php @@ -222,7 +222,7 @@ class DAV extends \OC\Files\Storage\Common{ return 0; } } catch(\Exception $e) { - return 0; + return \OC\Files\FREE_SPACE_UNKNOWN; } } diff --git a/lib/files/filesystem.php b/lib/files/filesystem.php index f4530868077..0dafef836bd 100644 --- a/lib/files/filesystem.php +++ b/lib/files/filesystem.php @@ -29,6 +29,8 @@ namespace OC\Files; +const FREE_SPACE_UNKNOWN = -2; + class Filesystem { public static $loaded = false; /** diff --git a/lib/files/storage/common.php b/lib/files/storage/common.php index 4cdabf1c8a6..4e7a73e5d4a 100644 --- a/lib/files/storage/common.php +++ b/lib/files/storage/common.php @@ -301,4 +301,13 @@ abstract class Common implements \OC\Files\Storage\Storage { } return implode('/', $output); } + + /** + * get the free space in the storage + * @param $path + * return int + */ + public function free_space($path){ + return \OC\Files\FREE_SPACE_UNKNOWN; + } } diff --git a/lib/helper.php b/lib/helper.php index 0f810ffc0c2..add5c66e7be 100644 --- a/lib/helper.php +++ b/lib/helper.php @@ -762,9 +762,13 @@ class OC_Helper { $maxUploadFilesize = min($upload_max_filesize, $post_max_size); $freeSpace = \OC\Files\Filesystem::free_space($dir); - $freeSpace = max($freeSpace, 0); + if($freeSpace !== \OC\Files\FREE_SPACE_UNKNOWN){ + $freeSpace = max($freeSpace, 0); - return min($maxUploadFilesize, $freeSpace); + return min($maxUploadFilesize, $freeSpace); + } else { + return $maxUploadFilesize; + } } /** -- cgit v1.2.3