-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
18 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
<?php | ||
/** | ||
* @author Sujith Haridasan <[email protected]> | ||
* @author Ilja Neumann <[email protected]> | ||
* | ||
* @copyright Copyright (c) 2019, ownCloud GmbH | ||
* @license AGPL-3.0 | ||
|
@@ -62,6 +63,12 @@ protected function configure() { | |
'p', | ||
InputArgument::OPTIONAL, | ||
'Limit files to fix with path, e.g., --path="/Music/Artist". If path indicates a directory, all the files inside directory will be fixed.' | ||
)->addOption( | ||
'increment-range', | ||
'i', | ||
InputArgument::OPTIONAL, | ||
'Try versions within a given upper bound', | ||
5 | ||
); | ||
} | ||
|
||
|
@@ -91,16 +98,17 @@ protected function execute(InputInterface $input, OutputInterface $output) { | |
$output->writeln("<error>User id $user does not exist. Please provide a valid user id</error>"); | ||
return 1; | ||
} | ||
return $this->walkPathOfUser($user, $pathToWalk, $output); | ||
return $this->walkPathOfUser($user, $pathToWalk, $output, $input->getOption('increment-range')); | ||
} | ||
|
||
/** | ||
* @param string $user | ||
* @param string $path | ||
* @param OutputInterface $output | ||
* @param $incrRange int Range of versions to try (upper/lower bound) | ||
* @return int 0 for success, 1 for error | ||
*/ | ||
private function walkPathOfUser($user, $path, OutputInterface $output) { | ||
private function walkPathOfUser($user, $path, OutputInterface $output, $incrRange) { | ||
$this->setupUserFs($user); | ||
if (!$this->view->file_exists($path)) { | ||
$output->writeln("<error>Path $path does not exist. Please provide a valid path.</error>"); | ||
|
@@ -109,7 +117,7 @@ private function walkPathOfUser($user, $path, OutputInterface $output) { | |
|
||
if ($this->view->is_file($path)) { | ||
$output->writeln("Verifying the content of file $path"); | ||
$this->verifyFileContent($path, $output); | ||
$this->verifyFileContent($path, $output, $incrRange); | ||
return 0; | ||
} | ||
$directories = []; | ||
|
@@ -122,7 +130,7 @@ private function walkPathOfUser($user, $path, OutputInterface $output) { | |
$directories[] = $path; | ||
} else { | ||
$output->writeln("Verifying the content of file $path"); | ||
$this->verifyFileContent($path, $output); | ||
$this->verifyFileContent($path, $output, $incrRange); | ||
} | ||
} | ||
} | ||
|
@@ -134,7 +142,7 @@ private function walkPathOfUser($user, $path, OutputInterface $output) { | |
* @param OutputInterface $output | ||
* @param bool $ignoreCorrectEncVersionCall, setting this variable to false avoids recursion | ||
*/ | ||
private function verifyFileContent($path, OutputInterface $output, $ignoreCorrectEncVersionCall = true) { | ||
private function verifyFileContent($path, OutputInterface $output, $incrRange, $ignoreCorrectEncVersionCall = true) { | ||
try { | ||
/** | ||
* In encryption, the files are read in a block size of 8192 bytes | ||
|
@@ -158,7 +166,7 @@ private function verifyFileContent($path, OutputInterface $output, $ignoreCorrec | |
if ($ignoreCorrectEncVersionCall === true) { | ||
//Lets rectify the file by correcting encrypted version | ||
$output->writeln("<info>Attempting to fix the path: $path</info>"); | ||
return $this->correctEncryptedVersion($path, $output); | ||
return $this->correctEncryptedVersion($path, $output, $incrRange); | ||
} | ||
return false; | ||
} | ||
|
@@ -169,7 +177,7 @@ private function verifyFileContent($path, OutputInterface $output, $ignoreCorrec | |
* @param OutputInterface $output | ||
* @return bool | ||
*/ | ||
private function correctEncryptedVersion($path, OutputInterface $output) { | ||
private function correctEncryptedVersion($path, OutputInterface $output, $incrRange) { | ||
$fileInfo = $this->view->getFileInfo($path); | ||
$fileId = $fileInfo->getId(); | ||
$encryptedVersion = $fileInfo->getEncryptedVersion(); | ||
|
@@ -192,7 +200,7 @@ private function correctEncryptedVersion($path, OutputInterface $output) { | |
$cacheInfo = ['encryptedVersion' => $encryptedVersion, 'encrypted' => $encryptedVersion]; | ||
$cache->put($fileCache->getPath(), $cacheInfo); | ||
$output->writeln("<info>Decrement the encrypted version to $encryptedVersion</info>"); | ||
if ($this->verifyFileContent($path, $output, false) === true) { | ||
if ($this->verifyFileContent($path, $output, $incrRange, false) === true) { | ||
$output->writeln("<info>Fixed the file: $path with version " . $encryptedVersion . "</info>"); | ||
return true; | ||
} | ||
|
@@ -201,7 +209,7 @@ private function correctEncryptedVersion($path, OutputInterface $output) { | |
|
||
//So decrementing did not work. Now lets increment. Max increment is till 5 | ||
$increment = 1; | ||
while ($increment <= 5) { | ||
while ($increment <= $incrRange) { | ||
/** | ||
* The wrongEncryptedVersion would not be incremented so nothing to worry about here. | ||
* Only the newEncryptedVersion is incremented. | ||
|
@@ -215,7 +223,7 @@ private function correctEncryptedVersion($path, OutputInterface $output) { | |
$cacheInfo = ['encryptedVersion' => $newEncryptedVersion, 'encrypted' => $newEncryptedVersion]; | ||
$cache->put($fileCache->getPath(), $cacheInfo); | ||
$output->writeln("<info>Increment the encrypted version to $newEncryptedVersion</info>"); | ||
if ($this->verifyFileContent($path, $output, false) === true) { | ||
if ($this->verifyFileContent($path, $output, $incrRange, false) === true) { | ||
$output->writeln("<info>Fixed the file: $path with version " . $newEncryptedVersion . "</info>"); | ||
return true; | ||
} | ||
|