Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Make filecache repair step work with oc9
  • Loading branch information
tomneedham committed Nov 6, 2017
commit c2ef84ef85d31928bef8b15f7e5885296a065223
5 changes: 4 additions & 1 deletion apps/files/appinfo/register_command.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,11 @@
$userManager = OC::$server->getUserManager();
$shareManager = \OC::$server->getShareManager();
$mountManager = \OC::$server->getMountManager();
$lockingProvider = \OC::$server->getLockingProvider();
$mimeTypeLoader = \OC::$server->getMimeTypeLoader();
$config = \OC::$server->getConfig();

/** @var Symfony\Component\Console\Application $application */
$application->add(new OCA\Files\Command\Scan($userManager));
$application->add(new OCA\Files\Command\Scan($userManager, $lockingProvider, $mimeTypeLoader, $config));
$application->add(new OCA\Files\Command\DeleteOrphanedFiles($dbConnection));
$application->add(new OCA\Files\Command\TransferOwnership($userManager, $shareManager, $mountManager));
3 changes: 1 addition & 2 deletions apps/files/command/scan.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Helper\Table;
use OC\Repair\RepairMismatchFileCachePath;
use OC\Migration\ConsoleOutput;
use OCP\Lock\ILockingProvider;
use OCP\Lock\LockedException;
use OCP\Files\IMimeTypeLoader;
Expand Down Expand Up @@ -154,7 +153,7 @@ protected function scanFiles($user, $path, $verbose, OutputInterface $output, $s
);
$repairStep->setStorageNumericId($storage->getCache()->getNumericStorageId());
$repairStep->setCountOnly(false);
$repairStep->run(new ConsoleOutput($output));
$repairStep->run();
} finally {
$storage->releaseLock('', ILockingProvider::LOCK_EXCLUSIVE, $this->lockingProvider);
}
Expand Down
51 changes: 34 additions & 17 deletions lib/private/Repair/RepairMismatchFileCachePath.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,9 @@

namespace OC\Repair;

use Doctrine\DBAL\Platforms\PostgreSqlPlatform;
use OCP\DB\QueryBuilder\IQueryBuilder;
use OC\Hooks\BasicEmitter;
use OCP\ILogger;
use OCP\Migration\IOutput;
use OCP\Migration\IRepairStep;
use Doctrine\DBAL\Platforms\MySqlPlatform;
use Doctrine\DBAL\Platforms\OraclePlatform;
use OCP\Files\IMimeTypeLoader;
Expand All @@ -33,7 +32,7 @@
/**
* Repairs file cache entry which path do not match the parent-child relationship
*/
class RepairMismatchFileCachePath implements IRepairStep {
class RepairMismatchFileCachePath extends BasicEmitter implements \OC\RepairStep {

const CHUNK_SIZE = 10000;

Expand Down Expand Up @@ -92,14 +91,14 @@ public function setCountOnly($countOnly) {
/**
* Fixes the broken entry's path.
*
* @param IOutput $out repair output
* @param LogOutput $out repair output
* @param int $fileId file id of the entry to fix
* @param string $wrongPath wrong path of the entry to fix
* @param int $correctStorageNumericId numeric idea of the correct storage
* @param string $correctPath value to which to set the path of the entry
* @return bool true for success
*/
private function fixEntryPath(IOutput $out, $fileId, $wrongPath, $correctStorageNumericId, $correctPath) {
private function fixEntryPath(LogOutput $out, $fileId, $wrongPath, $correctStorageNumericId, $correctPath) {
// delete target if exists
$qb = $this->connection->getQueryBuilder();
$qb->delete('filecache')
Expand Down Expand Up @@ -214,7 +213,7 @@ private function countResultsToProcessNonExistingParentIdEntry($storageNumericId
/**
* Outputs a report about storages with wrong path that need repairing in the file cache
*/
private function reportAffectedStoragesParentIdWrongPath(IOutput $out) {
private function reportAffectedStoragesParentIdWrongPath(LogOutput $out) {
$qb = $this->connection->getQueryBuilder();
$qb->selectDistinct('fc.storage');
$this->addQueryConditionsParentIdWrongPath($qb);
Expand Down Expand Up @@ -242,7 +241,7 @@ private function reportAffectedStoragesParentIdWrongPath(IOutput $out) {
/**
* Outputs a report about storages with non existing parents that need repairing in the file cache
*/
private function reportAffectedStoragesNonExistingParentIdEntry(IOutput $out) {
private function reportAffectedStoragesNonExistingParentIdEntry(LogOutput $out) {
$qb = $this->connection->getQueryBuilder();
$qb->selectDistinct('fc.storage');
$this->addQueryConditionsNonExistingParentIdEntry($qb);
Expand All @@ -269,11 +268,11 @@ private function reportAffectedStoragesNonExistingParentIdEntry(IOutput $out) {
* Repair all entries for which the parent entry exists but the path
* value doesn't match the parent's path.
*
* @param IOutput $out
* @param LogOutput $out
* @param int|null $storageNumericId storage to fix or null for all
* @return int[] storage numeric ids that were targets to a move and needs further fixing
*/
private function fixEntriesWithCorrectParentIdButWrongPath(IOutput $out, $storageNumericId = null) {
private function fixEntriesWithCorrectParentIdButWrongPath(LogOutput $out, $storageNumericId = null) {
$totalResultsCount = 0;
$affectedStorages = [$storageNumericId => true];

Expand Down Expand Up @@ -413,7 +412,7 @@ private function getOrCreateEntry($storageId, $path, $reuseFileId = null) {
/**
* Fixes the broken entry's path.
*
* @param IOutput $out repair output
* @param LogOutput $out repair output
* @param int $storageId storage id of the entry to fix
* @param int $fileId file id of the entry to fix
* @param string $path path from the entry to fix
Expand All @@ -422,7 +421,7 @@ private function getOrCreateEntry($storageId, $path, $reuseFileId = null) {
* false if it doesn't
* @return bool true if the entry was fixed, false otherwise
*/
private function fixEntryParent(IOutput $out, $storageId, $fileId, $path, $wrongParentId, $parentIdExists = false) {
private function fixEntryParent(LogOutput $out, $storageId, $fileId, $path, $wrongParentId, $parentIdExists = false) {
if (!$parentIdExists) {
// if the parent doesn't exist, let us reuse its id in case there is metadata to salvage
$correctParentId = $this->getOrCreateEntry($storageId, dirname($path), $wrongParentId);
Expand Down Expand Up @@ -451,11 +450,11 @@ private function fixEntryParent(IOutput $out, $storageId, $fileId, $path, $wrong
* Repair entries where the parent id doesn't point to any existing entry
* by finding the actual parent entry matching the entry's path dirname.
*
* @param IOutput $out output
* @param LogOutput $out output
* @param int|null $storageNumericId storage to fix or null for all
* @return int number of results that were fixed
*/
private function fixEntriesWithNonExistingParentIdEntry(IOutput $out, $storageNumericId = null) {
private function fixEntriesWithNonExistingParentIdEntry(LogOutput $out, $storageNumericId = null) {
$qb = $this->connection->getQueryBuilder();
$this->addQueryConditionsNonExistingParentIdEntry($qb, $storageNumericId);
$qb->setMaxResults(self::CHUNK_SIZE);
Expand Down Expand Up @@ -498,10 +497,10 @@ private function fixEntriesWithNonExistingParentIdEntry(IOutput $out, $storageNu

/**
* Run the repair step
*
* @param IOutput $out output
*/
public function run(IOutput $out) {
public function run() {

$out = new LogOutput(\OC::$server->getLogger());

$this->dirMimeTypeId = $this->mimeLoader->getId('httpd/unix-directory');
$this->dirMimePartId = $this->mimeLoader->getId('httpd');
Expand Down Expand Up @@ -537,3 +536,21 @@ public function run(IOutput $out) {
}
}
}

class LogOutput {
/**
* @var ILogger
*/
protected $logger;
public function __construct(ILogger $logger) {
$this->logger = $logger;
}
public function info($message) {
$this->logger->info($message);
}
public function finishProgress() {}
public function startProgress() {}
public function warning($message) {
$this->logger->warning($message);
}
}