From 2421404fd33bc65a71fba5893122910a19640b79 Mon Sep 17 00:00:00 2001 From: Simon Spannagel Date: Wed, 18 Jan 2023 15:45:55 +0100 Subject: [PATCH 1/7] Add repair step for unencrypted_size Signed-off-by: Simon Spannagel --- lib/private/Repair/RepairUnencryptedSize.php | 53 ++++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 lib/private/Repair/RepairUnencryptedSize.php diff --git a/lib/private/Repair/RepairUnencryptedSize.php b/lib/private/Repair/RepairUnencryptedSize.php new file mode 100644 index 0000000000000..cc14e6c86fbc2 --- /dev/null +++ b/lib/private/Repair/RepairUnencryptedSize.php @@ -0,0 +1,53 @@ + + * + * @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 + * + */ +namespace OC\Repair; + +use OCP\DB\QueryBuilder\IQueryBuilder; +use OCP\IDBConnection; +use OCP\Migration\IOutput; +use OCP\Migration\IRepairStep; + +class RepairUnencryptedSize implements IRepairStep { + /** @var IDBConnection */ + protected $connection; + + public function __construct(IDBConnection $connection) { + $this->connection = $connection; + } + + public function getName() { + return 'Repair file size of unencrypted files'; + } + + /** + * Fix unencrypted file size + */ + public function run(IOutput $out) { + + $update = $this->connection->getQueryBuilder(); + $update->update('filecache') + ->set('unencrypted_size', 0) + ->where($update->expr()->eq('encrypted',0, IQueryBuilder::PARAM_INT)); + + $count = $update->execute(); + } +} From c9b6d5e012b68d6d86d9b764a67380de3958d38d Mon Sep 17 00:00:00 2001 From: Simon Spannagel Date: Wed, 18 Jan 2023 15:46:31 +0100 Subject: [PATCH 2/7] Register new repair step Signed-off-by: Simon Spannagel --- lib/private/Repair.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib/private/Repair.php b/lib/private/Repair.php index 9ca3ece6dd493..30240dfb60b70 100644 --- a/lib/private/Repair.php +++ b/lib/private/Repair.php @@ -83,6 +83,7 @@ use OC\Repair\RepairDavShares; use OC\Repair\RepairInvalidShares; use OC\Repair\RepairMimeTypes; +use OC\Repair\RepairUnencryptedSize; use OC\Repair\SqliteAutoincrement; use OC\Template\JSCombiner; use Psr\Log\LoggerInterface; @@ -176,6 +177,7 @@ public static function getRepairSteps(): array { return [ new Collation(\OC::$server->getConfig(), \OC::$server->get(LoggerInterface::class), \OC::$server->getDatabaseConnection(), false), new RepairMimeTypes(\OC::$server->getConfig(), \OC::$server->getDatabaseConnection()), + new RepairUnencryptedSize(\OC::$server->getDatabaseConnection()), new CleanTags(\OC::$server->getDatabaseConnection(), \OC::$server->getUserManager()), new RepairInvalidShares(\OC::$server->getConfig(), \OC::$server->getDatabaseConnection()), new MoveUpdaterStepFile(\OC::$server->getConfig()), From 8a03a1d633a1269c825b47a81664403d8850a453 Mon Sep 17 00:00:00 2001 From: Simon Spannagel Date: Wed, 18 Jan 2023 16:01:44 +0100 Subject: [PATCH 3/7] Fix psalm complaints and add log Signed-off-by: Simon Spannagel --- lib/private/Repair/RepairUnencryptedSize.php | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/lib/private/Repair/RepairUnencryptedSize.php b/lib/private/Repair/RepairUnencryptedSize.php index cc14e6c86fbc2..5d7a44215df21 100644 --- a/lib/private/Repair/RepairUnencryptedSize.php +++ b/lib/private/Repair/RepairUnencryptedSize.php @@ -41,13 +41,15 @@ public function getName() { /** * Fix unencrypted file size */ - public function run(IOutput $out) { + public function run(IOutput $output) { $update = $this->connection->getQueryBuilder(); $update->update('filecache') - ->set('unencrypted_size', 0) - ->where($update->expr()->eq('encrypted',0, IQueryBuilder::PARAM_INT)); + ->set('unencrypted_size', "0") + ->where($update->expr()->eq('encrypted',"0", IQueryBuilder::PARAM_INT)); - $count = $update->execute(); + if ($update->execute()) { + $output->info('Fixed file size of unencrypted files'); + } } } From 768436c34da0f1dbf877199f7999bad95aad90f3 Mon Sep 17 00:00:00 2001 From: Simon Spannagel Date: Wed, 18 Jan 2023 16:04:14 +0100 Subject: [PATCH 4/7] Satisfy linter :) Signed-off-by: Simon Spannagel --- lib/private/Repair/RepairUnencryptedSize.php | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/lib/private/Repair/RepairUnencryptedSize.php b/lib/private/Repair/RepairUnencryptedSize.php index 5d7a44215df21..8dab4e00417da 100644 --- a/lib/private/Repair/RepairUnencryptedSize.php +++ b/lib/private/Repair/RepairUnencryptedSize.php @@ -38,18 +38,17 @@ public function getName() { return 'Repair file size of unencrypted files'; } - /** + /** * Fix unencrypted file size */ public function run(IOutput $output) { - - $update = $this->connection->getQueryBuilder(); + $update = $this->connection->getQueryBuilder(); $update->update('filecache') ->set('unencrypted_size', "0") - ->where($update->expr()->eq('encrypted',"0", IQueryBuilder::PARAM_INT)); + ->where($update->expr()->eq('encrypted', "0", IQueryBuilder::PARAM_INT)); - if ($update->execute()) { - $output->info('Fixed file size of unencrypted files'); - } + if ($update->execute()) { + $output->info('Fixed file size of unencrypted files'); + } } } From 6856c381dbe3ad2013681f1cc300938d04ee649b Mon Sep 17 00:00:00 2001 From: simonspa <1677436+simonspa@users.noreply.github.com> Date: Wed, 18 Jan 2023 16:33:13 +0100 Subject: [PATCH 5/7] Only touch problematic rows Co-authored-by: Anna Signed-off-by: simonspa <1677436+simonspa@users.noreply.github.com> --- lib/private/Repair/RepairUnencryptedSize.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/private/Repair/RepairUnencryptedSize.php b/lib/private/Repair/RepairUnencryptedSize.php index 8dab4e00417da..9eab9f96aff42 100644 --- a/lib/private/Repair/RepairUnencryptedSize.php +++ b/lib/private/Repair/RepairUnencryptedSize.php @@ -45,7 +45,8 @@ public function run(IOutput $output) { $update = $this->connection->getQueryBuilder(); $update->update('filecache') ->set('unencrypted_size', "0") - ->where($update->expr()->eq('encrypted', "0", IQueryBuilder::PARAM_INT)); + ->where($update->expr()->eq('encrypted', "0", IQueryBuilder::PARAM_INT) + ->andWhere($update->expr()->neq('unencrypted_size', "0", IQueryBuilder::PARAM_INT); if ($update->execute()) { $output->info('Fixed file size of unencrypted files'); From 112bbd2aa6e2a229c7ad17a71f32f607e2cc82fe Mon Sep 17 00:00:00 2001 From: Simon Spannagel Date: Wed, 18 Jan 2023 17:03:41 +0100 Subject: [PATCH 6/7] Fix query Signed-off-by: Simon Spannagel --- lib/private/Repair/RepairUnencryptedSize.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/private/Repair/RepairUnencryptedSize.php b/lib/private/Repair/RepairUnencryptedSize.php index 9eab9f96aff42..be91934821185 100644 --- a/lib/private/Repair/RepairUnencryptedSize.php +++ b/lib/private/Repair/RepairUnencryptedSize.php @@ -45,8 +45,8 @@ public function run(IOutput $output) { $update = $this->connection->getQueryBuilder(); $update->update('filecache') ->set('unencrypted_size', "0") - ->where($update->expr()->eq('encrypted', "0", IQueryBuilder::PARAM_INT) - ->andWhere($update->expr()->neq('unencrypted_size', "0", IQueryBuilder::PARAM_INT); + ->where($update->expr()->eq('encrypted', "0", IQueryBuilder::PARAM_INT)) + ->andWhere($update->expr()->neq('unencrypted_size', "0", IQueryBuilder::PARAM_INT)); if ($update->execute()) { $output->info('Fixed file size of unencrypted files'); From 43da5b0b2bb03fb3f89b8de00c0096556fef38d9 Mon Sep 17 00:00:00 2001 From: Simon Spannagel Date: Sun, 29 Jan 2023 15:14:19 +0100 Subject: [PATCH 7/7] RepairStep for unencrypted size: make DB query more efficient Signed-off-by: Simon Spannagel --- lib/private/Repair/RepairUnencryptedSize.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/private/Repair/RepairUnencryptedSize.php b/lib/private/Repair/RepairUnencryptedSize.php index be91934821185..08f4455a7d2d7 100644 --- a/lib/private/Repair/RepairUnencryptedSize.php +++ b/lib/private/Repair/RepairUnencryptedSize.php @@ -45,8 +45,8 @@ public function run(IOutput $output) { $update = $this->connection->getQueryBuilder(); $update->update('filecache') ->set('unencrypted_size', "0") - ->where($update->expr()->eq('encrypted', "0", IQueryBuilder::PARAM_INT)) - ->andWhere($update->expr()->neq('unencrypted_size', "0", IQueryBuilder::PARAM_INT)); + ->where($update->expr()->gt('unencrypted_size', "0", IQueryBuilder::PARAM_INT)) + ->andWhere($update->expr()->eq('encrypted', "0", IQueryBuilder::PARAM_INT)); if ($update->execute()) { $output->info('Fixed file size of unencrypted files');