diff options
author | Arthur Schiwon <blizzz@arthur-schiwon.de> | 2016-06-11 15:34:43 +0200 |
---|---|---|
committer | Arthur Schiwon <blizzz@arthur-schiwon.de> | 2016-06-11 15:34:43 +0200 |
commit | 42c66efea5ef512d3a3442112f820168e6499265 (patch) | |
tree | 97ef44632d653656608e71e096fd537bbd609936 /lib | |
parent | 75f37f550bb7895757325d3f9a3215bcc4471065 (diff) | |
parent | 52a0c939ab8674857bbfe9a9fb0ee7308eee960e (diff) | |
download | nextcloud-server-42c66efea5ef512d3a3442112f820168e6499265.tar.gz nextcloud-server-42c66efea5ef512d3a3442112f820168e6499265.zip |
Merge branch 'master' of https://github.com/owncloud/core into downstream-160611
Diffstat (limited to 'lib')
-rw-r--r-- | lib/l10n/pl.js | 1 | ||||
-rw-r--r-- | lib/l10n/pl.json | 1 | ||||
-rw-r--r-- | lib/l10n/pt_PT.js | 4 | ||||
-rw-r--r-- | lib/l10n/pt_PT.json | 4 | ||||
-rw-r--r-- | lib/private/AppConfig.php | 4 | ||||
-rw-r--r-- | lib/private/DB/ConnectionFactory.php | 4 | ||||
-rw-r--r-- | lib/private/Encryption/File.php | 3 | ||||
-rw-r--r-- | lib/private/Files/Cache/Propagator.php | 88 | ||||
-rw-r--r-- | lib/private/Files/Utils/Scanner.php | 4 | ||||
-rw-r--r-- | lib/private/Repair.php | 4 | ||||
-rw-r--r-- | lib/private/Repair/AvatarPermissions.php | 115 | ||||
-rw-r--r-- | lib/private/Repair/RemoveOldShares.php | 103 | ||||
-rw-r--r-- | lib/private/legacy/json.php | 4 | ||||
-rw-r--r-- | lib/private/legacy/util.php | 5 | ||||
-rw-r--r-- | lib/public/Files/Cache/IPropagator.php | 19 | ||||
-rw-r--r-- | lib/public/Migration/IRepairStep.php | 3 |
16 files changed, 358 insertions, 8 deletions
diff --git a/lib/l10n/pl.js b/lib/l10n/pl.js index 3124a335261..1a36e960779 100644 --- a/lib/l10n/pl.js +++ b/lib/l10n/pl.js @@ -30,6 +30,7 @@ OC.L10N.register( "_%n minute ago_::_%n minutes ago_" : ["%n minute temu","%n minut temu","%n minut temu"], "seconds ago" : "sekund temu", "Empty filename is not allowed" : "Pusta nazwa nie jest dozwolona.", + "4-byte characters are not supported in file names" : "Znaki 4-bajtowe są niedozwolone w nazwach plików", "File name contains at least one invalid character" : "Nazwa pliku zawiera co najmniej jeden nieprawidłowy znak", "File name is too long" : "Nazwa pliku zbyt długa", "App directory already exists" : "Katalog aplikacji już isnieje", diff --git a/lib/l10n/pl.json b/lib/l10n/pl.json index bbb4cc7b5ea..048530779e1 100644 --- a/lib/l10n/pl.json +++ b/lib/l10n/pl.json @@ -28,6 +28,7 @@ "_%n minute ago_::_%n minutes ago_" : ["%n minute temu","%n minut temu","%n minut temu"], "seconds ago" : "sekund temu", "Empty filename is not allowed" : "Pusta nazwa nie jest dozwolona.", + "4-byte characters are not supported in file names" : "Znaki 4-bajtowe są niedozwolone w nazwach plików", "File name contains at least one invalid character" : "Nazwa pliku zawiera co najmniej jeden nieprawidłowy znak", "File name is too long" : "Nazwa pliku zbyt długa", "App directory already exists" : "Katalog aplikacji już isnieje", diff --git a/lib/l10n/pt_PT.js b/lib/l10n/pt_PT.js index 196009d71d8..f069531895d 100644 --- a/lib/l10n/pt_PT.js +++ b/lib/l10n/pt_PT.js @@ -18,12 +18,12 @@ OC.L10N.register( "Following platforms are supported: %s" : "São suportadas as seguintes plataformas: %s", "ownCloud %s or higher is required." : "É necessário ownCloud %s ou superior.", "ownCloud %s or lower is required." : "É necessário ownCloud %s ou inferior.", - "Unknown filetype" : "Ficheiro desconhecido", + "Unknown filetype" : "Tipo de ficheiro desconhecido", "Invalid image" : "Imagem inválida", "today" : "hoje", "yesterday" : "ontem", "_%n day ago_::_%n days ago_" : ["%n dia atrás","%n dias atrás"], - "last month" : "ultímo mês", + "last month" : "ultimo mês", "last year" : "ano passado", "_%n year ago_::_%n years ago_" : ["%n ano atrás","%n anos atrás"], "seconds ago" : "Minutos atrás", diff --git a/lib/l10n/pt_PT.json b/lib/l10n/pt_PT.json index 5dc215f41b8..55492d0f14c 100644 --- a/lib/l10n/pt_PT.json +++ b/lib/l10n/pt_PT.json @@ -16,12 +16,12 @@ "Following platforms are supported: %s" : "São suportadas as seguintes plataformas: %s", "ownCloud %s or higher is required." : "É necessário ownCloud %s ou superior.", "ownCloud %s or lower is required." : "É necessário ownCloud %s ou inferior.", - "Unknown filetype" : "Ficheiro desconhecido", + "Unknown filetype" : "Tipo de ficheiro desconhecido", "Invalid image" : "Imagem inválida", "today" : "hoje", "yesterday" : "ontem", "_%n day ago_::_%n days ago_" : ["%n dia atrás","%n dias atrás"], - "last month" : "ultímo mês", + "last month" : "ultimo mês", "last year" : "ano passado", "_%n year ago_::_%n years ago_" : ["%n ano atrás","%n anos atrás"], "seconds ago" : "Minutos atrás", diff --git a/lib/private/AppConfig.php b/lib/private/AppConfig.php index f84c8a41f17..4e48ee149ef 100644 --- a/lib/private/AppConfig.php +++ b/lib/private/AppConfig.php @@ -273,7 +273,9 @@ class AppConfig implements IAppConfig { ->from('appconfig'); $result = $sql->execute(); - while ($row = $result->fetch()) { + // we are going to store the result in memory anyway + $rows = $result->fetchAll(); + foreach ($rows as $row) { if (!isset($this->cache[$row['appid']])) { $this->cache[$row['appid']] = []; } diff --git a/lib/private/DB/ConnectionFactory.php b/lib/private/DB/ConnectionFactory.php index 0856d8d19c0..6a096e504d8 100644 --- a/lib/private/DB/ConnectionFactory.php +++ b/lib/private/DB/ConnectionFactory.php @@ -104,6 +104,10 @@ class ConnectionFactory { break; case 'oci': $eventManager->addEventSubscriber(new OracleSessionInit); + // the driverOptions are unused in dbal and need to be mapped to the parameters + if (isset($additionalConnectionParams['driverOptions'])) { + $additionalConnectionParams = array_merge($additionalConnectionParams, $additionalConnectionParams['driverOptions']); + } break; case 'sqlite3': $journalMode = $additionalConnectionParams['sqlite.journal_mode']; diff --git a/lib/private/Encryption/File.php b/lib/private/Encryption/File.php index 2bd9fb02100..3573ff19c6e 100644 --- a/lib/private/Encryption/File.php +++ b/lib/private/Encryption/File.php @@ -22,6 +22,8 @@ namespace OC\Encryption; +use OC\Cache\CappedMemoryCache; + class File implements \OCP\Encryption\IFile { /** @var Util */ @@ -36,6 +38,7 @@ class File implements \OCP\Encryption\IFile { public function __construct(Util $util) { $this->util = $util; + $this->cache = new CappedMemoryCache(); } diff --git a/lib/private/Files/Cache/Propagator.php b/lib/private/Files/Cache/Propagator.php index b998c6bcfae..52bb4dfdfca 100644 --- a/lib/private/Files/Cache/Propagator.php +++ b/lib/private/Files/Cache/Propagator.php @@ -29,6 +29,10 @@ use OCP\IDBConnection; * Propagate etags and mtimes within the storage */ class Propagator implements IPropagator { + private $inBatch = false; + + private $batch = []; + /** * @var \OC\Files\Storage\Storage */ @@ -59,6 +63,13 @@ class Propagator implements IPropagator { $parents = $this->getParents($internalPath); + if ($this->inBatch) { + foreach ($parents as $parent) { + $this->addToBatch($parent, $time, $sizeDifference); + } + return; + } + $parentHashes = array_map('md5', $parents); $etag = uniqid(); // since we give all folders the same etag we don't ask the storage for the etag @@ -68,7 +79,7 @@ class Propagator implements IPropagator { }, $parentHashes); $builder->update('filecache') - ->set('mtime', $builder->createFunction('GREATEST(`mtime`, ' . $builder->createNamedParameter($time) . ')')) + ->set('mtime', $builder->createFunction('GREATEST(`mtime`, ' . $builder->createNamedParameter($time, IQueryBuilder::PARAM_INT) . ')')) ->set('etag', $builder->createNamedParameter($etag, IQueryBuilder::PARAM_STR)) ->where($builder->expr()->eq('storage', $builder->createNamedParameter($storageId, IQueryBuilder::PARAM_INT))) ->andWhere($builder->expr()->in('path_hash', $hashParams)); @@ -98,4 +109,79 @@ class Propagator implements IPropagator { } return $parents; } + + /** + * Mark the beginning of a propagation batch + * + * Note that not all cache setups support propagation in which case this will be a noop + * + * Batching for cache setups that do support it has to be explicit since the cache state is not fully consistent + * before the batch is committed. + */ + public function beginBatch() { + $this->inBatch = true; + } + + private function addToBatch($internalPath, $time, $sizeDifference) { + if (!isset($this->batch[$internalPath])) { + $this->batch[$internalPath] = [ + 'hash' => md5($internalPath), + 'time' => $time, + 'size' => $sizeDifference + ]; + } else { + $this->batch[$internalPath]['size'] += $sizeDifference; + if ($time > $this->batch[$internalPath]['time']) { + $this->batch[$internalPath]['time'] = $time; + } + } + } + + /** + * Commit the active propagation batch + */ + public function commitBatch() { + if (!$this->inBatch) { + throw new \BadMethodCallException('Not in batch'); + } + $this->inBatch = false; + + $this->connection->beginTransaction(); + + $query = $this->connection->getQueryBuilder(); + $storageId = (int)$this->storage->getStorageCache()->getNumericId(); + + $query->update('filecache') + ->set('mtime', $query->createFunction('GREATEST(`mtime`, ' . $query->createParameter('time') . ')')) + ->set('etag', $query->expr()->literal(uniqid())) + ->where($query->expr()->eq('storage', $query->expr()->literal($storageId, IQueryBuilder::PARAM_INT))) + ->andWhere($query->expr()->eq('path_hash', $query->createParameter('hash'))); + + $sizeQuery = $this->connection->getQueryBuilder(); + $sizeQuery->update('filecache') + ->set('size', $sizeQuery->createFunction('`size` + ' . $sizeQuery->createParameter('size'))) + ->where($query->expr()->eq('storage', $query->expr()->literal($storageId, IQueryBuilder::PARAM_INT))) + ->andWhere($query->expr()->eq('path_hash', $query->createParameter('hash'))) + ->andWhere($sizeQuery->expr()->gt('size', $sizeQuery->expr()->literal(-1, IQueryBuilder::PARAM_INT))); + + foreach ($this->batch as $item) { + $query->setParameter('time', $item['time'], IQueryBuilder::PARAM_INT); + $query->setParameter('hash', $item['hash']); + + $query->execute(); + + if ($item['size']) { + $sizeQuery->setParameter('size', $item['size'], IQueryBuilder::PARAM_INT); + $sizeQuery->setParameter('hash', $item['hash']); + + $sizeQuery->execute(); + } + } + + $this->batch = []; + + $this->connection->commit(); + } + + } diff --git a/lib/private/Files/Utils/Scanner.php b/lib/private/Files/Utils/Scanner.php index 8beba116fe1..e4e5e353f9f 100644 --- a/lib/private/Files/Utils/Scanner.php +++ b/lib/private/Files/Utils/Scanner.php @@ -138,7 +138,9 @@ class Scanner extends PublicEmitter { $this->triggerPropagator($storage, $path); }); + $storage->getPropagator()->beginBatch(); $scanner->backgroundScan(); + $storage->getPropagator()->commitBatch(); } } @@ -187,12 +189,14 @@ class Scanner extends PublicEmitter { $this->db->beginTransaction(); } try { + $storage->getPropagator()->beginBatch(); $scanner->scan($relativePath, \OC\Files\Cache\Scanner::SCAN_RECURSIVE, \OC\Files\Cache\Scanner::REUSE_ETAG | \OC\Files\Cache\Scanner::REUSE_SIZE); $cache = $storage->getCache(); if ($cache instanceof Cache) { // only re-calculate for the root folder we scanned, anything below that is taken care of by the scanner $cache->correctFolderSize($relativePath); } + $storage->getPropagator()->commitBatch(); } catch (StorageNotAvailableException $e) { $this->logger->error('Storage ' . $storage->getId() . ' not available'); $this->logger->logException($e); diff --git a/lib/private/Repair.php b/lib/private/Repair.php index 4869db77497..bb2967d7e6e 100644 --- a/lib/private/Repair.php +++ b/lib/private/Repair.php @@ -29,11 +29,13 @@ namespace OC; use OC\Repair\AssetCache; +use OC\Repair\AvatarPermissions; use OC\Repair\CleanTags; use OC\Repair\Collation; use OC\Repair\DropOldJobs; use OC\Repair\OldGroupMembershipShares; use OC\Repair\RemoveGetETagEntries; +use OC\Repair\RemoveOldShares; use OC\Repair\SharePropagation; use OC\Repair\SqliteAutoincrement; use OC\Repair\DropOldTables; @@ -132,6 +134,8 @@ class Repair implements IOutput{ new UpdateOutdatedOcsIds(\OC::$server->getConfig()), new RepairInvalidShares(\OC::$server->getConfig(), \OC::$server->getDatabaseConnection()), new SharePropagation(\OC::$server->getConfig()), + new RemoveOldShares(\OC::$server->getDatabaseConnection()), + new AvatarPermissions(\OC::$server->getDatabaseConnection()), ]; } diff --git a/lib/private/Repair/AvatarPermissions.php b/lib/private/Repair/AvatarPermissions.php new file mode 100644 index 00000000000..d23479f5ba8 --- /dev/null +++ b/lib/private/Repair/AvatarPermissions.php @@ -0,0 +1,115 @@ +<?php +/** + * @author Roeland Jago Douma <rullzer@owncloud.com> + * + * @copyright Copyright (c) 2016, ownCloud, Inc. + * @license AGPL-3.0 + * + * This code is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License, version 3, + * as published by the Free Software Foundation. + * + * This program 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, version 3, + * along with this program. If not, see <http://www.gnu.org/licenses/> + * + */ +namespace OC\Repair; + +use Doctrine\DBAL\Platforms\OraclePlatform; +use OCP\IDBConnection; +use OCP\Migration\IOutput; +use OCP\Migration\IRepairStep; + +/** + * Class AvatarPermissions + * + * @package OC\Repair + */ +class AvatarPermissions implements IRepairStep { + /** @var IDBConnection */ + private $connection; + + /** + * AvatarPermissions constructor. + * + * @param IDBConnection $connection + */ + public function __construct(IDBConnection $connection) { + $this->connection = $connection; + } + + /** + * @return string + */ + public function getName() { + return 'Fix permissions so avatars can be stored again'; + } + + /** + * @param IOutput $output + */ + public function run(IOutput $output) { + $output->startProgress(2); + $this->fixUserRootPermissions(); + $output->advance(); + $this->fixAvatarPermissions(); + $output->finishProgress(); + } + + /** + * Make sure all user roots have permissions 23 (all but share) + */ + protected function fixUserRootPermissions() { + $qb = $this->connection->getQueryBuilder(); + $qb2 = $this->connection->getQueryBuilder(); + + $qb->select('numeric_id') + ->from('storages') + ->where($qb->expr()->like('id', $qb2->createParameter('like'))); + + if ($this->connection->getDatabasePlatform() instanceof OraclePlatform) { + // '' is null on oracle + $path = $qb2->expr()->isNull('path'); + } else { + $path = $qb2->expr()->eq('path', $qb2->createNamedParameter('')); + } + + $qb2->update('filecache') + ->set('permissions', $qb2->createNamedParameter(23)) + ->where($path) + ->andWhere($qb2->expr()->in('storage', $qb2->createFunction($qb->getSQL()))) + ->andWhere($qb2->expr()->neq('permissions', $qb2->createNamedParameter(23))) + ->setParameter('like', 'home::%'); + + + $qb2->execute(); + } + + /** + * Make sure all avatar files in the user roots have permission 27 + */ + protected function fixAvatarPermissions() { + $qb = $this->connection->getQueryBuilder(); + $qb2 = $this->connection->getQueryBuilder(); + + $qb->select('numeric_id') + ->from('storages') + ->where($qb->expr()->like('id', $qb2->createParameter('like'))); + + $qb2->update('filecache') + ->set('permissions', $qb2->createNamedParameter(27)) + ->where($qb2->expr()->like('path', $qb2->createNamedParameter('avatar.%'))) + ->andWhere($qb2->expr()->in('storage', $qb2->createFunction($qb->getSQL()))) + ->andWhere($qb2->expr()->neq('permissions', $qb2->createNamedParameter(27))) + ->setParameter('like', 'home::%'); + + $qb2->execute(); + } + +} + diff --git a/lib/private/Repair/RemoveOldShares.php b/lib/private/Repair/RemoveOldShares.php new file mode 100644 index 00000000000..2c05d97b15c --- /dev/null +++ b/lib/private/Repair/RemoveOldShares.php @@ -0,0 +1,103 @@ +<?php +/** + * @author Roeland Jago Douma <rullzer@owncloud.com> + * + * @copyright Copyright (c) 2016, ownCloud, Inc. + * @license AGPL-3.0 + * + * This code is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License, version 3, + * as published by the Free Software Foundation. + * + * This program 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, version 3, + * along with this program. If not, see <http://www.gnu.org/licenses/> + * + */ +namespace OC\Repair; + +use OCP\IDBConnection; +use OCP\Migration\IOutput; +use OCP\Migration\IRepairStep; + +/** + * Class RemoveOldShares + * + * @package OC\Repair + */ +class RemoveOldShares implements IRepairStep { + + /** @var IDBConnection */ + protected $connection; + + /** + * RemoveOldCalendarShares constructor. + * + * @param IDBConnection $db + */ + public function __construct(IDBConnection $connection) { + $this->connection = $connection; + } + + /** + * @return string + */ + public function getName() { + return 'Remove old (< 9.0) calendar/contact shares'; + } + + /** + * @param IOutput $output + */ + public function run(IOutput $output) { + $output->startProgress(4); + + $this->removeCalendarShares($output); + $this->removeContactShares($output); + + $output->finishProgress(); + } + + /** + * @param IOutput $output + */ + private function removeCalendarShares(IOutput $output) { + $qb = $this->connection->getQueryBuilder(); + $qb->delete('share') + ->where($qb->expr()->eq('item_type', $qb->createNamedParameter('calendar'))); + $qb->execute(); + + $output->advance(); + + $qb = $this->connection->getQueryBuilder(); + $qb->delete('share') + ->where($qb->expr()->eq('item_type', $qb->createNamedParameter('event'))); + $qb->execute(); + + $output->advance(); + } + + /** + * @param IOutput $output + */ + private function removeContactShares(IOutput $output) { + $qb = $this->connection->getQueryBuilder(); + $qb->delete('share') + ->where($qb->expr()->eq('item_type', $qb->createNamedParameter('contact'))); + $qb->execute(); + + $output->advance(); + + $qb = $this->connection->getQueryBuilder(); + $qb->delete('share') + ->where($qb->expr()->eq('item_type', $qb->createNamedParameter('addressbook'))); + $qb->execute(); + + $output->advance(); + } +} + diff --git a/lib/private/legacy/json.php b/lib/private/legacy/json.php index d201d69723e..1dde63602b1 100644 --- a/lib/private/legacy/json.php +++ b/lib/private/legacy/json.php @@ -64,7 +64,9 @@ class OC_JSON{ * @deprecated Use annotation based ACLs from the AppFramework instead */ public static function checkLoggedIn() { - if( !OC_User::isLoggedIn()) { + $twoFactorAuthManger = \OC::$server->getTwoFactorAuthManager(); + if( !OC_User::isLoggedIn() + || $twoFactorAuthManger->needsSecondFactor()) { $l = \OC::$server->getL10N('lib'); http_response_code(\OCP\AppFramework\Http::STATUS_UNAUTHORIZED); self::error(array( 'data' => array( 'message' => $l->t('Authentication error'), 'error' => 'authentication_error' ))); diff --git a/lib/private/legacy/util.php b/lib/private/legacy/util.php index a863348566e..65d00c16388 100644 --- a/lib/private/legacy/util.php +++ b/lib/private/legacy/util.php @@ -970,6 +970,11 @@ class OC_Util { ); exit(); } + // Redirect to index page if 2FA challenge was not solved yet + if (\OC::$server->getTwoFactorAuthManager()->needsSecondFactor()) { + header('Location: ' . \OCP\Util::linkToAbsolute('', 'index.php')); + exit(); + } } /** diff --git a/lib/public/Files/Cache/IPropagator.php b/lib/public/Files/Cache/IPropagator.php index 5494ec9a54e..541135b9e60 100644 --- a/lib/public/Files/Cache/IPropagator.php +++ b/lib/public/Files/Cache/IPropagator.php @@ -28,6 +28,25 @@ namespace OCP\Files\Cache; */ interface IPropagator { /** + * Mark the beginning of a propagation batch + * + * Note that not all cache setups support propagation in which case this will be a noop + * + * Batching for cache setups that do support it has to be explicit since the cache state is not fully consistent + * before the batch is committed. + * + * @since 9.1.0 + */ + public function beginBatch(); + + /** + * Commit the active propagation batch + * + * @since 9.1.0 + */ + public function commitBatch(); + + /** * @param string $internalPath * @param int $time * @since 9.0.0 diff --git a/lib/public/Migration/IRepairStep.php b/lib/public/Migration/IRepairStep.php index 3394b70a6ff..84619128b4e 100644 --- a/lib/public/Migration/IRepairStep.php +++ b/lib/public/Migration/IRepairStep.php @@ -39,8 +39,9 @@ interface IRepairStep { * Run repair step. * Must throw exception on error. * - * @since 9.1.0 + * @param IOutput $output * @throws \Exception in case of failure + * @since 9.1.0 */ public function run(IOutput $output); |