From 4e5a3fbcafcaa0cdaba351dfb307b0000179c832 Mon Sep 17 00:00:00 2001 From: Administrator Date: Sun, 10 Feb 2013 14:08:00 +0100 Subject: - Fixed indentations. - Fixed a bug in legacy.php: there was an error that was not checked for if the table 'fscache' did not exist in the database. --- lib/files/cache/legacy.php | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'lib/files') diff --git a/lib/files/cache/legacy.php b/lib/files/cache/legacy.php index 33d4b8e7c9f..bdc3cbf00b2 100644 --- a/lib/files/cache/legacy.php +++ b/lib/files/cache/legacy.php @@ -51,6 +51,12 @@ class Legacy { $this->cacheHasItems = false; return false; } + + if ($result === false || property_exists($result, 'error_message_prefix')) { + $this->cacheHasItems = false; + return false; + } + $this->cacheHasItems = (bool)$result->fetchRow(); return $this->cacheHasItems; } -- cgit v1.2.3 From 78a3625ddfc67e7e6743a2ff6fd31e1566b174c8 Mon Sep 17 00:00:00 2001 From: Thomas Mueller Date: Thu, 14 Feb 2013 21:59:24 +0100 Subject: final adoptions for mssql connectivity --- lib/db.php | 7 +++++++ lib/files/cache/cache.php | 6 +++--- tests/lib/dbschema.php | 12 +++++++++--- 3 files changed, 19 insertions(+), 6 deletions(-) (limited to 'lib/files') diff --git a/lib/db.php b/lib/db.php index 3ccd51737ae..903f76c8c04 100644 --- a/lib/db.php +++ b/lib/db.php @@ -404,6 +404,13 @@ class OC_DB { $query = self::prepare('SELECT lastval() AS id'); $row = $query->execute()->fetchRow(); return $row['id']; + } + if( $type == 'mssql' ) { + if($table !== null) { + $prefix = OC_Config::getValue( "dbtableprefix", "oc_" ); + $table = str_replace( '*PREFIX*', $prefix, $table ); + } + return self::$connection->lastInsertId($table); }else{ if($table !== null) { $prefix = OC_Config::getValue( "dbtableprefix", "oc_" ); diff --git a/lib/files/cache/cache.php b/lib/files/cache/cache.php index dcb6e8fd39a..b61f1de4483 100644 --- a/lib/files/cache/cache.php +++ b/lib/files/cache/cache.php @@ -56,7 +56,7 @@ class Cache { } else { $query = \OC_DB::prepare('INSERT INTO `*PREFIX*storages`(`id`) VALUES(?)'); $query->execute(array($this->storageId)); - $this->numericId = \OC_DB::insertid('*PREFIX*filecache'); + $this->numericId = \OC_DB::insertid('*PREFIX*storages'); } } @@ -493,8 +493,8 @@ class Cache { */ public function getIncomplete() { $query = \OC_DB::prepare('SELECT `path` FROM `*PREFIX*filecache` WHERE `storage` = ? AND `size` = -1 ORDER BY `fileid` DESC LIMIT 1'); - $query->execute(array($this->numericId)); - if ($row = $query->fetchRow()) { + $result = $query->execute(array($this->numericId)); + if ($row = $result->fetchRow()) { return $row['path']; } else { return false; diff --git a/tests/lib/dbschema.php b/tests/lib/dbschema.php index fb60ce7dbb7..e20a04ef7fd 100644 --- a/tests/lib/dbschema.php +++ b/tests/lib/dbschema.php @@ -91,9 +91,15 @@ class Test_DBSchema extends PHPUnit_Framework_TestCase { break; case 'pgsql': $sql = "SELECT tablename AS table_name, schemaname AS schema_name " - . "FROM pg_tables WHERE schemaname NOT LIKE 'pg_%' " - . "AND schemaname != 'information_schema' " - . "AND tablename = '".$table."'"; + . "FROM pg_tables WHERE schemaname NOT LIKE 'pg_%' " + . "AND schemaname != 'information_schema' " + . "AND tablename = '".$table."'"; + $query = OC_DB::prepare($sql); + $result = $query->execute(array()); + $exists = $result && $result->fetchOne(); + break; + case 'mssql': + $sql = "SELECT * FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = '{$table}'"; $query = OC_DB::prepare($sql); $result = $query->execute(array()); $exists = $result && $result->fetchOne(); -- cgit v1.2.3 From b488800bd5665eaa11b54002509e9e8b85c0780e Mon Sep 17 00:00:00 2001 From: Thomas Mueller Date: Fri, 15 Feb 2013 17:41:22 +0100 Subject: fix error in recursive search --- lib/files/storage/mappedlocal.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'lib/files') diff --git a/lib/files/storage/mappedlocal.php b/lib/files/storage/mappedlocal.php index e707f71d71c..434c10bcbf7 100644 --- a/lib/files/storage/mappedlocal.php +++ b/lib/files/storage/mappedlocal.php @@ -20,7 +20,7 @@ class MappedLocal extends \OC\Files\Storage\Common{ $this->datadir.='/'; } - $this->mapper= new \OC\Files\Mapper(); + $this->mapper= new \OC\Files\Mapper($this->datadir); } public function __destruct() { if (defined('PHPUNIT_RUN')) { @@ -274,7 +274,7 @@ class MappedLocal extends \OC\Files\Storage\Common{ return $this->buildPath($path); } - protected function searchInDir($query, $dir='', $isLogicPath=true) { + protected function searchInDir($query, $dir='') { $files=array(); $physicalDir = $this->buildPath($dir); foreach (scandir($physicalDir) as $item) { @@ -287,7 +287,7 @@ class MappedLocal extends \OC\Files\Storage\Common{ $files[]=$dir.'/'.$item; } if(is_dir($physicalItem)) { - $files=array_merge($files, $this->searchInDir($query, $physicalItem, false)); + $files=array_merge($files, $this->searchInDir($query, $dir.'/'.$item)); } } return $files; -- cgit v1.2.3 From 40739350c9b674551f0b218220054ec4f303f154 Mon Sep 17 00:00:00 2001 From: Thomas Mueller Date: Fri, 15 Feb 2013 17:42:17 +0100 Subject: class Mapper no respects an unchanged physical root which will be excluded from slugifying the path --- lib/files/mapper.php | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) (limited to 'lib/files') diff --git a/lib/files/mapper.php b/lib/files/mapper.php index cd163dcbfcd..520fadbd8c6 100644 --- a/lib/files/mapper.php +++ b/lib/files/mapper.php @@ -7,6 +7,12 @@ namespace OC\Files; */ class Mapper { + private $unchangedPhysicalRoot; + + public function __construct($rootDir) { + $this->unchangedPhysicalRoot = $rootDir; + } + /** * @param string $logicPath * @param bool $create indicates if the generated physical name shall be stored in the database or not @@ -23,7 +29,7 @@ class Mapper /** * @param string $physicalPath - * @return string|null + * @return string */ public function physicalToLogic($physicalPath) { $logicPath = $this->resolvePhysicalPath($physicalPath); @@ -39,6 +45,7 @@ class Mapper * @param string $path * @param bool $isLogicPath indicates if $path is logical or physical * @param $recursive + * @return void */ public function removePath($path, $isLogicPath, $recursive) { if ($recursive) { @@ -159,14 +166,11 @@ class Mapper } private function slugifyPath($path, $index=null) { + $path = $this->stripRootFolder($path, $this->unchangedPhysicalRoot); + $pathElements = explode('/', $path); $sluggedElements = array(); - // skip slugging the drive letter on windows - TODO: test if local path - if (\OC_Util::runningOnWindows()) { - $sluggedElements[]= $pathElements[0]; - array_shift($pathElements); - } foreach ($pathElements as $pathElement) { // remove empty elements if (empty($pathElement)) { @@ -186,12 +190,8 @@ class Mapper array_push($sluggedElements, $last.'-'.$index); } - // on non-windows systems add the leading / if necessary - if (!\OC_Util::runningOnWindows() and $path[0] === '/') { - return DIRECTORY_SEPARATOR.implode(DIRECTORY_SEPARATOR, $sluggedElements); - } - - return implode(DIRECTORY_SEPARATOR, $sluggedElements); + $sluggedPath = $this->unchangedPhysicalRoot.implode(DIRECTORY_SEPARATOR, $sluggedElements); + return $this->stripLast($sluggedPath); } /** -- cgit v1.2.3 From 0c1ec758e89517acac8971f87e3c5796124e40ca Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Fri, 15 Feb 2013 21:49:40 +0100 Subject: Cache: hash long storage ids to ensure they fit in the database --- lib/files/cache/cache.php | 11 +++++++---- lib/files/mount.php | 6 ++++++ tests/lib/files/cache/cache.php | 15 +++++++++++++++ tests/lib/files/mount.php | 17 +++++++++++++++++ 4 files changed, 45 insertions(+), 4 deletions(-) (limited to 'lib/files') diff --git a/lib/files/cache/cache.php b/lib/files/cache/cache.php index 5feed37ae48..3652dc7cf23 100644 --- a/lib/files/cache/cache.php +++ b/lib/files/cache/cache.php @@ -48,6 +48,9 @@ class Cache { } else { $this->storageId = $storage; } + if (strlen($this->storageId) > 64) { + $this->storageId = md5($this->storageId); + } $query = \OC_DB::prepare('SELECT `numeric_id` FROM `*PREFIX*storages` WHERE `id` = ?'); $result = $query->execute(array($this->storageId)); @@ -199,7 +202,7 @@ class Cache { $valuesPlaceholder = array_fill(0, count($queryParts), '?'); $query = \OC_DB::prepare('INSERT INTO `*PREFIX*filecache`(' . implode(', ', $queryParts) . ')' - .' VALUES(' . implode(', ', $valuesPlaceholder) . ')'); + . ' VALUES(' . implode(', ', $valuesPlaceholder) . ')'); $query->execute($params); return (int)\OC_DB::insertid('*PREFIX*filecache'); @@ -217,7 +220,7 @@ class Cache { $params[] = $id; $query = \OC_DB::prepare('UPDATE `*PREFIX*filecache` SET ' . implode(' = ?, ', $queryParts) . '=?' - .' WHERE fileid = ?'); + . ' WHERE fileid = ?'); $query->execute($params); } @@ -335,7 +338,7 @@ class Cache { } $query = \OC_DB::prepare('UPDATE `*PREFIX*filecache` SET `path` = ?, `path_hash` = ?, `parent` =?' - .' WHERE `fileid` = ?'); + . ' WHERE `fileid` = ?'); $query->execute(array($target, md5($target), $newParentId, $sourceId)); } @@ -496,7 +499,7 @@ class Cache { */ public function getIncomplete() { $query = \OC_DB::prepare('SELECT `path` FROM `*PREFIX*filecache`' - .' WHERE `storage` = ? AND `size` = -1 ORDER BY `fileid` DESC LIMIT 1'); + . ' WHERE `storage` = ? AND `size` = -1 ORDER BY `fileid` DESC LIMIT 1'); $query->execute(array($this->numericId)); if ($row = $query->fetchRow()) { return $row['path']; diff --git a/lib/files/mount.php b/lib/files/mount.php index 74ee483b1be..6e99d8eabb4 100644 --- a/lib/files/mount.php +++ b/lib/files/mount.php @@ -93,6 +93,9 @@ class Mount { $this->storage = $this->createStorage(); } $this->storageId = $this->storage->getId(); + if (strlen($this->storageId) > 64) { + $this->storageId = md5($this->storageId); + } } return $this->storageId; } @@ -177,6 +180,9 @@ class Mount { * @return \OC\Files\Storage\Storage[] */ public static function findById($id) { + if (strlen($id) > 64) { + $id = md5($id); + } $result = array(); foreach (self::$mounts as $mount) { if ($mount->getStorageId() === $id) { diff --git a/tests/lib/files/cache/cache.php b/tests/lib/files/cache/cache.php index c466fbb63e7..250842805e5 100644 --- a/tests/lib/files/cache/cache.php +++ b/tests/lib/files/cache/cache.php @@ -8,6 +8,12 @@ namespace Test\Files\Cache; +class LongId extends \OC\Files\Storage\Temporary { + public function getId() { + return 'long:' . str_repeat('foo', 50) . parent::getId(); + } +} + class Cache extends \PHPUnit_Framework_TestCase { /** * @var \OC\Files\Storage\Temporary $storage; @@ -204,6 +210,15 @@ class Cache extends \PHPUnit_Framework_TestCase { $this->assertEquals(array($storageId, 'foo'), \OC\Files\Cache\Cache::getById($id)); } + function testLongId() { + $storage = new LongId(array()); + $cache = $storage->getCache(); + $storageId = $storage->getId(); + $data = array('size' => 1000, 'mtime' => 20, 'mimetype' => 'foo/file'); + $id = $cache->put('foo', $data); + $this->assertEquals(array(md5($storageId), 'foo'), \OC\Files\Cache\Cache::getById($id)); + } + public function tearDown() { $this->cache->clear(); } diff --git a/tests/lib/files/mount.php b/tests/lib/files/mount.php index f223f0f6c53..4e6aaf0679b 100644 --- a/tests/lib/files/mount.php +++ b/tests/lib/files/mount.php @@ -10,6 +10,12 @@ namespace Test\Files; use \OC\Files\Storage\Temporary; +class LongId extends Temporary { + public function getId() { + return 'long:' . str_repeat('foo', 50) . parent::getId(); + } +} + class Mount extends \PHPUnit_Framework_TestCase { public function setup() { \OC_Util::setupFS(); @@ -38,4 +44,15 @@ class Mount extends \PHPUnit_Framework_TestCase { $mount2 = new \OC\Files\Mount($storage, '/foo/bar'); $this->assertEquals(array($mount, $mount2), \OC\Files\Mount::findById($id)); } + + public function testLong() { + $storage = new LongId(array()); + $mount = new \OC\Files\Mount($storage, '/foo'); + + $id = $mount->getStorageId(); + $storageId = $storage->getId(); + $this->assertEquals(array($mount), \OC\Files\Mount::findById($id)); + $this->assertEquals(array($mount), \OC\Files\Mount::findById($storageId)); + $this->assertEquals(array($mount), \OC\Files\Mount::findById(md5($storageId))); + } } -- cgit v1.2.3 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 --- apps/files_external/lib/config.php | 3 +- lib/arrayparser.php | 189 +++++++++++++++++++++++++++++++++++++ lib/files/filesystem.php | 16 ++-- 3 files changed, 200 insertions(+), 8 deletions(-) create mode 100644 lib/arrayparser.php (limited to 'lib/files') diff --git a/apps/files_external/lib/config.php b/apps/files_external/lib/config.php index 44e668a09c0..6ef7f37f58b 100755 --- a/apps/files_external/lib/config.php +++ b/apps/files_external/lib/config.php @@ -279,13 +279,14 @@ class OC_Mount_Config { * @return array */ private static function readData($isPersonal) { + $parser = new \OC\ArrayParser(); if ($isPersonal) { $file = OC_User::getHome(OCP\User::getUser()).'/mount.php'; } else { $file = OC::$SERVERROOT.'/config/mount.php'; } if (is_file($file)) { - $mountPoints = include $file; + $mountPoints = $parser->parsePHP(file_get_contents($file)); if (is_array($mountPoints)) { return $mountPoints; } diff --git a/lib/arrayparser.php b/lib/arrayparser.php new file mode 100644 index 00000000000..3bb394a5163 --- /dev/null +++ b/lib/arrayparser.php @@ -0,0 +1,189 @@ +. + * + */ + +namespace OC; + +class SyntaxException extends \Exception { +} + +class ArrayParser { + const TYPE_NUM = 1; + const TYPE_BOOL = 2; + const TYPE_STRING = 3; + const TYPE_ARRAY = 4; + + function parsePHP($string) { + $string = $this->stripPHPTags($string); + $string = $this->stripAssignAndReturn($string); + return $this->parse($string); + } + + function stripPHPTags($string) { + $string = trim($string); + if (substr($string, 0, 5) === '') { + $string = substr($string, 0, -2); + } + return $string; + } + + function stripAssignAndReturn($string) { + $string = trim($string); + if (substr($string, 0, 6) === 'return') { + $string = substr($string, 6); + } + if (substr($string, 0, 1) === '$') { + list(, $string) = explode('=', $string, 2); + } + return $string; + } + + function parse($string) { + $string = trim($string); + $string = trim($string, ';'); + switch ($this->getType($string)) { + case self::TYPE_NUM: + return $this->parseNum($string); + case self::TYPE_BOOL: + return $this->parseBool($string); + case self::TYPE_STRING: + return $this->parseString($string); + case self::TYPE_ARRAY: + return $this->parseArray($string); + } + return null; + } + + function getType($string) { + $string = strtolower($string); + $first = substr($string, 0, 1); + $last = substr($string, -1, 1); + $arrayFirst = substr($string, 0, 5); + if (($first === '"' or $first === "'") and ($last === '"' or $last === "'")) { + return self::TYPE_STRING; + } elseif ($string === 'false' or $string === 'true') { + return self::TYPE_BOOL; + } elseif ($arrayFirst === 'array' and $last === ')') { + return self::TYPE_ARRAY; + } else { + return self::TYPE_NUM; + } + } + + function parseString($string) { + return substr($string, 1, -1); + } + + function parseNum($string) { + return intval($string); + } + + function parseBool($string) { + $string = strtolower($string); + return $string === 'true'; + } + + function parseArray($string) { + $body = substr($string, 5); + $body = trim($body); + $body = substr($body, 1, -1); + $items = $this->splitArray($body); + $result = array(); + $lastKey = -1; + foreach ($items as $item) { + $item = trim($item); + if ($item) { + if (strpos($item, '=>')) { + list($key, $value) = explode('=>', $item, 2); + $key = $this->parse($key); + $value = $this->parse($value); + } else { + $key = ++$lastKey; + $value = $item; + } + + if (is_numeric($key)) { + $lastKey = $key; + } + $result[$key] = $value; + } + } + return $result; + } + + function splitArray($body) { + $inSingleQuote = false;//keep track if we are inside quotes + $inDoubleQuote = false; + $bracketDepth = 0;//keep track if we are inside brackets + $parts = array(); + $start = 0; + $escaped = false;//keep track if we are after an escape character + $skips = array();//keep track of the escape characters we need to remove from the result + if (substr($body, -1, 1) !== ',') { + $body .= ','; + } + for ($i = 0; $i < strlen($body); $i++) { + $char = substr($body, $i, 1); + if ($char === '\\') { + if ($escaped) { + array_unshift($skips, $i - 1); + } + $escaped = !$escaped; + } else { + if ($char === '"' and !$inSingleQuote) { + if ($escaped) { + array_unshift($skips, $i - 1); + } else { + $inDoubleQuote = !$inDoubleQuote; + } + } elseif ($char === "'" and !$inDoubleQuote) { + if ($escaped) { + array_unshift($skips, $i - 1); + } else { + $inSingleQuote = !$inSingleQuote; + } + } elseif (!$inDoubleQuote and !$inSingleQuote) { + if ($char === '(') { + $bracketDepth++; + } elseif ($char === ')') { + if ($bracketDepth <= 0) { + throw new SyntaxException; + } else { + $bracketDepth--; + } + } elseif ($bracketDepth === 0 and $char === ',') { + $part = substr($body, $start, $i - $start); + foreach ($skips as $skip) { + $part = substr($part, 0, $skip - $start) . substr($part, $skip - $start + 1); + } + $parts[] = $part; + $start = $i + 1; + $skips = array(); + } + } + $escaped = false; + } + } + return $parts; + } +} 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') 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') 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 From f51d8c1cd93f974a69252527ca020ab903b57656 Mon Sep 17 00:00:00 2001 From: Georg Ehrke Date: Fri, 22 Feb 2013 14:19:29 +0100 Subject: fix order of mount commands --- lib/files/filesystem.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'lib/files') diff --git a/lib/files/filesystem.php b/lib/files/filesystem.php index 875a9d6c5ee..8f171283207 100644 --- a/lib/files/filesystem.php +++ b/lib/files/filesystem.php @@ -219,6 +219,9 @@ class Filesystem { } $parser = new \OC\ArrayParser(); + $root = \OC_User::getHome($user); + self::mount('\OC\Files\Storage\Local', array('datadir' => $root), $user); + // Load system mount points if (is_file(\OC::$SERVERROOT . '/config/mount.php') or is_file(\OC::$SERVERROOT . '/config/mount.json')) { if(is_file(\OC::$SERVERROOT . '/config/mount.json')){ @@ -259,8 +262,6 @@ 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') or is_file($root . '/mount.json')) { if (is_file($root . '/mount.json')){ $mountConfig = json_decode(file_get_contents($root . '/mount.json'), true); -- cgit v1.2.3 From 5b949596867c986916568e5bea2003e04102aa71 Mon Sep 17 00:00:00 2001 From: Björn Schießle Date: Fri, 22 Feb 2013 14:56:50 +0100 Subject: using the number of writen bytes as indicator if streamCopy() was successfully. Instead check if fwrite returns the number of bytes or false --- lib/files/view.php | 3 +-- lib/helper.php | 8 +++++--- 2 files changed, 6 insertions(+), 5 deletions(-) (limited to 'lib/files') diff --git a/lib/files/view.php b/lib/files/view.php index 9ac08c98082..11edbadab9b 100644 --- a/lib/files/view.php +++ b/lib/files/view.php @@ -361,10 +361,9 @@ class View { } else { $source = $this->fopen($path1 . $postFix1, 'r'); $target = $this->fopen($path2 . $postFix2, 'w'); - $count = \OC_Helper::streamCopy($source, $target); + $result = \OC_Helper::streamCopy($source, $target); list($storage1, $internalPath1) = Filesystem::resolvePath($absolutePath1 . $postFix1); $storage1->unlink($internalPath1); - $result = $count > 0; } if ($this->fakeRoot == Filesystem::getRoot()) { \OC_Hook::emit( diff --git a/lib/helper.php b/lib/helper.php index add5c66e7be..2c9cd36b199 100644 --- a/lib/helper.php +++ b/lib/helper.php @@ -513,11 +513,13 @@ class OC_Helper { if(!$source or !$target) { return false; } - $count=0; + $result=true; while(!feof($source)) { - $count+=fwrite($target, fread($source, 8192)); + if (fwrite($target, fread($source, 8192)) === false) { + $result = false; + } } - return $count; + return $result; } /** -- cgit v1.2.3 From 62c65bc1c857c3a82152cf33694f251a235b8afa Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Fri, 22 Feb 2013 16:13:08 +0100 Subject: Add OC\Files\Filesystem::isFileBlacklisted --- lib/files/filesystem.php | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) (limited to 'lib/files') diff --git a/lib/files/filesystem.php b/lib/files/filesystem.php index 875a9d6c5ee..36a21288b4d 100644 --- a/lib/files/filesystem.php +++ b/lib/files/filesystem.php @@ -221,9 +221,9 @@ class Filesystem { // Load system mount points if (is_file(\OC::$SERVERROOT . '/config/mount.php') or is_file(\OC::$SERVERROOT . '/config/mount.json')) { - if(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')){ + } elseif (is_file(\OC::$SERVERROOT . '/config/mount.php')) { $mountConfig = $parser->parsePHP(file_get_contents(\OC::$SERVERROOT . '/config/mount.php')); } if (isset($mountConfig['global'])) { @@ -262,9 +262,9 @@ class Filesystem { $root = \OC_User::getHome($user); self::mount('\OC\Files\Storage\Local', array('datadir' => $root), $user); if (is_file($root . '/mount.php') or is_file($root . '/mount.json')) { - if (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')){ + } elseif (is_file($root . '/mount.php')) { $mountConfig = $parser->parsePHP(file_get_contents($root . '/mount.php')); } if (isset($mountConfig['user'][$user])) { @@ -389,20 +389,28 @@ class Filesystem { * @param array $data from hook */ static public function isBlacklisted($data) { - $blacklist = \OC_Config::getValue('blacklisted_files', array('.htaccess')); if (isset($data['path'])) { $path = $data['path']; } else if (isset($data['newpath'])) { $path = $data['newpath']; } if (isset($path)) { - $filename = strtolower(basename($path)); - if (in_array($filename, $blacklist)) { + if (self::isFileBlacklisted($path)) { $data['run'] = false; } } } + /** + * @param string $filename + * @return bool + */ + static public function isFileBlacklisted($filename) { + $blacklist = \OC_Config::getValue('blacklisted_files', array('.htaccess')); + $filename = strtolower(basename($filename)); + return (in_array($filename, $blacklist)); + } + /** * following functions are equivalent to their php builtin equivalents for arguments/return values. */ -- cgit v1.2.3 From d8137fdf66a513d0de4bb234d0427ff27ca40106 Mon Sep 17 00:00:00 2001 From: Björn Schießle Date: Fri, 22 Feb 2013 16:43:11 +0100 Subject: return both, count and result if the operation succeeded or failed. Maybe in some cases it is useful to know how much bytes where copied --- apps/files_sharing/lib/sharedstorage.php | 3 ++- lib/files/storage/common.php | 4 ++-- lib/files/view.php | 8 ++++---- lib/helper.php | 9 ++++++--- lib/public/files.php | 3 ++- 5 files changed, 16 insertions(+), 11 deletions(-) (limited to 'lib/files') diff --git a/apps/files_sharing/lib/sharedstorage.php b/apps/files_sharing/lib/sharedstorage.php index 65812b7e2fd..e920329ae49 100644 --- a/apps/files_sharing/lib/sharedstorage.php +++ b/apps/files_sharing/lib/sharedstorage.php @@ -314,7 +314,8 @@ class Shared extends \OC\Files\Storage\Common { if ($this->isCreatable(dirname($path2))) { $source = $this->fopen($path1, 'r'); $target = $this->fopen($path2, 'w'); - return \OC_Helper::streamCopy($source, $target); + list ($count, $result) = \OC_Helper::streamCopy($source, $target); + return $result; } return false; } diff --git a/lib/files/storage/common.php b/lib/files/storage/common.php index 4e7a73e5d4a..fd9ae844a8e 100644 --- a/lib/files/storage/common.php +++ b/lib/files/storage/common.php @@ -97,8 +97,8 @@ abstract class Common implements \OC\Files\Storage\Storage { public function copy($path1, $path2) { $source=$this->fopen($path1, 'r'); $target=$this->fopen($path2, 'w'); - $count=\OC_Helper::streamCopy($source, $target); - return $count>0; + list($count, $result) = \OC_Helper::streamCopy($source, $target); + return $result; } /** diff --git a/lib/files/view.php b/lib/files/view.php index 11edbadab9b..f48d0c8b225 100644 --- a/lib/files/view.php +++ b/lib/files/view.php @@ -285,7 +285,7 @@ class View { } $target = $this->fopen($path, 'w'); if ($target) { - $count = \OC_Helper::streamCopy($data, $target); + list ($count, $result) = \OC_Helper::streamCopy($data, $target); fclose($target); fclose($data); if ($this->fakeRoot == Filesystem::getRoot()) { @@ -303,7 +303,7 @@ class View { ); } \OC_FileProxy::runPostProxies('file_put_contents', $absolutePath, $count); - return $count > 0; + return $result; } else { return false; } @@ -361,7 +361,7 @@ class View { } else { $source = $this->fopen($path1 . $postFix1, 'r'); $target = $this->fopen($path2 . $postFix2, 'w'); - $result = \OC_Helper::streamCopy($source, $target); + list($count, $result) = \OC_Helper::streamCopy($source, $target); list($storage1, $internalPath1) = Filesystem::resolvePath($absolutePath1 . $postFix1); $storage1->unlink($internalPath1); } @@ -443,7 +443,7 @@ class View { } else { $source = $this->fopen($path1 . $postFix1, 'r'); $target = $this->fopen($path2 . $postFix2, 'w'); - $result = \OC_Helper::streamCopy($source, $target); + list($count, $result) = \OC_Helper::streamCopy($source, $target); } if ($this->fakeRoot == Filesystem::getRoot()) { \OC_Hook::emit( diff --git a/lib/helper.php b/lib/helper.php index 2c9cd36b199..7420a79eb2d 100644 --- a/lib/helper.php +++ b/lib/helper.php @@ -513,13 +513,16 @@ class OC_Helper { if(!$source or !$target) { return false; } - $result=true; + $result = true; + $count = 0; while(!feof($source)) { - if (fwrite($target, fread($source, 8192)) === false) { + if ($c = fwrite($target, fread($source, 8192)) === false) { $result = false; + } else { + $count += $c; } } - return $result; + return array($count, $result); } /** diff --git a/lib/public/files.php b/lib/public/files.php index c2945b200e8..700bf574537 100644 --- a/lib/public/files.php +++ b/lib/public/files.php @@ -62,7 +62,8 @@ class Files { * @return int the number of bytes copied */ public static function streamCopy( $source, $target ) { - return(\OC_Helper::streamCopy( $source, $target )); + list($count, $result) = \OC_Helper::streamCopy( $source, $target ); + return $count; } /** -- cgit v1.2.3 From bb75dfc021a68bcd9526ef40f78bca4910798345 Mon Sep 17 00:00:00 2001 From: Bart Visscher Date: Fri, 22 Feb 2013 17:21:57 +0100 Subject: Whitespace fixes --- apps/files/js/filelist.js | 14 +- apps/files/js/files.js | 20 +- apps/files_external/lib/config.php | 16 +- apps/files_external/lib/sftp.php | 14 +- apps/files_sharing/public.php | 3 +- apps/files_trashbin/ajax/delete.php | 2 +- apps/files_trashbin/ajax/undelete.php | 4 +- apps/files_trashbin/appinfo/app.php | 6 +- apps/files_trashbin/index.php | 28 +-- apps/files_trashbin/js/disableDefaultActions.js | 6 +- apps/files_trashbin/js/trash.js | 24 +- apps/files_trashbin/lib/hooks.php | 40 +-- apps/files_trashbin/lib/trash.php | 322 ++++++++++++------------ apps/files_trashbin/templates/part.list.php | 1 - apps/files_versions/ajax/rollbackVersion.php | 1 - apps/files_versions/js/versions.js | 4 +- apps/files_versions/lib/hooks.php | 6 +- apps/files_versions/lib/versions.php | 84 +++---- apps/user_ldap/lib/helper.php | 1 - apps/user_webdavauth/settings.php | 2 +- lib/connector/sabre/directory.php | 12 +- lib/connector/sabre/file.php | 8 +- lib/files/cache/legacy.php | 6 +- lib/files/filesystem.php | 2 +- lib/files/storage/common.php | 4 +- lib/group.php | 50 ++-- lib/group/backend.php | 34 +-- lib/group/database.php | 32 +-- lib/hook.php | 16 +- lib/image.php | 2 +- lib/public/share.php | 6 +- lib/public/user.php | 34 +-- lib/request.php | 2 +- lib/search.php | 4 +- lib/setup.php | 10 +- lib/user.php | 2 +- lib/user/backend.php | 4 +- lib/user/database.php | 12 +- settings/ajax/changedisplayname.php | 62 ++--- settings/routes.php | 2 +- 40 files changed, 449 insertions(+), 453 deletions(-) (limited to 'lib/files') diff --git a/apps/files/js/filelist.js b/apps/files/js/filelist.js index 0bf1f79ab77..ea721059c3f 100644 --- a/apps/files/js/filelist.js +++ b/apps/files/js/filelist.js @@ -35,7 +35,7 @@ var FileList={ if(extension){ name_span.append($('').addClass('extension').text(extension)); } - //dirs can show the number of uploaded files + //dirs can show the number of uploaded files if (type == 'dir') { link_elem.append($('').attr({ 'class': 'uploadtext', @@ -44,7 +44,7 @@ var FileList={ } td.append(link_elem); tr.append(td); - + //size column if(size!=t('files', 'Pending')){ simpleSize=simpleFileSize(size); @@ -59,7 +59,7 @@ var FileList={ "style": 'color:rgb('+sizeColor+','+sizeColor+','+sizeColor+')' }).text(simpleSize); tr.append(td); - + // date column var modifiedColor = Math.round((Math.round((new Date()).getTime() / 1000)-lastModifiedTime)/60/60/24*5); td = $('').attr({ "class": "date" }); @@ -87,7 +87,7 @@ var FileList={ lastModified, $('#permissions').val() ); - + FileList.insertElement(name, 'file', tr.attr('data-file',name)); var row = $('tr').filterAttr('data-file',name); if(loading){ @@ -101,7 +101,7 @@ var FileList={ FileActions.display(row.find('td.filename')); }, addDir:function(name,size,lastModified,hidden){ - + var tr = this.createRow( 'dir', name, @@ -111,7 +111,7 @@ var FileList={ lastModified, $('#permissions').val() ); - + FileList.insertElement(name,'dir',tr); var row = $('tr').filterAttr('data-file',name); row.find('td.filename').draggable(dragOptions); @@ -344,7 +344,7 @@ var FileList={ var deleteAction = $('tr').filterAttr('data-file',file).children("td.date").children(".move2trash"); deleteAction[0].outerHTML = oldHTML; }); - } + } }); } }; diff --git a/apps/files/js/files.js b/apps/files/js/files.js index 8327460cca6..6801fb59910 100644 --- a/apps/files/js/files.js +++ b/apps/files/js/files.js @@ -114,7 +114,7 @@ $(document).ready(function() { $(this).parent().children('#file_upload_start').trigger('click'); return false; }); - + // Show trash bin $('#trash a').live('click', function() { window.location=OC.filePath('files_trashbin', '', 'index.php'); @@ -817,26 +817,26 @@ var createDragShadow = function(event){ //select dragged file $(event.target).parents('tr').find('td input:first').prop('checked',true); } - + var selectedFiles = getSelectedFiles(); - + if (!isDragSelected && selectedFiles.length == 1) { //revert the selection $(event.target).parents('tr').find('td input:first').prop('checked',false); } - + //also update class when we dragged more than one file if (selectedFiles.length > 1) { $(event.target).parents('tr').addClass('selected'); } - + // build dragshadow var dragshadow = $('
'); var tbody = $(''); dragshadow.append(tbody); - + var dir=$('#dir').val(); - + $(selectedFiles).each(function(i,elem){ var newtr = $('' +''+elem.name+''+humanFileSize(elem.size)+'' @@ -850,7 +850,7 @@ var createDragShadow = function(event){ }); } }); - + return dragshadow; } @@ -870,9 +870,9 @@ var folderDropOptions={ if ($(event.target).parents('tr').find('td input:first').prop('checked') === true) { return false; } - + var target=$.trim($(this).find('.nametext').text()); - + var files = ui.helper.find('tr'); $(files).each(function(i,row){ var dir = $(row).data('dir'); diff --git a/apps/files_external/lib/config.php b/apps/files_external/lib/config.php index d31c2f35a68..905c5d50cde 100755 --- a/apps/files_external/lib/config.php +++ b/apps/files_external/lib/config.php @@ -38,7 +38,7 @@ class OC_Mount_Config { * @return array */ public static function getBackends() { - + $backends['\OC\Files\Storage\Local']=array( 'backend' => 'Local', 'configuration' => array( @@ -77,7 +77,7 @@ class OC_Mount_Config { 'token' => '#token', 'token_secret' => '#token secret'), 'custom' => 'google'); - + $backends['\OC\Files\Storage\SWIFT']=array( 'backend' => 'OpenStack Swift', 'configuration' => array( @@ -86,7 +86,7 @@ class OC_Mount_Config { 'token' => '*Token', 'root' => '&Root', 'secure' => '!Secure ftps://')); - + if(OC_Mount_Config::checksmbclient()) $backends['\OC\Files\Storage\SMB']=array( 'backend' => 'SMB / CIFS', 'configuration' => array( @@ -95,7 +95,7 @@ class OC_Mount_Config { 'password' => '*Password', 'share' => 'Share', 'root' => '&Root')); - + $backends['\OC\Files\Storage\DAV']=array( 'backend' => 'ownCloud / WebDAV', 'configuration' => array( @@ -104,13 +104,13 @@ class OC_Mount_Config { 'password' => '*Password', 'root' => '&Root', 'secure' => '!Secure https://')); - + $backends['\OC\Files\Storage\SFTP']=array( 'backend' => 'SFTP', 'configuration' => array( 'host' => 'URL', - 'user' => 'Username', - 'password' => '*Password', + 'user' => 'Username', + 'password' => '*Password', 'root' => '&Root')); return($backends); @@ -378,7 +378,7 @@ class OC_Mount_Config { } /** - * check if php-ftp is installed + * check if php-ftp is installed */ public static function checkphpftp() { if(function_exists('ftp_login')) { diff --git a/apps/files_external/lib/sftp.php b/apps/files_external/lib/sftp.php index 785eb7dfc42..ede6c251fd9 100644 --- a/apps/files_external/lib/sftp.php +++ b/apps/files_external/lib/sftp.php @@ -32,7 +32,7 @@ class SFTP extends \OC\Files\Storage\Common { $this->root = isset($params['root']) ? $this->cleanPath($params['root']) : '/'; if ($this->root[0] != '/') $this->root = '/' . $this->root; if (substr($this->root, -1, 1) != '/') $this->root .= '/'; - + $host_keys = $this->read_host_keys(); $this->client = new \Net_SFTP($this->host); @@ -50,18 +50,18 @@ class SFTP extends \OC\Files\Storage\Common { $host_keys[$this->host] = $current_host_key; $this->write_host_keys($host_keys); } - + if(!$this->file_exists('')){ $this->mkdir(''); } } - + public function test() { if (!isset($params['host']) || !isset($params['user']) || !isset($params['password'])) { throw new \Exception("Required parameters not set"); - } + } } - + public function getId(){ return 'sftp::' . $this->user . '@' . $this->host . '/' . $this->root; } @@ -109,7 +109,7 @@ class SFTP extends \OC\Files\Storage\Common { $host_key_arr = explode("::", $line, 2); if (count($host_key_arr) == 2) { $hosts[] = $host_key_arr[0]; - $keys[] = $host_key_arr[1]; + $keys[] = $host_key_arr[1]; } } return array_combine($hosts, $keys); @@ -203,7 +203,7 @@ class SFTP extends \OC\Files\Storage\Common { $tmp = \OC_Helper::tmpFile($ext); $this->getFile($abs_path, $tmp); return fopen($tmp, $mode); - + case 'w': case 'wb': case 'a': diff --git a/apps/files_sharing/public.php b/apps/files_sharing/public.php index f265a7dd014..243ee668f1f 100644 --- a/apps/files_sharing/public.php +++ b/apps/files_sharing/public.php @@ -43,7 +43,7 @@ if (isset($_GET['t'])) { $path = \OC\Files\Filesystem::getPath($linkItem['file_source']); } } -} +} if (isset($path)) { if (!isset($linkItem['item_type'])) { OCP\Util::writeLog('share', 'No item type set for share id: ' . $linkItem['id'], \OCP\Util::ERROR); @@ -212,4 +212,3 @@ if (isset($path)) { header('HTTP/1.0 404 Not Found'); $tmpl = new OCP\Template('', '404', 'guest'); $tmpl->printPage(); - diff --git a/apps/files_trashbin/ajax/delete.php b/apps/files_trashbin/ajax/delete.php index 34f35c39ccb..1834fb54003 100644 --- a/apps/files_trashbin/ajax/delete.php +++ b/apps/files_trashbin/ajax/delete.php @@ -20,7 +20,7 @@ foreach ($list as $file) { $filename = $file; $timestamp = null; } - + OCA\Files_Trashbin\Trashbin::delete($filename, $timestamp); if (!OCA\Files_Trashbin\Trashbin::file_exists($filename, $timestamp)) { $success[$i]['filename'] = $file; diff --git a/apps/files_trashbin/ajax/undelete.php b/apps/files_trashbin/ajax/undelete.php index 93f2aaf1fa2..80de3c31f91 100644 --- a/apps/files_trashbin/ajax/undelete.php +++ b/apps/files_trashbin/ajax/undelete.php @@ -1,4 +1,4 @@ -getAbsolutePath($dir); $dirContent = opendir($fullpath); $i = 0; @@ -36,10 +36,10 @@ if ($dir) { 'type' => $view->is_dir($dir.'/'.$entryName) ? 'dir' : 'file', 'location' => $dir, ); - } + } } closedir($dirContent); - + } else { $dirlisting = false; $query = \OC_DB::prepare('SELECT id,location,timestamp,type,mime FROM *PREFIX*files_trash WHERE user=?'); @@ -67,28 +67,28 @@ foreach ($result as $r) { $files[] = $i; } -// Make breadcrumb +// Make breadcrumb $pathtohere = ''; -$breadcrumb = array(); -foreach (explode('/', $dir) as $i) { +$breadcrumb = array(); +foreach (explode('/', $dir) as $i) { if ($i != '') { if ( preg_match('/^(.+)\.d[0-9]+$/', $i, $match) ) { $name = $match[1]; } else { $name = $i; - } - $pathtohere .= '/' . $i; - $breadcrumb[] = array('dir' => $pathtohere, 'name' => $name); - } + } + $pathtohere .= '/' . $i; + $breadcrumb[] = array('dir' => $pathtohere, 'name' => $name); + } } -$breadcrumbNav = new OCP\Template('files', 'part.breadcrumb', ''); -$breadcrumbNav->assign('breadcrumb', $breadcrumb, false); +$breadcrumbNav = new OCP\Template('files', 'part.breadcrumb', ''); +$breadcrumbNav->assign('breadcrumb', $breadcrumb, false); $breadcrumbNav->assign('baseURL', OCP\Util::linkTo('files_trashbin', 'index.php') . '?dir=', false); $list = new OCP\Template('files_trashbin', 'part.list', ''); $list->assign('files', $files, false); -$list->assign('baseURL', OCP\Util::linkTo('files_trashbin', 'index.php'). '?dir='.$dir, false); +$list->assign('baseURL', OCP\Util::linkTo('files_trashbin', 'index.php'). '?dir='.$dir, false); $list->assign('downloadURL', OCP\Util::linkTo('files_trashbin', 'download.php') . '?file='.$dir, false); $list->assign('disableSharing', true); $list->assign('dirlisting', $dirlisting); diff --git a/apps/files_trashbin/js/disableDefaultActions.js b/apps/files_trashbin/js/disableDefaultActions.js index 27c3e13db4d..df08bfb1a50 100644 --- a/apps/files_trashbin/js/disableDefaultActions.js +++ b/apps/files_trashbin/js/disableDefaultActions.js @@ -1,4 +1,4 @@ -/* disable download and sharing actions */ -var disableDownloadActions = true; -var disableSharing = true; +/* disable download and sharing actions */ +var disableDownloadActions = true; +var disableSharing = true; var trashBinApp = true; \ No newline at end of file diff --git a/apps/files_trashbin/js/trash.js b/apps/files_trashbin/js/trash.js index 208cc88f0fd..7769def535e 100644 --- a/apps/files_trashbin/js/trash.js +++ b/apps/files_trashbin/js/trash.js @@ -19,22 +19,22 @@ $(document).ready(function() { OC.dialogs.alert(result.data.message, 'Error'); } }); - + }); }; - + FileActions.register('all', 'Delete', OC.PERMISSION_READ, function () { return OC.imagePath('core', 'actions/delete'); }, function (filename) { $('.tipsy').remove(); - + var tr=$('tr').filterAttr('data-file', filename); var deleteAction = $('tr').filterAttr('data-file',filename).children("td.date").children(".action.delete"); var oldHTML = deleteAction[0].outerHTML; var newHTML = ''; var files = tr.attr('data-file'); deleteAction[0].outerHTML = newHTML; - + $.post(OC.filePath('files_trashbin','ajax','delete.php'), {files:JSON.stringify([files]), dirlisting:tr.attr('data-dirlisting') }, function(result){ @@ -46,9 +46,9 @@ $(document).ready(function() { OC.dialogs.alert(result.data.message, 'Error'); } }); - + }); - + // Sets the select_all checkbox behaviour : $('#select_all').click(function() { if($(this).attr('checked')){ @@ -91,18 +91,18 @@ $(document).ready(function() { } processSelection(); }); - + $('.undelete').click('click',function(event) { var spinner = ''; var files=getSelectedFiles('file'); var fileslist = JSON.stringify(files); var dirlisting=getSelectedFiles('dirlisting')[0]; - + for (var i=0; i'; var files=getSelectedFiles('file'); var fileslist = JSON.stringify(files); var dirlisting=getSelectedFiles('dirlisting')[0]; - + for (var i=0; i. - * +/** + * ownCloud - trash bin + * + * @author Bjoern Schiessle + * @copyright 2013 Bjoern Schiessle schiessle@owncloud.com + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE + * License as published by the Free Software Foundation; either + * version 3 of the License, or any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU AFFERO GENERAL PUBLIC LICENSE for more details. + * + * You should have received a copy of the GNU Affero General Public + * License along with this library. If not, see . + * */ /** @@ -36,7 +36,7 @@ class Hooks { * to copy the file to the trash bin */ public static function remove_hook($params) { - + if ( \OCP\App::isEnabled('files_trashbin') ) { $path = $params['path']; Trashbin::move2trash($path); diff --git a/apps/files_trashbin/lib/trash.php b/apps/files_trashbin/lib/trash.php index 2b8b32c3a16..8355c7252b0 100644 --- a/apps/files_trashbin/lib/trash.php +++ b/apps/files_trashbin/lib/trash.php @@ -1,67 +1,67 @@ . - * - */ - -namespace OCA\Files_Trashbin; - +/** + * ownCloud - trash bin + * + * @author Bjoern Schiessle + * @copyright 2013 Bjoern Schiessle schiessle@owncloud.com + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE + * License as published by the Free Software Foundation; either + * version 3 of the License, or any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU AFFERO GENERAL PUBLIC LICENSE for more details. + * + * You should have received a copy of the GNU Affero General Public + * License along with this library. If not, see . + * + */ + +namespace OCA\Files_Trashbin; + class Trashbin { // how long do we keep files in the trash bin if no other value is defined in the config file (unit: days) const DEFAULT_RETENTION_OBLIGATION=180; // unit: percentage; 50% of available disk space/quota const DEFAULTMAXSIZE=50; - + /** * move file to the trash bin - * + * * @param $file_path path to the deleted file/directory relative to the files root directory */ public static function move2trash($file_path) { $user = \OCP\User::getUser(); - $view = new \OC_FilesystemView('/'. $user); - if (!$view->is_dir('files_trashbin')) { - $view->mkdir('files_trashbin'); - $view->mkdir("versions_trashbin"); - } - - $path_parts = pathinfo($file_path); - - $deleted = $path_parts['basename']; - $location = $path_parts['dirname']; - $timestamp = time(); - $mime = $view->getMimeType('files'.$file_path); - - if ( $view->is_dir('files'.$file_path) ) { - $type = 'dir'; - } else { - $type = 'file'; + $view = new \OC_FilesystemView('/'. $user); + if (!$view->is_dir('files_trashbin')) { + $view->mkdir('files_trashbin'); + $view->mkdir("versions_trashbin"); } - - if ( ($trashbinSize = \OCP\Config::getAppValue('files_trashbin', 'size')) === null ) { + + $path_parts = pathinfo($file_path); + + $deleted = $path_parts['basename']; + $location = $path_parts['dirname']; + $timestamp = time(); + $mime = $view->getMimeType('files'.$file_path); + + if ( $view->is_dir('files'.$file_path) ) { + $type = 'dir'; + } else { + $type = 'file'; + } + + if ( ($trashbinSize = \OCP\Config::getAppValue('files_trashbin', 'size')) === null ) { $trashbinSize = self::calculateSize(new \OC_FilesystemView('/'. $user.'/files_trashbin')); - $trashbinSize += self::calculateSize(new \OC_FilesystemView('/'. $user.'/versions_trashbin')); + $trashbinSize += self::calculateSize(new \OC_FilesystemView('/'. $user.'/versions_trashbin')); } $trashbinSize += self::copy_recursive($file_path, 'files_trashbin/'.$deleted.'.d'.$timestamp, $view); - if ( $view->file_exists('files_trashbin/'.$deleted.'.d'.$timestamp) ) { + if ( $view->file_exists('files_trashbin/'.$deleted.'.d'.$timestamp) ) { $query = \OC_DB::prepare("INSERT INTO *PREFIX*files_trash (id,timestamp,location,type,mime,user)" ." VALUES (?,?,?,?,?,?)"); $result = $query->execute(array($deleted, $timestamp, $location, $type, $mime, $user)); @@ -69,49 +69,49 @@ class Trashbin { $view->deleteAll('files_trashbin/'.$deleted.'.d'.$timestamp); \OC_Log::write('files_trashbin', 'trash bin database couldn\'t be updated', \OC_log::ERROR); return; - } - - if ( \OCP\App::isEnabled('files_versions') ) { + } + + if ( \OCP\App::isEnabled('files_versions') ) { if ( $view->is_dir('files_versions'.$file_path) ) { $trashbinSize += self::calculateSize( new \OC_FilesystemView('/'. $user.'/files_versions/'.$file_path) ); - $view->rename('files_versions'.$file_path, 'versions_trashbin/'. $deleted.'.d'.$timestamp); - } else if ( $versions = \OCA\Files_Versions\Storage::getVersions($file_path) ) { + $view->rename('files_versions'.$file_path, 'versions_trashbin/'. $deleted.'.d'.$timestamp); + } else if ( $versions = \OCA\Files_Versions\Storage::getVersions($file_path) ) { foreach ($versions as $v) { - $trashbinSize += $view->filesize('files_versions'.$v['path'].'.v'.$v['version']); + $trashbinSize += $view->filesize('files_versions'.$v['path'].'.v'.$v['version']); $view->rename('files_versions'.$v['path'].'.v'.$v['version'], 'versions_trashbin/'. $deleted.'.v'.$v['version'].'.d'.$timestamp); - } - } + } + } } } else { \OC_Log::write('files_trashbin', 'Couldn\'t move '.$file_path.' to the trash bin', \OC_log::ERROR); } - - // get available disk space for user - $quota = \OCP\Util::computerFileSize(\OC_Preferences::getValue($user, 'files', 'quota')); - if ( $quota == null ) { - $quota = \OCP\Util::computerFileSize(\OC_Appconfig::getValue('files', 'default_quota')); - } - if ( $quota == null ) { - $quota = \OC\Files\Filesystem::free_space('/'); + + // get available disk space for user + $quota = \OCP\Util::computerFileSize(\OC_Preferences::getValue($user, 'files', 'quota')); + if ( $quota == null ) { + $quota = \OCP\Util::computerFileSize(\OC_Appconfig::getValue('files', 'default_quota')); + } + if ( $quota == null ) { + $quota = \OC\Files\Filesystem::free_space('/'); } - - // calculate available space for trash bin - $rootInfo = $view->getFileInfo('/files'); - $free = $quota-$rootInfo['size']; // remaining free space for user - if ( $free > 0 ) { - $availableSpace = ($free * self::DEFAULTMAXSIZE / 100) - $trashbinSize; // how much space can be used for versions - } else { - $availableSpace = $free-$trashbinSize; + + // calculate available space for trash bin + $rootInfo = $view->getFileInfo('/files'); + $free = $quota-$rootInfo['size']; // remaining free space for user + if ( $free > 0 ) { + $availableSpace = ($free * self::DEFAULTMAXSIZE / 100) - $trashbinSize; // how much space can be used for versions + } else { + $availableSpace = $free-$trashbinSize; } - + $trashbinSize -= self::expire($availableSpace); - \OCP\Config::setAppValue('files_trashbin', 'size', $trashbinSize); + \OCP\Config::setAppValue('files_trashbin', 'size', $trashbinSize); } - - + + /** * restore files from trash bin * @param $file path to the deleted file @@ -121,10 +121,10 @@ class Trashbin { public static function restore($file, $filename, $timestamp) { $user = \OCP\User::getUser(); $view = new \OC_FilesystemView('/'.$user); - - if ( ($trashbinSize = \OCP\Config::getAppValue('files_trashbin', 'size')) === null ) { - $trashbinSize = self::calculateSize(new \OC_FilesystemView('/'. $user.'/files_trashbin')); - $trashbinSize += self::calculateSize(new \OC_FilesystemView('/'. $user.'/versions_trashbin')); + + if ( ($trashbinSize = \OCP\Config::getAppValue('files_trashbin', 'size')) === null ) { + $trashbinSize = self::calculateSize(new \OC_FilesystemView('/'. $user.'/files_trashbin')); + $trashbinSize += self::calculateSize(new \OC_FilesystemView('/'. $user.'/versions_trashbin')); } if ( $timestamp ) { $query = \OC_DB::prepare('SELECT location,type FROM *PREFIX*files_trash' @@ -134,13 +134,13 @@ class Trashbin { \OC_Log::write('files_trashbin', 'trash bin database inconsistent!', \OC_Log::ERROR); return false; } - - // if location no longer exists, restore file in the root directory - $location = $result[0]['location']; - if ( $result[0]['location'] != '/' && + + // if location no longer exists, restore file in the root directory + $location = $result[0]['location']; + if ( $result[0]['location'] != '/' && (!$view->is_dir('files'.$result[0]['location']) || - !$view->isUpdatable('files'.$result[0]['location'])) ) { - $location = ''; + !$view->isUpdatable('files'.$result[0]['location'])) ) { + $location = ''; } } else { $path_parts = pathinfo($filename); @@ -150,10 +150,10 @@ class Trashbin { ); $location = ''; } - + $source = \OC_Filesystem::normalizePath('files_trashbin/'.$file); $target = \OC_Filesystem::normalizePath('files/'.$location.'/'.$filename); - + // we need a extension in case a file/dir with the same name already exists $ext = self::getUniqueExtension($location, $filename, $view); $mtime = $view->filemtime($source); @@ -170,14 +170,14 @@ class Trashbin { $versionedFile = $filename; } else { $versionedFile = $file; - } + } if ( $result[0]['type'] == 'dir' ) { $trashbinSize -= self::calculateSize( new \OC_FilesystemView('/'.$user.'/'.'versions_trashbin/'. $file) ); $view->rename(\OC_Filesystem::normalizePath('versions_trashbin/'. $file), \OC_Filesystem::normalizePath('files_versions/'.$location.'/'.$filename.$ext)); - } else if ( $versions = self::getVersionsFromTrash($versionedFile, $timestamp) ) { + } else if ( $versions = self::getVersionsFromTrash($versionedFile, $timestamp) ) { foreach ($versions as $v) { if ($timestamp ) { $trashbinSize -= $view->filesize('versions_trashbin/'.$versionedFile.'.v'.$v.'.d'.$timestamp); @@ -187,13 +187,13 @@ class Trashbin { $trashbinSize -= $view->filesize('versions_trashbin/'.$versionedFile.'.v'.$v); $view->rename('versions_trashbin/'.$versionedFile.'.v'.$v, 'files_versions/'.$location.'/'.$filename.$ext.'.v'.$v); - } - } - } + } + } + } } if ( $timestamp ) { - $query = \OC_DB::prepare('DELETE FROM *PREFIX*files_trash WHERE user=? AND id=? AND timestamp=?'); + $query = \OC_DB::prepare('DELETE FROM *PREFIX*files_trash WHERE user=? AND id=? AND timestamp=?'); $query->execute(array($user,$filename,$timestamp)); } @@ -205,31 +205,31 @@ class Trashbin { return false; } - - /** - * delete file from trash bin permanently + + /** + * delete file from trash bin permanently * @param $filename path to the file - * @param $timestamp of deletion time - * @return size of deleted files - */ - public static function delete($filename, $timestamp=null) { - $user = \OCP\User::getUser(); + * @param $timestamp of deletion time + * @return size of deleted files + */ + public static function delete($filename, $timestamp=null) { + $user = \OCP\User::getUser(); $view = new \OC_FilesystemView('/'.$user); - $size = 0; - - if ( ($trashbinSize = \OCP\Config::getAppValue('files_trashbin', 'size')) === null ) { - $trashbinSize = self::calculateSize(new \OC_FilesystemView('/'. $user.'/files_trashbin')); - $trashbinSize += self::calculateSize(new \OC_FilesystemView('/'. $user.'/versions_trashbin')); + $size = 0; + + if ( ($trashbinSize = \OCP\Config::getAppValue('files_trashbin', 'size')) === null ) { + $trashbinSize = self::calculateSize(new \OC_FilesystemView('/'. $user.'/files_trashbin')); + $trashbinSize += self::calculateSize(new \OC_FilesystemView('/'. $user.'/versions_trashbin')); } - - if ( $timestamp ) { - $query = \OC_DB::prepare('DELETE FROM *PREFIX*files_trash WHERE user=? AND id=? AND timestamp=?'); - $query->execute(array($user,$filename,$timestamp)); + + if ( $timestamp ) { + $query = \OC_DB::prepare('DELETE FROM *PREFIX*files_trash WHERE user=? AND id=? AND timestamp=?'); + $query->execute(array($user,$filename,$timestamp)); $file = $filename.'.d'.$timestamp; } else { $file = $filename; } - + if ( \OCP\App::isEnabled('files_versions') ) { if ($view->is_dir('versions_trashbin/'.$file)) { $size += self::calculateSize(new \OC_Filesystemview('/'.$user.'/versions_trashbin/'.$file)); @@ -245,8 +245,8 @@ class Trashbin { } } } - } - + } + if ($view->is_dir('/files_trashbin/'.$file)) { $size += self::calculateSize(new \OC_Filesystemview('/'.$user.'/files_trashbin/'.$file)); } else { @@ -255,8 +255,8 @@ class Trashbin { $view->unlink('/files_trashbin/'.$file); $trashbinSize -= $size; \OCP\Config::setAppValue('files_trashbin', 'size', $trashbinSize); - - return $size; + + return $size; } /** @@ -279,22 +279,22 @@ class Trashbin { return $view->file_exists($target); } - /** + /** * clean up the trash bin - * @param max. available disk space for trashbin - */ + * @param max. available disk space for trashbin + */ private static function expire($availableSpace) { - + $user = \OCP\User::getUser(); $view = new \OC_FilesystemView('/'.$user); $size = 0; - - $query = \OC_DB::prepare('SELECT location,type,id,timestamp FROM *PREFIX*files_trash WHERE user=?'); + + $query = \OC_DB::prepare('SELECT location,type,id,timestamp FROM *PREFIX*files_trash WHERE user=?'); $result = $query->execute(array($user))->fetchAll(); - + $retention_obligation = \OC_Config::getValue('trashbin_retention_obligation', self::DEFAULT_RETENTION_OBLIGATION); - + $limit = time() - ($retention_obligation * 86400); foreach ( $result as $r ) { @@ -318,14 +318,14 @@ class Trashbin { foreach ($versions as $v) { $size += $view->filesize('versions_trashbin/'.$filename.'.v'.$v.'.d'.$timestamp); $view->unlink('versions_trashbin/'.$filename.'.v'.$v.'.d'.$timestamp); - } + } } } } - - $query = \OC_DB::prepare('DELETE FROM *PREFIX*files_trash WHERE user=? AND timestampexecute(array($user,$limit)); - + $availableSpace = $availableSpace + $size; // if size limit for trash bin reached, delete oldest files in trash bin if ($availableSpace < 0) { @@ -340,15 +340,15 @@ class Trashbin { $size += $tmp; $i++; } - + } - - return $size; + + return $size; } - + /** * recursive copy to copy a whole directory - * + * * @param $source source path, relative to the users files directory * @param $destination destination path relative to the users root directoy * @param $view file view for the users root directory @@ -375,7 +375,7 @@ class Trashbin { } return $size; } - + /** * find all versions which belong to the file we want to restore * @param $filename name of the file which should be restored @@ -383,7 +383,7 @@ class Trashbin { */ private static function getVersionsFromTrash($filename, $timestamp) { $view = new \OC_FilesystemView('/'.\OCP\User::getUser().'/versions_trashbin'); - $versionsName = \OCP\Config::getSystemValue('datadirectory').$view->getAbsolutePath($filename); + $versionsName = \OCP\Config::getSystemValue('datadirectory').$view->getAbsolutePath($filename); $versions = array(); if ($timestamp ) { // fetch for old versions @@ -391,20 +391,20 @@ class Trashbin { $offset = -strlen($timestamp)-2; } else { $matches = glob( $versionsName.'.v*' ); - } - + } + foreach( $matches as $ma ) { if ( $timestamp ) { - $parts = explode( '.v', substr($ma, 0, $offset) ); + $parts = explode( '.v', substr($ma, 0, $offset) ); $versions[] = ( end( $parts ) ); } else { - $parts = explode( '.v', $ma ); + $parts = explode( '.v', $ma ); $versions[] = ( end( $parts ) ); } } return $versions; } - + /** * find unique extension for restored file if a file with the same name already exists * @param $location where the file should be restored @@ -413,40 +413,40 @@ class Trashbin { * @return string with unique extension */ private static function getUniqueExtension($location, $filename, $view) { - $ext = ''; - if ( $view->file_exists('files'.$location.'/'.$filename) ) { - $tmpext = '.restored'; - $ext = $tmpext; - $i = 1; - while ( $view->file_exists('files'.$location.'/'.$filename.$ext) ) { - $ext = $tmpext.$i; - $i++; - } + $ext = ''; + if ( $view->file_exists('files'.$location.'/'.$filename) ) { + $tmpext = '.restored'; + $ext = $tmpext; + $i = 1; + while ( $view->file_exists('files'.$location.'/'.$filename.$ext) ) { + $ext = $tmpext.$i; + $i++; + } } return $ext; } - /** + /** * @brief get the size from a given root folder - * @param $view file view on the root folder - * @return size of the folder - */ - private static function calculateSize($view) { - $root = \OCP\Config::getSystemValue('datadirectory').$view->getAbsolutePath(''); + * @param $view file view on the root folder + * @return size of the folder + */ + private static function calculateSize($view) { + $root = \OCP\Config::getSystemValue('datadirectory').$view->getAbsolutePath(''); if (!file_exists($root)) { return 0; } $iterator = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($root), - \RecursiveIteratorIterator::CHILD_FIRST); - $size = 0; - + \RecursiveIteratorIterator::CHILD_FIRST); + $size = 0; + foreach ($iterator as $path) { $relpath = substr($path, strlen($root)-1); if ( !$view->is_dir($relpath) ) { $size += $view->filesize($relpath); - } - } - return $size; + } + } + return $size; } - -} + +} diff --git a/apps/files_trashbin/templates/part.list.php b/apps/files_trashbin/templates/part.list.php index 2de0d7ee91a..dea0a43cd4c 100644 --- a/apps/files_trashbin/templates/part.list.php +++ b/apps/files_trashbin/templates/part.list.php @@ -69,4 +69,3 @@ array( "message" => $l->t("Could not revert: %s", array($file) )))); } - diff --git a/apps/files_versions/js/versions.js b/apps/files_versions/js/versions.js index dec222eefce..109829fa03f 100644 --- a/apps/files_versions/js/versions.js +++ b/apps/files_versions/js/versions.js @@ -64,9 +64,9 @@ function createVersionsDropdown(filename, files) { } else { $(html).appendTo($('thead .share')); } - + $("#makelink").click(function() { - goToVersionPage(historyUrl); + goToVersionPage(historyUrl); }); $.ajax({ diff --git a/apps/files_versions/lib/hooks.php b/apps/files_versions/lib/hooks.php index 6c87eba423d..7891b20e92f 100644 --- a/apps/files_versions/lib/hooks.php +++ b/apps/files_versions/lib/hooks.php @@ -41,7 +41,7 @@ class Hooks { if($path<>'') { Storage::delete($path); } - + } } @@ -59,8 +59,8 @@ class Hooks { if($oldpath<>'' && $newpath<>'') { Storage::rename( $oldpath, $newpath ); } - + } } - + } diff --git a/apps/files_versions/lib/versions.php b/apps/files_versions/lib/versions.php index 8a67de04d83..adbf2c1df7e 100644 --- a/apps/files_versions/lib/versions.php +++ b/apps/files_versions/lib/versions.php @@ -19,7 +19,7 @@ class Storage { const DEFAULTENABLED=true; const DEFAULTMAXSIZE=50; // unit: percentage; 50% of available disk space/quota - + private static $max_versions_per_interval = array( //first 10sec, one version every 2sec 1 => array('intervalEndsAfter' => 10, 'step' => 2), @@ -45,14 +45,14 @@ class Storage { } return array($uid, $filename); } - + /** * store a new version of a file. */ public static function store($filename) { if(\OCP\Config::getSystemValue('files_versions', Storage::DEFAULTENABLED)=='true') { list($uid, $filename) = self::getUidAndFilename($filename); - + $files_view = new \OC\Files\View('/'.$uid .'/files'); $users_view = new \OC\Files\View('/'.$uid); @@ -79,10 +79,10 @@ class Storage { $versionsSize = self::calculateSize($uid); } $versionsSize += $users_view->filesize('files'.$filename); - + // expire old revisions if necessary $newSize = self::expire($filename, $versionsSize); - + if ( $newSize != $versionsSize ) { \OCP\Config::setAppValue('files_versions', 'size', $versionsSize); } @@ -96,7 +96,7 @@ class Storage { public static function delete($filename) { list($uid, $filename) = self::getUidAndFilename($filename); $versions_fileview = new \OC\Files\View('/'.$uid .'/files_versions'); - + $abs_path = \OCP\Config::getSystemValue('datadirectory').$versions_fileview->getAbsolutePath('').$filename.'.v'; if( ($versions = self::getVersions($uid, $filename)) ) { if ( ($versionsSize = \OCP\Config::getAppValue('files_versions', 'size')) === null ) { @@ -109,7 +109,7 @@ class Storage { \OCP\Config::setAppValue('files_versions', 'size', $versionsSize); } } - + /** * rename versions of a file */ @@ -119,7 +119,7 @@ class Storage { $versions_view = new \OC\Files\View('/'.$uid .'/files_versions'); $files_view = new \OC\Files\View('/'.$uid .'/files'); $abs_newpath = \OCP\Config::getSystemValue('datadirectory').$versions_view->getAbsolutePath('').$newpath; - + if ( $files_view->is_dir($oldpath) && $versions_view->is_dir($oldpath) ) { $versions_view->rename($oldpath, $newpath); } else if ( ($versions = Storage::getVersions($uid, $oldpath)) ) { @@ -130,7 +130,7 @@ class Storage { } } } - + /** * rollback to an old version of a file. */ @@ -140,14 +140,14 @@ class Storage { list($uid, $filename) = self::getUidAndFilename($filename); $users_view = new \OC\Files\View('/'.$uid); $versionCreated = false; - + //first create a new version $version = 'files_versions'.$filename.'.v'.$users_view->filemtime('files'.$filename); if ( !$users_view->file_exists($version)) { $users_view->copy('files'.$filename, 'files_versions'.$filename.'.v'.$users_view->filemtime('files'.$filename)); $versionCreated = true; } - + // rollback if( @$users_view->copy('files_versions'.$filename.'.v'.$revision, 'files'.$filename) ) { $users_view->touch('files'.$filename, $revision); @@ -178,7 +178,7 @@ class Storage { $versions = array(); // fetch for old versions $matches = glob( $versionsName.'.v*' ); - + if ( !$matches ) { return $versions; } @@ -238,25 +238,25 @@ class Storage { if( \OCP\Config::getSystemValue('files_versions', Storage::DEFAULTENABLED)=='true' ) { $versions_fileview = new \OC\Files\View('/'.$uid.'/files_versions'); $versionsRoot = \OCP\Config::getSystemValue('datadirectory').$versions_fileview->getAbsolutePath(''); - + $iterator = new \RecursiveIteratorIterator( new \RecursiveDirectoryIterator($versionsRoot), \RecursiveIteratorIterator::CHILD_FIRST ); - + $size = 0; - + foreach ($iterator as $path) { if ( preg_match('/^.+\.v(\d+)$/', $path, $match) ) { $relpath = substr($path, strlen($versionsRoot)-1); $size += $versions_fileview->filesize($relpath); } } - + return $size; } } - + /** * @brief returns all stored file versions from a given user * @param $uid id to the user @@ -266,27 +266,27 @@ class Storage { if( \OCP\Config::getSystemValue('files_versions', Storage::DEFAULTENABLED)=='true' ) { $versions_fileview = new \OC\Files\View('/'.$uid.'/files_versions'); $versionsRoot = \OCP\Config::getSystemValue('datadirectory').$versions_fileview->getAbsolutePath(''); - + $iterator = new \RecursiveIteratorIterator( new \RecursiveDirectoryIterator($versionsRoot), \RecursiveIteratorIterator::CHILD_FIRST ); - + $versions = array(); - + foreach ($iterator as $path) { if ( preg_match('/^.+\.v(\d+)$/', $path, $match) ) { $relpath = substr($path, strlen($versionsRoot)-1); $versions[$match[1].'#'.$relpath] = array('path' => $relpath, 'timestamp' => $match[1]); } } - + ksort($versions); - + $i = 0; - + $result = array(); - + foreach( $versions as $key => $value ) { $i++; $size = $versions_fileview->filesize($value['path']); @@ -295,14 +295,14 @@ class Storage { $result['all'][$key]['version'] = $value['timestamp']; $result['all'][$key]['path'] = $filename; $result['all'][$key]['size'] = $size; - + $filename = substr($value['path'], 0, -strlen($value['timestamp'])-2); $result['by_file'][$filename][$key]['version'] = $value['timestamp']; $result['by_file'][$filename][$key]['path'] = $filename; $result['by_file'][$filename][$key]['size'] = $size; - + } - + return $result; } } @@ -312,9 +312,9 @@ class Storage { */ private static function expire($filename, $versionsSize = null) { if(\OCP\Config::getSystemValue('files_versions', Storage::DEFAULTENABLED)=='true') { - list($uid, $filename) = self::getUidAndFilename($filename); + list($uid, $filename) = self::getUidAndFilename($filename); $versions_fileview = new \OC\Files\View('/'.$uid.'/files_versions'); - + // get available disk space for user $quota = \OCP\Util::computerFileSize(\OC_Preferences::getValue($uid, 'files', 'quota')); if ( $quota == null ) { @@ -323,7 +323,7 @@ class Storage { if ( $quota == null ) { $quota = \OC\Files\Filesystem::free_space('/'); } - + // make sure that we have the current size of the version history if ( $versionsSize === null ) { if ( ($versionsSize = \OCP\Config::getAppValue('files_versions', 'size')) === null ) { @@ -339,9 +339,9 @@ class Storage { $availableSpace = ($free * self::DEFAULTMAXSIZE / 100) - $versionsSize; // how much space can be used for versions } else { $availableSpace = $free-$versionsSize; - } + } - // after every 1000s run reduce the number of all versions not only for the current file + // after every 1000s run reduce the number of all versions not only for the current file $random = rand(0, 1000); if ($random == 0) { $result = Storage::getAllVersions($uid); @@ -351,29 +351,29 @@ class Storage { $all_versions = Storage::getVersions($uid, $filename); $versions_by_file[$filename] = $all_versions; } - + $time = time(); - + // it is possible to expire versions from more than one file // iterate through all given files foreach ($versions_by_file as $filename => $versions) { $versions = array_reverse($versions); // newest version first - + $interval = 1; - $step = Storage::$max_versions_per_interval[$interval]['step']; + $step = Storage::$max_versions_per_interval[$interval]['step']; if (Storage::$max_versions_per_interval[$interval]['intervalEndsAfter'] == -1) { $nextInterval = -1; } else { $nextInterval = $time - Storage::$max_versions_per_interval[$interval]['intervalEndsAfter']; } - + $firstVersion = reset($versions); $firstKey = key($versions); $prevTimestamp = $firstVersion['version']; $nextVersion = $firstVersion['version'] - $step; $remaining_versions[$firstKey] = $firstVersion; unset($versions[$firstKey]); - + foreach ($versions as $key => $version) { $newInterval = true; while ( $newInterval ) { @@ -403,11 +403,11 @@ class Storage { $prevTimestamp = $version['version']; } } - + // check if enough space is available after versions are rearranged. // if not we delete the oldest versions until we meet the size limit for versions $numOfVersions = count($all_versions); - $i = 0; + $i = 0; while ($availableSpace < 0) { if ($i = $numOfVersions-2) break; // keep at least the last version $versions_fileview->unlink($all_versions[$i]['path'].'.v'.$all_versions[$i]['version']); @@ -415,10 +415,10 @@ class Storage { $availableSpace += $all_versions[$i]['size']; $i++; } - + return $versionsSize; // finally return the new size of the version history } - + return false; } } diff --git a/apps/user_ldap/lib/helper.php b/apps/user_ldap/lib/helper.php index 29ce998dae7..45c379445af 100644 --- a/apps/user_ldap/lib/helper.php +++ b/apps/user_ldap/lib/helper.php @@ -102,4 +102,3 @@ class Helper { return true; } } - diff --git a/apps/user_webdavauth/settings.php b/apps/user_webdavauth/settings.php index 7eabb0d48cc..ae9cb7e4c92 100755 --- a/apps/user_webdavauth/settings.php +++ b/apps/user_webdavauth/settings.php @@ -26,7 +26,7 @@ OC_Util::checkAdminUser(); if($_POST) { // CSRF check OCP\JSON::callCheck(); - + if(isset($_POST['webdav_url'])) { OC_CONFIG::setValue('user_webdavauth_url', strip_tags($_POST['webdav_url'])); } diff --git a/lib/connector/sabre/directory.php b/lib/connector/sabre/directory.php index a9aa891d409..953692f80a9 100644 --- a/lib/connector/sabre/directory.php +++ b/lib/connector/sabre/directory.php @@ -62,12 +62,12 @@ class OC_Connector_Sabre_Directory extends OC_Connector_Sabre_Node implements Sa } } else { $newPath = $this->path . '/' . $name; - + // mark file as partial while uploading (ignored by the scanner) $partpath = $newPath . '.part'; - + \OC\Files\Filesystem::file_put_contents($partpath, $data); - + //detect aborted upload if (isset ($_SERVER['REQUEST_METHOD']) && $_SERVER['REQUEST_METHOD'] === 'PUT' ) { if (isset($_SERVER['CONTENT_LENGTH'])) { @@ -80,10 +80,10 @@ class OC_Connector_Sabre_Directory extends OC_Connector_Sabre_Node implements Sa } } } - + // rename to correct path \OC\Files\Filesystem::rename($partpath, $newPath); - + // allow sync clients to send the mtime along in a header $mtime = OC_Request::hasModificationTime(); if ($mtime !== false) { @@ -91,7 +91,7 @@ class OC_Connector_Sabre_Directory extends OC_Connector_Sabre_Node implements Sa header('X-OC-MTime: accepted'); } } - + return OC_Connector_Sabre_Node::getETagPropertyForPath($newPath); } diff --git a/lib/connector/sabre/file.php b/lib/connector/sabre/file.php index c4c27e92251..91646312e90 100644 --- a/lib/connector/sabre/file.php +++ b/lib/connector/sabre/file.php @@ -47,9 +47,9 @@ class OC_Connector_Sabre_File extends OC_Connector_Sabre_Node implements Sabre_D // mark file as partial while uploading (ignored by the scanner) $partpath = $this->path . '.part'; - + \OC\Files\Filesystem::file_put_contents($partpath, $data); - + //detect aborted upload if (isset ($_SERVER['REQUEST_METHOD']) && $_SERVER['REQUEST_METHOD'] === 'PUT' ) { if (isset($_SERVER['CONTENT_LENGTH'])) { @@ -62,10 +62,10 @@ class OC_Connector_Sabre_File extends OC_Connector_Sabre_Node implements Sabre_D } } } - + // rename to correct path \OC\Files\Filesystem::rename($partpath, $this->path); - + //allow sync clients to send the mtime along in a header $mtime = OC_Request::hasModificationTime(); if ($mtime !== false) { diff --git a/lib/files/cache/legacy.php b/lib/files/cache/legacy.php index 6d1ffa7b40b..2b8689fcbda 100644 --- a/lib/files/cache/legacy.php +++ b/lib/files/cache/legacy.php @@ -51,12 +51,12 @@ class Legacy { $this->cacheHasItems = false; return false; } - + if ($result === false || property_exists($result, 'error_message_prefix')) { $this->cacheHasItems = false; return false; - } - + } + $this->cacheHasItems = (bool)$result->fetchRow(); return $this->cacheHasItems; } diff --git a/lib/files/filesystem.php b/lib/files/filesystem.php index 401ee8417e5..0bbd7550d74 100644 --- a/lib/files/filesystem.php +++ b/lib/files/filesystem.php @@ -221,7 +221,7 @@ class Filesystem { $root = \OC_User::getHome($user); self::mount('\OC\Files\Storage\Local', array('datadir' => $root), $user); - + // Load system mount points if (is_file(\OC::$SERVERROOT . '/config/mount.php') or is_file(\OC::$SERVERROOT . '/config/mount.json')) { if (is_file(\OC::$SERVERROOT . '/config/mount.json')) { diff --git a/lib/files/storage/common.php b/lib/files/storage/common.php index 4e7a73e5d4a..8faacdf01d8 100644 --- a/lib/files/storage/common.php +++ b/lib/files/storage/common.php @@ -278,7 +278,7 @@ abstract class Common implements \OC\Files\Storage\Storage { return uniqid(); } } - + /** * clean a path, i.e. remove all redundant '.' and '..' * making sure that it can't point to higher than '/' @@ -289,7 +289,7 @@ abstract class Common implements \OC\Files\Storage\Storage { if (strlen($path) == 0 or $path[0] != '/') { $path = '/' . $path; } - + $output = array(); foreach (explode('/', $path) as $chunk) { if ($chunk == '..') { diff --git a/lib/group.php b/lib/group.php index 8c06ddc0fd0..88f0a2a032c 100644 --- a/lib/group.php +++ b/lib/group.php @@ -286,31 +286,31 @@ class OC_Group { } return $users; } - - /** - * @brief get a list of all display names in a group - * @returns array with display names (value) and user ids(key) - */ - public static function displayNamesInGroup($gid, $search = '', $limit = -1, $offset = 0) { - $displayNames=array(); - foreach(self::$_usedBackends as $backend) { - $displayNames = array_merge($backend->displayNamesInGroup($gid, $search, $limit, $offset), $displayNames); - } - return $displayNames; + + /** + * @brief get a list of all display names in a group + * @returns array with display names (value) and user ids(key) + */ + public static function displayNamesInGroup($gid, $search = '', $limit = -1, $offset = 0) { + $displayNames=array(); + foreach(self::$_usedBackends as $backend) { + $displayNames = array_merge($backend->displayNamesInGroup($gid, $search, $limit, $offset), $displayNames); + } + return $displayNames; } - - /** - * @brief get a list of all display names in several groups - * @param array $gids - * @param string $search - * @param int $limit - * @param int $offset - * @return array with display names (Key) user ids (value) - */ - public static function displayNamesInGroups($gids, $search = '', $limit = -1, $offset = 0) { + + /** + * @brief get a list of all display names in several groups + * @param array $gids + * @param string $search + * @param int $limit + * @param int $offset + * @return array with display names (Key) user ids (value) + */ + public static function displayNamesInGroups($gids, $search = '', $limit = -1, $offset = 0) { $displayNames = array(); - foreach ($gids as $gid) { - // TODO Need to apply limits to groups as total + foreach ($gids as $gid) { + // TODO Need to apply limits to groups as total $diff = array_diff( self::displayNamesInGroup($gid, $search, $limit, $offset), $displayNames @@ -318,7 +318,7 @@ class OC_Group { if ($diff) { $displayNames = array_merge($diff, $displayNames); } - } - return $displayNames; + } + return $displayNames; } } diff --git a/lib/group/backend.php b/lib/group/backend.php index 4f6570c3be3..e7b7b21d957 100644 --- a/lib/group/backend.php +++ b/lib/group/backend.php @@ -133,23 +133,23 @@ abstract class OC_Group_Backend implements OC_Group_Interface { public function usersInGroup($gid, $search = '', $limit = -1, $offset = 0) { return array(); } - - /** - * @brief get a list of all display names in a group - * @param string $gid - * @param string $search - * @param int $limit - * @param int $offset - * @return array with display names (value) and user ids (key) - */ - public function DisplayNamesInGroup($gid, $search = '', $limit = -1, $offset = 0) { - $displayNames = ''; - $users = $this->usersInGroup($gid, $search, $limit, $offset); - foreach ( $users as $user ) { - $DisplayNames[$user] = $user; - } - - return $DisplayNames; + + /** + * @brief get a list of all display names in a group + * @param string $gid + * @param string $search + * @param int $limit + * @param int $offset + * @return array with display names (value) and user ids (key) + */ + public function DisplayNamesInGroup($gid, $search = '', $limit = -1, $offset = 0) { + $displayNames = ''; + $users = $this->usersInGroup($gid, $search, $limit, $offset); + foreach ( $users as $user ) { + $DisplayNames[$user] = $user; + } + + return $DisplayNames; } } diff --git a/lib/group/database.php b/lib/group/database.php index 93dc05c53a1..40e9b0d4147 100644 --- a/lib/group/database.php +++ b/lib/group/database.php @@ -210,16 +210,16 @@ class OC_Group_Database extends OC_Group_Backend { } return $users; } - - /** - * @brief get a list of all display names in a group - * @param string $gid - * @param string $search - * @param int $limit - * @param int $offset - * @return array with display names (value) and user ids (key) - */ - public function DisplayNamesInGroup($gid, $search = '', $limit = -1, $offset = 0) { + + /** + * @brief get a list of all display names in a group + * @param string $gid + * @param string $search + * @param int $limit + * @param int $offset + * @return array with display names (value) and user ids (key) + */ + public function DisplayNamesInGroup($gid, $search = '', $limit = -1, $offset = 0) { $displayNames = ''; $stmt = OC_DB::prepare('SELECT `*PREFIX*users`.`uid`, `*PREFIX*users`.`displayname`' @@ -228,12 +228,12 @@ class OC_Group_Database extends OC_Group_Backend { .' WHERE `gid` = ? AND `*PREFIX*group_user`.`uid` LIKE ?', $limit, $offset); - $result = $stmt->execute(array($gid, $search.'%')); - $users = array(); + $result = $stmt->execute(array($gid, $search.'%')); + $users = array(); while ($row = $result->fetchRow()) { - $displayName = trim($row['displayname'], ' '); - $displayNames[$row['uid']] = empty($displayName) ? $row['uid'] : $displayName; - } - return $displayNames; + $displayName = trim($row['displayname'], ' '); + $displayNames[$row['uid']] = empty($displayName) ? $row['uid'] : $displayName; + } + return $displayNames; } } diff --git a/lib/hook.php b/lib/hook.php index 554381251d6..8516cf0dcff 100644 --- a/lib/hook.php +++ b/lib/hook.php @@ -20,23 +20,23 @@ class OC_Hook{ * TODO: write example */ static public function connect( $signalclass, $signalname, $slotclass, $slotname ) { - // If we're trying to connect to an emitting class that isn't + // If we're trying to connect to an emitting class that isn't // yet registered, register it if( !array_key_exists( $signalclass, self::$registered )) { self::$registered[$signalclass] = array(); } - // If we're trying to connect to an emitting method that isn't + // If we're trying to connect to an emitting method that isn't // yet registered, register it with the emitting class - if( !array_key_exists( $signalname, self::$registered[$signalclass] )) { + if( !array_key_exists( $signalname, self::$registered[$signalclass] )) { self::$registered[$signalclass][$signalname] = array(); } - + // Connect the hook handler to the requested emitter self::$registered[$signalclass][$signalname][] = array( "class" => $slotclass, "name" => $slotname ); - + // No chance for failure ;-) return true; } @@ -53,19 +53,19 @@ class OC_Hook{ * TODO: write example */ static public function emit( $signalclass, $signalname, $params = array()) { - + // Return false if no hook handlers are listening to this // emitting class if( !array_key_exists( $signalclass, self::$registered )) { return false; } - + // Return false if no hook handlers are listening to this // emitting method if( !array_key_exists( $signalname, self::$registered[$signalclass] )) { return false; } - + // Call all slots foreach( self::$registered[$signalclass][$signalname] as $i ) { try { diff --git a/lib/image.php b/lib/image.php index dc1c6df85ae..97b0231047b 100644 --- a/lib/image.php +++ b/lib/image.php @@ -765,7 +765,7 @@ class OC_Image { imagealphablending($process, false); imagesavealpha($process, true); } - + imagecopyresampled($process, $this->resource, 0, 0, $x, $y, $targetWidth, $targetHeight, $width, $height); if ($process == false) { OC_Log::write('core', diff --git a/lib/public/share.php b/lib/public/share.php index c0f35333e83..37cf0838ed1 100644 --- a/lib/public/share.php +++ b/lib/public/share.php @@ -384,7 +384,7 @@ class Share { 'itemSource' => $itemSource, 'shareType' => $shareType, 'shareWith' => $shareWith, - )); + )); self::delete($item['id']); return true; } @@ -404,7 +404,7 @@ class Share { 'itemType' => $itemType, 'itemSource' => $itemSource, 'shares' => $shares - )); + )); foreach ($shares as $share) { self::delete($share['id']); } @@ -848,7 +848,7 @@ class Share { if ( isset($row['uid_owner']) && $row['uid_owner'] != '') { $row['displayname_owner'] = \OCP\User::getDisplayName($row['uid_owner']); } - + $items[$row['id']] = $row; } if (!empty($items)) { diff --git a/lib/public/user.php b/lib/public/user.php index 86d1d0ccde8..9edebe0e7cf 100644 --- a/lib/public/user.php +++ b/lib/public/user.php @@ -52,25 +52,25 @@ class User { public static function getUsers($search = '', $limit = null, $offset = null) { return \OC_USER::getUsers(); } - - /** - * @brief get the user display name of the user currently logged in. - * @return string display name - */ - public static function getDisplayName($user=null) { - return \OC_USER::getDisplayName($user); + + /** + * @brief get the user display name of the user currently logged in. + * @return string display name + */ + public static function getDisplayName($user=null) { + return \OC_USER::getDisplayName($user); } - - /** - * @brief Get a list of all display names - * @returns array with all display names (value) and the correspondig uids (key) - * - * Get a list of all display names and user ids. - */ - public static function getDisplayNames($search = '', $limit = null, $offset = null) { - return \OC_USER::getDisplayNames($search, $limit, $offset); + + /** + * @brief Get a list of all display names + * @returns array with all display names (value) and the correspondig uids (key) + * + * Get a list of all display names and user ids. + */ + public static function getDisplayNames($search = '', $limit = null, $offset = null) { + return \OC_USER::getDisplayNames($search, $limit, $offset); } - + /** * @brief Check if the user is logged in * @returns true/false diff --git a/lib/request.php b/lib/request.php index 3af93289670..30a25df23ab 100755 --- a/lib/request.php +++ b/lib/request.php @@ -149,7 +149,7 @@ class OC_Request { return 'gzip'; return false; } - + /** * @brief Check if the requester sent along an mtime * @returns false or an mtime diff --git a/lib/search.php b/lib/search.php index e5a65f7157d..b9c75dfc333 100644 --- a/lib/search.php +++ b/lib/search.php @@ -57,14 +57,14 @@ class OC_Search{ } return $results; } - + /** * remove an existing search provider * @param string $provider class name of a OC_Search_Provider */ public static function removeProvider($provider) { self::$registeredProviders = array_filter( - self::$registeredProviders, + self::$registeredProviders, function ($element) use ($provider) { return ($element['class'] != $provider); } diff --git a/lib/setup.php b/lib/setup.php index faf011fccb1..19e4a82b51f 100644 --- a/lib/setup.php +++ b/lib/setup.php @@ -98,7 +98,7 @@ class OC_Setup { $error[] = array( 'error' => $e->getMessage(), 'hint' => $e->getHint() - ); + ); return($error); } catch (Exception $e) { $error[] = array( @@ -174,7 +174,7 @@ class OC_Setup { OC_Appconfig::setValue('core', 'lastupdatedat', microtime(true)); OC_AppConfig::setValue('core', 'remote_core.css', '/core/minimizer.php'); OC_AppConfig::setValue('core', 'remote_core.js', '/core/minimizer.php'); - + OC_Group::createGroup('admin'); OC_Group::addToGroup($username, 'admin'); OC_User::login($username, $password); @@ -276,7 +276,7 @@ class OC_Setup { $query = "CREATE USER '$name'@'%' IDENTIFIED BY '$password'"; $result = mysql_query($query, $connection); if (!$result) { - throw new DatabaseSetupException($l->t("MySQL user '%s'@'%%' already exists", array($name)), + throw new DatabaseSetupException($l->t("MySQL user '%s'@'%%' already exists", array($name)), $l->t("Drop this user from MySQL.")); } } @@ -550,7 +550,7 @@ class OC_Setup { $result = oci_execute($stmt); if(!$result) { $entry = $l->t('DB Error: "%s"', array(oci_error($connection))) . '
'; - $entry .= $l->t('Offending command was: "%s", name: %s, password: %s', + $entry .= $l->t('Offending command was: "%s", name: %s, password: %s', array($query, $name, $password)) . '
'; echo($entry); } @@ -582,7 +582,7 @@ class OC_Setup { $result = oci_execute($stmt); if(!$result) { $entry = $l->t('DB Error: "%s"', array(oci_error($connection))) . '
'; - $entry .= $l->t('Offending command was: "%s", name: %s, password: %s', + $entry .= $l->t('Offending command was: "%s", name: %s, password: %s', array($query, $name, $password)) . '
'; echo($entry); } diff --git a/lib/user.php b/lib/user.php index e69fef95a13..16f6d2787cb 100644 --- a/lib/user.php +++ b/lib/user.php @@ -437,7 +437,7 @@ class OC_User { } return false; } - + /** * @brief Check whether user can change his display name * @param $uid The username diff --git a/lib/user/backend.php b/lib/user/backend.php index 60b3cc6c5e4..93e8f17ca98 100644 --- a/lib/user/backend.php +++ b/lib/user/backend.php @@ -124,7 +124,7 @@ abstract class OC_User_Backend implements OC_User_Interface { public function getHome($uid) { return false; } - + /** * @brief get display name of the user * @param $uid user ID of the user @@ -133,7 +133,7 @@ abstract class OC_User_Backend implements OC_User_Interface { public function getDisplayName($uid) { return $uid; } - + /** * @brief Get a list of all display names * @returns array with all displayNames (value) and the corresponding uids (key) diff --git a/lib/user/database.php b/lib/user/database.php index a0ad03fe0a0..210c7f3e1eb 100644 --- a/lib/user/database.php +++ b/lib/user/database.php @@ -110,7 +110,7 @@ class OC_User_Database extends OC_User_Backend { return false; } } - + /** * @brief Set display name * @param $uid The username @@ -146,7 +146,7 @@ class OC_User_Database extends OC_User_Backend { } } } - + /** * @brief Get a list of all display names * @returns array with all displayNames (value) and the correspondig uids (key) @@ -162,7 +162,7 @@ class OC_User_Database extends OC_User_Backend { while ($row = $result->fetchRow()) { $displayNames[$row['uid']] = $row['displayname']; } - + // let's see if we can also find some users who don't have a display name yet $query = OC_DB::prepare('SELECT `uid`, `displayname` FROM `*PREFIX*users`' .' WHERE LOWER(`uid`) LIKE LOWER(?)', $limit, $offset); @@ -173,11 +173,11 @@ class OC_User_Database extends OC_User_Backend { $displayNames[$row['uid']] = $row['uid']; } } - - + + return $displayNames; } - + /** * @brief Check if the password is correct * @param $uid The username diff --git a/settings/ajax/changedisplayname.php b/settings/ajax/changedisplayname.php index 08c1b1455cd..dff4d733cd2 100644 --- a/settings/ajax/changedisplayname.php +++ b/settings/ajax/changedisplayname.php @@ -1,33 +1,33 @@ - array( "message" => $l->t("Authentication error") ))); - exit(); -} - -// Return Success story -if( OC_User::setDisplayName( $username, $displayName )) { - OC_JSON::success(array("data" => array( "username" => $username, 'displayName' => $displayName ))); -} -else{ + array( "message" => $l->t("Authentication error") ))); + exit(); +} + +// Return Success story +if( OC_User::setDisplayName( $username, $displayName )) { + OC_JSON::success(array("data" => array( "username" => $username, 'displayName' => $displayName ))); +} +else{ OC_JSON::error(array("data" => array( "message" => $l->t("Unable to change display name"), 'displayName' => OC_User::getDisplayName($username) ))); } diff --git a/settings/routes.php b/settings/routes.php index 26d933dba45..b20119b5803 100644 --- a/settings/routes.php +++ b/settings/routes.php @@ -39,7 +39,7 @@ $this->create('settings_ajax_removegroup', '/settings/ajax/removegroup.php') ->actionInclude('settings/ajax/removegroup.php'); $this->create('settings_ajax_changepassword', '/settings/ajax/changepassword.php') ->actionInclude('settings/ajax/changepassword.php'); -$this->create('settings_ajax_changedisplayname', '/settings/ajax/changedisplayname.php') +$this->create('settings_ajax_changedisplayname', '/settings/ajax/changedisplayname.php') ->actionInclude('settings/ajax/changedisplayname.php'); // personel $this->create('settings_ajax_lostpassword', '/settings/ajax/lostpassword.php') -- cgit v1.2.3 From 6b33a23a513b612416d8219a516331ffa695efe2 Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Tue, 26 Feb 2013 02:51:57 +0100 Subject: Code style --- lib/files/storage/common.php | 187 ++++++++++++++++++++++++------------------- 1 file changed, 106 insertions(+), 81 deletions(-) (limited to 'lib/files') diff --git a/lib/files/storage/common.php b/lib/files/storage/common.php index f9c6bdfce0c..0e596561920 100644 --- a/lib/files/storage/common.php +++ b/lib/files/storage/common.php @@ -22,81 +22,94 @@ namespace OC\Files\Storage; abstract class Common implements \OC\Files\Storage\Storage { - public function __construct($parameters) {} + public function __construct($parameters) { + } + public function is_dir($path) { - return $this->filetype($path)=='dir'; + return $this->filetype($path) == 'dir'; } + public function is_file($path) { - return $this->filetype($path)=='file'; + return $this->filetype($path) == 'file'; } + public function filesize($path) { - if($this->is_dir($path)) { - return 0;//by definition - }else{ + if ($this->is_dir($path)) { + return 0; //by definition + } else { $stat = $this->stat($path); return $stat['size']; } } + public function isCreatable($path) { if ($this->is_dir($path) && $this->isUpdatable($path)) { return true; } return false; } + public function isDeletable($path) { return $this->isUpdatable($path); } + public function isSharable($path) { return $this->isReadable($path); } - public function getPermissions($path){ + + public function getPermissions($path) { $permissions = 0; - if($this->isCreatable($path)) { + if ($this->isCreatable($path)) { $permissions |= \OCP\PERMISSION_CREATE; } - if($this->isReadable($path)) { + if ($this->isReadable($path)) { $permissions |= \OCP\PERMISSION_READ; } - if($this->isUpdatable($path)) { + if ($this->isUpdatable($path)) { $permissions |= \OCP\PERMISSION_UPDATE; } - if($this->isDeletable($path)) { + if ($this->isDeletable($path)) { $permissions |= \OCP\PERMISSION_DELETE; } - if($this->isSharable($path)) { + if ($this->isSharable($path)) { $permissions |= \OCP\PERMISSION_SHARE; } return $permissions; } + public function filemtime($path) { $stat = $this->stat($path); return $stat['mtime']; } + public function file_get_contents($path) { $handle = $this->fopen($path, "r"); - if(!$handle) { + if (!$handle) { return false; } - $size=$this->filesize($path); - if($size==0) { + $size = $this->filesize($path); + if ($size == 0) { return ''; } return fread($handle, $size); } + public function file_put_contents($path, $data) { $handle = $this->fopen($path, "w"); return fwrite($handle, $data); } + public function rename($path1, $path2) { - if($this->copy($path1, $path2)) { + if ($this->copy($path1, $path2)) { return $this->unlink($path1); - }else{ + } else { return false; } } + public function copy($path1, $path2) { - $source=$this->fopen($path1, 'r'); - $target=$this->fopen($path2, 'w'); + $source = $this->fopen($path1, 'r'); + $target = $this->fopen($path2, 'w'); list($count, $result) = \OC_Helper::streamCopy($source, $target); return $result; } @@ -110,29 +123,30 @@ abstract class Common implements \OC\Files\Storage\Storage { * @note By default the directory specified by $directory will be * deleted together with its contents. To avoid this set $empty to true */ - public function deleteAll( $directory, $empty = false ) { + public function deleteAll($directory, $empty = false) { $directory = trim($directory, '/'); - if ( !$this->file_exists( \OCP\USER::getUser() . '/' . $directory ) - || !$this->is_dir( \OCP\USER::getUser() . '/' . $directory ) ) { + if (!$this->file_exists(\OCP\USER::getUser() . '/' . $directory) + || !$this->is_dir(\OCP\USER::getUser() . '/' . $directory) + ) { return false; - } elseif( !$this->isReadable( \OCP\USER::getUser() . '/' . $directory ) ) { + } elseif (!$this->isReadable(\OCP\USER::getUser() . '/' . $directory)) { return false; } else { - $directoryHandle = $this->opendir( \OCP\USER::getUser() . '/' . $directory ); - while ( $contents = readdir( $directoryHandle ) ) { - if ( $contents != '.' && $contents != '..') { + $directoryHandle = $this->opendir(\OCP\USER::getUser() . '/' . $directory); + while ($contents = readdir($directoryHandle)) { + if ($contents != '.' && $contents != '..') { $path = $directory . "/" . $contents; - if ( $this->is_dir( $path ) ) { - $this->deleteAll( $path ); + if ($this->is_dir($path)) { + $this->deleteAll($path); } else { - $this->unlink( \OCP\USER::getUser() .'/' . $path ); // TODO: make unlink use same system path as is_dir + $this->unlink(\OCP\USER::getUser() . '/' . $path); // TODO: make unlink use same system path as is_dir } } } //$this->closedir( $directoryHandle ); // TODO: implement closedir in OC_FSV - if ( $empty == false ) { - if ( !$this->rmdir( $directory ) ) { + if ($empty == false) { + if (!$this->rmdir($directory)) { return false; } } @@ -140,88 +154,95 @@ abstract class Common implements \OC\Files\Storage\Storage { } } + public function getMimeType($path) { - if(!$this->file_exists($path)) { + if (!$this->file_exists($path)) { return false; } - if($this->is_dir($path)) { + if ($this->is_dir($path)) { return 'httpd/unix-directory'; } - $source=$this->fopen($path, 'r'); - if(!$source) { + $source = $this->fopen($path, 'r'); + if (!$source) { return false; } - $head=fread($source, 8192);//8kb should suffice to determine a mimetype - if($pos=strrpos($path, '.')) { - $extension=substr($path, $pos); - }else{ - $extension=''; + $head = fread($source, 8192); //8kb should suffice to determine a mimetype + if ($pos = strrpos($path, '.')) { + $extension = substr($path, $pos); + } else { + $extension = ''; } - $tmpFile=\OC_Helper::tmpFile($extension); + $tmpFile = \OC_Helper::tmpFile($extension); file_put_contents($tmpFile, $head); - $mime=\OC_Helper::getMimeType($tmpFile); + $mime = \OC_Helper::getMimeType($tmpFile); unlink($tmpFile); return $mime; } + public function hash($type, $path, $raw = false) { - $tmpFile=$this->getLocalFile($path); - $hash=hash($type, $tmpFile, $raw); + $tmpFile = $this->getLocalFile($path); + $hash = hash($type, $tmpFile, $raw); unlink($tmpFile); return $hash; } + public function search($query) { return $this->searchInDir($query); } + public function getLocalFile($path) { return $this->toTmpFile($path); } - private function toTmpFile($path) {//no longer in the storage api, still useful here - $source=$this->fopen($path, 'r'); - if(!$source) { + + private function toTmpFile($path) { //no longer in the storage api, still useful here + $source = $this->fopen($path, 'r'); + if (!$source) { return false; } - if($pos=strrpos($path, '.')) { - $extension=substr($path, $pos); - }else{ - $extension=''; + if ($pos = strrpos($path, '.')) { + $extension = substr($path, $pos); + } else { + $extension = ''; } - $tmpFile=\OC_Helper::tmpFile($extension); - $target=fopen($tmpFile, 'w'); + $tmpFile = \OC_Helper::tmpFile($extension); + $target = fopen($tmpFile, 'w'); \OC_Helper::streamCopy($source, $target); return $tmpFile; } + public function getLocalFolder($path) { - $baseDir=\OC_Helper::tmpFolder(); + $baseDir = \OC_Helper::tmpFolder(); $this->addLocalFolder($path, $baseDir); return $baseDir; } + private function addLocalFolder($path, $target) { - if($dh=$this->opendir($path)) { - while($file=readdir($dh)) { - if($file!=='.' and $file!=='..') { - if($this->is_dir($path.'/'.$file)) { - mkdir($target.'/'.$file); - $this->addLocalFolder($path.'/'.$file, $target.'/'.$file); - }else{ - $tmp=$this->toTmpFile($path.'/'.$file); - rename($tmp, $target.'/'.$file); + if ($dh = $this->opendir($path)) { + while ($file = readdir($dh)) { + if ($file !== '.' and $file !== '..') { + if ($this->is_dir($path . '/' . $file)) { + mkdir($target . '/' . $file); + $this->addLocalFolder($path . '/' . $file, $target . '/' . $file); + } else { + $tmp = $this->toTmpFile($path . '/' . $file); + rename($tmp, $target . '/' . $file); } } } } } - protected function searchInDir($query, $dir='') { - $files=array(); - $dh=$this->opendir($dir); - if($dh) { - while($item=readdir($dh)) { + protected function searchInDir($query, $dir = '') { + $files = array(); + $dh = $this->opendir($dir); + if ($dh) { + while ($item = readdir($dh)) { if ($item == '.' || $item == '..') continue; - if(strstr(strtolower($item), strtolower($query))!==false) { - $files[]=$dir.'/'.$item; + if (strstr(strtolower($item), strtolower($query)) !== false) { + $files[] = $dir . '/' . $item; } - if($this->is_dir($dir.'/'.$item)) { - $files=array_merge($files, $this->searchInDir($query, $dir.'/'.$item)); + if ($this->is_dir($dir . '/' . $item)) { + $files = array_merge($files, $this->searchInDir($query, $dir . '/' . $item)); } } } @@ -230,32 +251,34 @@ abstract class Common implements \OC\Files\Storage\Storage { /** * check if a file or folder has been updated since $time + * * @param string $path * @param int $time * @return bool */ public function hasUpdated($path, $time) { - return $this->filemtime($path)>$time; + return $this->filemtime($path) > $time; } - public function getCache($path=''){ + public function getCache($path = '') { return new \OC\Files\Cache\Cache($this); } - public function getScanner($path=''){ + public function getScanner($path = '') { return new \OC\Files\Cache\Scanner($this); } - public function getPermissionsCache($path=''){ + public function getPermissionsCache($path = '') { return new \OC\Files\Cache\Permissions($this); } - public function getWatcher($path=''){ + public function getWatcher($path = '') { return new \OC\Files\Cache\Watcher($this); } /** * get the owner of a path + * * @param string $path The path to get the owner * @return string uid or false */ @@ -269,12 +292,12 @@ abstract class Common implements \OC\Files\Storage\Storage { * @param string $path * @return string */ - public function getETag($path){ + public function getETag($path) { $ETagFunction = \OC_Connector_Sabre_Node::$ETagFunction; - if($ETagFunction) { + if ($ETagFunction) { $hash = call_user_func($ETagFunction, $path); return $hash; - }else{ + } else { return uniqid(); } } @@ -282,6 +305,7 @@ abstract class Common implements \OC\Files\Storage\Storage { /** * clean a path, i.e. remove all redundant '.' and '..' * making sure that it can't point to higher than '/' + * * @param $path The path to clean * @return string cleaned path */ @@ -304,10 +328,11 @@ abstract class Common implements \OC\Files\Storage\Storage { /** * get the free space in the storage + * * @param $path * return int */ - public function free_space($path){ + public function free_space($path) { return \OC\Files\FREE_SPACE_UNKNOWN; } } -- cgit v1.2.3 From 52dccd4aa14612ed93f50967e85ed6a0c6e22295 Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Tue, 26 Feb 2013 02:53:02 +0100 Subject: Storage: don't throw warnings when a stat fails --- lib/files/storage/common.php | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) (limited to 'lib/files') diff --git a/lib/files/storage/common.php b/lib/files/storage/common.php index 0e596561920..cb41d17e446 100644 --- a/lib/files/storage/common.php +++ b/lib/files/storage/common.php @@ -38,7 +38,11 @@ abstract class Common implements \OC\Files\Storage\Storage { return 0; //by definition } else { $stat = $this->stat($path); - return $stat['size']; + if (isset($stat['size'])) { + return $stat['size']; + } else { + return 0; + } } } @@ -79,7 +83,11 @@ abstract class Common implements \OC\Files\Storage\Storage { public function filemtime($path) { $stat = $this->stat($path); - return $stat['mtime']; + if (isset($stat['mtime'])) { + return $stat['mtime']; + } else { + return 0; + } } public function file_get_contents($path) { -- cgit v1.2.3 From f7a43391a7de336a6816304478c08017e24a2a54 Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Thu, 28 Feb 2013 17:04:34 +0100 Subject: Cache: add option to delete file from permissions cache for all users --- lib/files/cache/permissions.php | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) (limited to 'lib/files') diff --git a/lib/files/cache/permissions.php b/lib/files/cache/permissions.php index e1735831b94..a5c9c144054 100644 --- a/lib/files/cache/permissions.php +++ b/lib/files/cache/permissions.php @@ -17,10 +17,10 @@ class Permissions { /** * @param \OC\Files\Storage\Storage|string $storage */ - public function __construct($storage){ - if($storage instanceof \OC\Files\Storage\Storage) { + public function __construct($storage) { + if ($storage instanceof \OC\Files\Storage\Storage) { $this->storageId = $storage->getId(); - }else{ + } else { $this->storageId = $storage; } } @@ -52,10 +52,10 @@ class Permissions { public function set($fileId, $user, $permissions) { if (self::get($fileId, $user) !== -1) { $query = \OC_DB::prepare('UPDATE `*PREFIX*permissions` SET `permissions` = ?' - .' WHERE `user` = ? AND `fileid` = ?'); + . ' WHERE `user` = ? AND `fileid` = ?'); } else { $query = \OC_DB::prepare('INSERT INTO `*PREFIX*permissions`(`permissions`, `user`, `fileid`)' - .' VALUES(?, ?,? )'); + . ' VALUES(?, ?,? )'); } $query->execute(array($permissions, $user, $fileId)); } @@ -76,7 +76,7 @@ class Permissions { $inPart = implode(', ', array_fill(0, count($fileIds), '?')); $query = \OC_DB::prepare('SELECT `fileid`, `permissions` FROM `*PREFIX*permissions`' - .' WHERE `fileid` IN (' . $inPart . ') AND `user` = ?'); + . ' WHERE `fileid` IN (' . $inPart . ') AND `user` = ?'); $result = $query->execute($params); $filePermissions = array(); while ($row = $result->fetchRow()) { @@ -91,14 +91,19 @@ class Permissions { * @param int $fileId * @param string $user */ - public function remove($fileId, $user) { - $query = \OC_DB::prepare('DELETE FROM `*PREFIX*permissions` WHERE `fileid` = ? AND `user` = ?'); - $query->execute(array($fileId, $user)); + public function remove($fileId, $user = null) { + if (is_null($user)) { + $query = \OC_DB::prepare('DELETE FROM `*PREFIX*permissions` WHERE `fileid` = ?'); + $query->execute(array($fileId)); + } else { + $query = \OC_DB::prepare('DELETE FROM `*PREFIX*permissions` WHERE `fileid` = ? AND `user` = ?'); + $query->execute(array($fileId, $user)); + } } public function removeMultiple($fileIds, $user) { $query = \OC_DB::prepare('DELETE FROM `*PREFIX*permissions` WHERE `fileid` = ? AND `user` = ?'); - foreach($fileIds as $fileId){ + foreach ($fileIds as $fileId) { $query->execute(array($fileId, $user)); } } -- cgit v1.2.3 From ee1eb98d4aadf980297ae81017e213d7c22e1c25 Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Thu, 28 Feb 2013 17:04:50 +0100 Subject: Cache: cleanup permissions cache when removing a file from the cache --- lib/files/cache/cache.php | 3 +++ 1 file changed, 3 insertions(+) (limited to 'lib/files') diff --git a/lib/files/cache/cache.php b/lib/files/cache/cache.php index 01e6e788263..f288919df74 100644 --- a/lib/files/cache/cache.php +++ b/lib/files/cache/cache.php @@ -313,6 +313,9 @@ class Cache { } $query = \OC_DB::prepare('DELETE FROM `*PREFIX*filecache` WHERE `fileid` = ?'); $query->execute(array($entry['fileid'])); + + $permissionsCache = new Permissions($this->storageId); + $permissionsCache->remove($entry['fileid']); } /** -- cgit v1.2.3 From 71bdccf3471ed7ff97c4e636ce18e4a018894d38 Mon Sep 17 00:00:00 2001 From: Michael Gapczynski Date: Sun, 3 Mar 2013 12:03:26 -0500 Subject: Chunk size comment should say kB, not MB --- lib/files/view.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib/files') diff --git a/lib/files/view.php b/lib/files/view.php index f48d0c8b225..3e2cb080e1d 100644 --- a/lib/files/view.php +++ b/lib/files/view.php @@ -199,7 +199,7 @@ class View { @ob_end_clean(); $handle = $this->fopen($path, 'rb'); if ($handle) { - $chunkSize = 8192; // 8 MB chunks + $chunkSize = 8192; // 8 kB chunks while (!feof($handle)) { echo fread($handle, $chunkSize); flush(); -- cgit v1.2.3 From 56ae4bb6e9a08c5ada36b4c42ae4e22eaf288df7 Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Mon, 4 Mar 2013 22:26:03 +0100 Subject: Cache: also check if the file id is already in the cache during upgrade Should solve upgrade issues if only some of the configured storages were migrated previously --- lib/files/cache/upgrade.php | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) (limited to 'lib/files') diff --git a/lib/files/cache/upgrade.php b/lib/files/cache/upgrade.php index 1fe4c584686..4d98abb2f8d 100644 --- a/lib/files/cache/upgrade.php +++ b/lib/files/cache/upgrade.php @@ -64,7 +64,7 @@ class Upgrade { * @param array $data the data for the new cache */ function insert($data) { - if (!$this->inCache($data['storage'], $data['path_hash'])) { + if (!$this->inCache($data['storage'], $data['path_hash'], $data['id'])) { $insertQuery = \OC_DB::prepare('INSERT INTO `*PREFIX*filecache` ( `fileid`, `storage`, `path`, `path_hash`, `parent`, `name`, `mimetype`, `mimepart`, `size`, `mtime`, `encrypted` ) VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)'); @@ -78,12 +78,19 @@ class Upgrade { /** * @param string $storage * @param string $pathHash + * @param string $id * @return bool */ - function inCache($storage, $pathHash) { + function inCache($storage, $pathHash, $id) { $query = \OC_DB::prepare('SELECT `fileid` FROM `*PREFIX*filecache` WHERE `storage` = ? AND `path_hash` = ?'); $result = $query->execute(array($storage, $pathHash)); - return (bool)$result->fetchRow(); + if ($result->fetchRow()) { + return true; + } else { + $query = \OC_DB::prepare('SELECT `fileid` FROM `*PREFIX*filecache` WHERE `fileid` = ?'); + $result = $query->execute(array($id)); + return (bool)$result->fetchRow(); + } } /** -- cgit v1.2.3 From 9d9acf24de482bdd5d0b700ba75631b246e5699b Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Mon, 4 Mar 2013 23:19:55 +0100 Subject: Cache: more efficient detection for existing entries during upgrade --- lib/files/cache/upgrade.php | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) (limited to 'lib/files') diff --git a/lib/files/cache/upgrade.php b/lib/files/cache/upgrade.php index 4d98abb2f8d..811d82d7437 100644 --- a/lib/files/cache/upgrade.php +++ b/lib/files/cache/upgrade.php @@ -82,15 +82,9 @@ class Upgrade { * @return bool */ function inCache($storage, $pathHash, $id) { - $query = \OC_DB::prepare('SELECT `fileid` FROM `*PREFIX*filecache` WHERE `storage` = ? AND `path_hash` = ?'); - $result = $query->execute(array($storage, $pathHash)); - if ($result->fetchRow()) { - return true; - } else { - $query = \OC_DB::prepare('SELECT `fileid` FROM `*PREFIX*filecache` WHERE `fileid` = ?'); - $result = $query->execute(array($id)); - return (bool)$result->fetchRow(); - } + $query = \OC_DB::prepare('SELECT `fileid` FROM `*PREFIX*filecache` WHERE (`storage` = ? AND `path_hash` = ?) OR `fileid` = ?'); + $result = $query->execute(array($storage, $pathHash, $id)); + return (bool)$result->fetchRow(); } /** -- cgit v1.2.3 From 48bb53030c657e1133da47765c7c778a069af665 Mon Sep 17 00:00:00 2001 From: Björn Schießle Date: Thu, 7 Mar 2013 15:51:44 +0100 Subject: distinguish between touch and write --- apps/files_versions/lib/hooks.php | 6 ++++++ apps/files_versions/lib/versions.php | 1 + lib/files/view.php | 10 +++++++++- 3 files changed, 16 insertions(+), 1 deletion(-) (limited to 'lib/files') diff --git a/apps/files_versions/lib/hooks.php b/apps/files_versions/lib/hooks.php index 7891b20e92f..6e81286052f 100644 --- a/apps/files_versions/lib/hooks.php +++ b/apps/files_versions/lib/hooks.php @@ -21,6 +21,12 @@ class Hooks { if(\OCP\Config::getSystemValue('files_versions', Storage::DEFAULTENABLED)=='true') { $path = $params[\OC\Files\Filesystem::signal_param_path]; + $pos = strrpos($path, '.part'); + if ($pos) { + error_log("old path: $path"); + $path = substr($path, 0, $pos); + error_log("new path: $path"); + } if($path<>'') { Storage::store($path); } diff --git a/apps/files_versions/lib/versions.php b/apps/files_versions/lib/versions.php index c37133cf32c..274f38095db 100644 --- a/apps/files_versions/lib/versions.php +++ b/apps/files_versions/lib/versions.php @@ -107,6 +107,7 @@ class Storage { // store a new version of a file $users_view->copy('files'.$filename, 'files_versions'.$filename.'.v'.$users_view->filemtime('files'.$filename)); + error_log("version created!"); $versionsSize = self::getVersionsSize($uid); if ( $versionsSize === false || $versionsSize < 0 ) { $versionsSize = self::calculateSize($uid); diff --git a/lib/files/view.php b/lib/files/view.php index 3e2cb080e1d..59339ff2071 100644 --- a/lib/files/view.php +++ b/lib/files/view.php @@ -245,7 +245,14 @@ class View { if (!is_null($mtime) and !is_numeric($mtime)) { $mtime = strtotime($mtime); } - return $this->basicOperation('touch', $path, array('write'), $mtime); + + $hooks = array('touch'); + + if (!$this->file_exists($path)) { + $hooks[] = 'write'; + } + + return $this->basicOperation('touch', $path, $hooks, $mtime); } public function file_get_contents($path) { @@ -596,6 +603,7 @@ class View { if ($path == null) { return false; } + foreach ($hooks as $h) if ($h == "write") error_log("write triggered by $operation for $path"); $run = $this->runHooks($hooks, $path); list($storage, $internalPath) = Filesystem::resolvePath($absolutePath . $postFix); if ($run and $storage) { -- cgit v1.2.3 From a5cab28bea6188ce840d7d115064c4780531e13d Mon Sep 17 00:00:00 2001 From: Michael Gapczynski Date: Thu, 7 Mar 2013 11:12:59 -0500 Subject: Fix fetching source path of shared files --- apps/files_sharing/lib/share/file.php | 23 ++++++++++++++++++++--- apps/files_sharing/lib/sharedstorage.php | 20 ++++++++++++-------- lib/files/mount.php | 26 ++++++++++++++++++++++++-- lib/files/view.php | 2 +- lib/public/share.php | 2 +- tests/lib/files/mount.php | 8 ++++---- 6 files changed, 62 insertions(+), 19 deletions(-) (limited to 'lib/files') diff --git a/apps/files_sharing/lib/share/file.php b/apps/files_sharing/lib/share/file.php index 0aeb763d89a..fa43e87b49e 100644 --- a/apps/files_sharing/lib/share/file.php +++ b/apps/files_sharing/lib/share/file.php @@ -73,7 +73,9 @@ class OC_Share_Backend_File implements OCP\Share_Backend_File_Dependent { if ($format == self::FORMAT_SHARED_STORAGE) { // Only 1 item should come through for this format call return array( + 'parent' => $items[key($items)]['parent'], 'path' => $items[key($items)]['path'], + 'storage' => $items[key($items)]['storage'], 'permissions' => $items[key($items)]['permissions'], 'uid_owner' => $items[key($items)]['uid_owner'] ); @@ -139,13 +141,28 @@ class OC_Share_Backend_File implements OCP\Share_Backend_File_Dependent { $source = \OCP\Share::getItemSharedWith('folder', $folder, \OC_Share_Backend_File::FORMAT_SHARED_STORAGE); if ($source) { $source['path'] = $source['path'].substr($target, strlen($folder)); - return $source; } } else { $source = \OCP\Share::getItemSharedWith('file', $target, \OC_Share_Backend_File::FORMAT_SHARED_STORAGE); - if ($source) { - return $source; + } + if ($source) { + if (isset($source['parent'])) { + $parent = $source['parent']; + while (isset($parent)) { + $query = \OC_DB::prepare('SELECT `parent`, `uid_owner` FROM `*PREFIX*share` WHERE `id` = ?', 1); + $item = $query->execute(array($parent))->fetchRow(); + if (isset($item['parent'])) { + $parent = $item['parent']; + } else { + $fileOwner = $item['uid_owner']; + break; + } + } + } else { + $fileOwner = $source['uid_owner']; } + $source['fileOwner'] = $fileOwner; + return $source; } \OCP\Util::writeLog('files_sharing', 'File source not found for: '.$target, \OCP\Util::ERROR); return false; diff --git a/apps/files_sharing/lib/sharedstorage.php b/apps/files_sharing/lib/sharedstorage.php index 5a9864b64ba..be0e59e6732 100644 --- a/apps/files_sharing/lib/sharedstorage.php +++ b/apps/files_sharing/lib/sharedstorage.php @@ -45,11 +45,7 @@ class Shared extends \OC\Files\Storage\Common { */ private function getFile($target) { if (!isset($this->files[$target])) { - $source = \OC_Share_Backend_File::getSource($target); - if ($source) { - $source['path'] = '/'.$source['uid_owner'].'/'.$source['path']; - } - $this->files[$target] = $source; + $this->files[$target] = \OC_Share_Backend_File::getSource($target); } return $this->files[$target]; } @@ -62,8 +58,16 @@ class Shared extends \OC\Files\Storage\Common { private function getSourcePath($target) { $source = $this->getFile($target); if ($source) { - \OC\Files\Filesystem::initMountPoints($source['uid_owner']); - return $source['path']; + if (!isset($source['fullPath'])) { + \OC\Files\Filesystem::initMountPoints($source['fileOwner']); + $mount = \OC\Files\Mount::findByNumericId($source['storage']); + if ($mount) { + $this->files[$target]['fullPath'] = $mount->getMountPoint().$source['path']; + } else { + $this->files[$target]['fullPath'] = false; + } + } + return $this->files[$target]['fullPath']; } return false; } @@ -430,7 +434,7 @@ class Shared extends \OC\Files\Storage\Common { } $source = $this->getFile($path); if ($source) { - return $source['uid_owner']; + return $source['fileOwner']; } return false; } diff --git a/lib/files/mount.php b/lib/files/mount.php index 6e99d8eabb4..1c9382d78e7 100644 --- a/lib/files/mount.php +++ b/lib/files/mount.php @@ -176,10 +176,12 @@ class Mount { } /** + * Find mounts by storage id + * * @param string $id - * @return \OC\Files\Storage\Storage[] + * @return Mount[] */ - public static function findById($id) { + public static function findByStorageId($id) { if (strlen($id) > 64) { $id = md5($id); } @@ -191,4 +193,24 @@ class Mount { } return $result; } + + /** + * Find mounts by numeric storage id + * + * @param string $id + * @return Mount + */ + public static function findByNumericId($id) { + $query = \OC_DB::prepare('SELECT `id` FROM `*PREFIX*storages` WHERE `numeric_id` = ?'); + $result = $query->execute(array($id))->fetchOne(); + if ($result) { + $id = $result; + foreach (self::$mounts as $mount) { + if ($mount->getStorageId() === $id) { + return $mount; + } + } + } + return false; + } } diff --git a/lib/files/view.php b/lib/files/view.php index 3e2cb080e1d..4ed3234552e 100644 --- a/lib/files/view.php +++ b/lib/files/view.php @@ -960,7 +960,7 @@ class View { */ public function getPath($id) { list($storage, $internalPath) = Cache\Cache::getById($id); - $mounts = Mount::findById($storage); + $mounts = Mount::findByStorageId($storage); foreach ($mounts as $mount) { /** * @var \OC\Files\Mount $mount diff --git a/lib/public/share.php b/lib/public/share.php index 8146a23f360..59f41a9bfd6 100644 --- a/lib/public/share.php +++ b/lib/public/share.php @@ -786,7 +786,7 @@ class Share { } else { $select = '`*PREFIX*share`.`id`, `item_type`, `item_source`, `item_target`, `*PREFIX*share`.`parent`, `share_type`, `share_with`, `uid_owner`, - `file_source`, `path`, `file_target`, `permissions`, `stime`, `expiration`, `token`'; + `file_source`, `path`, `file_target`, `permissions`, `stime`, `expiration`, `token`, `storage`'; } } else { $select = '*'; diff --git a/tests/lib/files/mount.php b/tests/lib/files/mount.php index 4e6aaf0679b..6a5c025b0e1 100644 --- a/tests/lib/files/mount.php +++ b/tests/lib/files/mount.php @@ -42,7 +42,7 @@ class Mount extends \PHPUnit_Framework_TestCase { $this->assertEquals(array($mount), \OC\Files\Mount::findById($id)); $mount2 = new \OC\Files\Mount($storage, '/foo/bar'); - $this->assertEquals(array($mount, $mount2), \OC\Files\Mount::findById($id)); + $this->assertEquals(array($mount, $mount2), \OC\Files\Mount::findByStorageId($id)); } public function testLong() { @@ -51,8 +51,8 @@ class Mount extends \PHPUnit_Framework_TestCase { $id = $mount->getStorageId(); $storageId = $storage->getId(); - $this->assertEquals(array($mount), \OC\Files\Mount::findById($id)); - $this->assertEquals(array($mount), \OC\Files\Mount::findById($storageId)); - $this->assertEquals(array($mount), \OC\Files\Mount::findById(md5($storageId))); + $this->assertEquals(array($mount), \OC\Files\Mount::findByStorageId($id)); + $this->assertEquals(array($mount), \OC\Files\Mount::findByStorageId($storageId)); + $this->assertEquals(array($mount), \OC\Files\Mount::findByStorageId(md5($storageId))); } } -- cgit v1.2.3 From 8d26400cb5427763b0562da8799bea52f4eae21e Mon Sep 17 00:00:00 2001 From: Björn Schießle Date: Fri, 8 Mar 2013 11:27:25 +0100 Subject: remove some debug output; move code to the right function --- apps/files_versions/lib/hooks.php | 6 ------ apps/files_versions/lib/versions.php | 8 ++++++++ lib/files/view.php | 2 +- 3 files changed, 9 insertions(+), 7 deletions(-) (limited to 'lib/files') diff --git a/apps/files_versions/lib/hooks.php b/apps/files_versions/lib/hooks.php index 6e81286052f..7891b20e92f 100644 --- a/apps/files_versions/lib/hooks.php +++ b/apps/files_versions/lib/hooks.php @@ -21,12 +21,6 @@ class Hooks { if(\OCP\Config::getSystemValue('files_versions', Storage::DEFAULTENABLED)=='true') { $path = $params[\OC\Files\Filesystem::signal_param_path]; - $pos = strrpos($path, '.part'); - if ($pos) { - error_log("old path: $path"); - $path = substr($path, 0, $pos); - error_log("new path: $path"); - } if($path<>'') { Storage::store($path); } diff --git a/apps/files_versions/lib/versions.php b/apps/files_versions/lib/versions.php index 79b16f2586f..20611c61ec7 100644 --- a/apps/files_versions/lib/versions.php +++ b/apps/files_versions/lib/versions.php @@ -82,6 +82,14 @@ class Storage { */ public static function store($filename) { if(\OCP\Config::getSystemValue('files_versions', Storage::DEFAULTENABLED)=='true') { + + // if the file gets streamed we need to remove the .part extension + // to get the right target + $ext = pathinfo($filename, PATHINFO_EXTENSION); + if ($ext === 'part') { + $filename = substr($filename, 0, strlen($filename)-5); + } + list($uid, $filename) = self::getUidAndFilename($filename); $files_view = new \OC\Files\View('/'.$uid .'/files'); diff --git a/lib/files/view.php b/lib/files/view.php index 59339ff2071..fe753342b6c 100644 --- a/lib/files/view.php +++ b/lib/files/view.php @@ -603,7 +603,7 @@ class View { if ($path == null) { return false; } - foreach ($hooks as $h) if ($h == "write") error_log("write triggered by $operation for $path"); + $run = $this->runHooks($hooks, $path); list($storage, $internalPath) = Filesystem::resolvePath($absolutePath . $postFix); if ($run and $storage) { -- cgit v1.2.3