Skip to content

Commit

Permalink
Fix the regression caused due to usage of part file in decrypt-all
Browse files Browse the repository at this point in the history
command

Fix the regression cuased due to the usage of part file in
decryptall command. An exception was thrown in the log
file during the rename operation.

Signed-off-by: Sujith H <sharidasan@owncloud.com>
  • Loading branch information
sharidas committed Aug 27, 2018
1 parent f5f18e8 commit 370f0a6
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 1 deletion.
2 changes: 2 additions & 0 deletions lib/private/Encryption/DecryptAll.php
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,9 @@ protected function decryptFile($path) {
\OC\Files\Storage\Wrapper\Encryption::setDisableWriteEncryption(true);
$this->rootView->copy($source, $target);
\OC\Files\Storage\Wrapper\Encryption::setDisableWriteEncryption(false);
View::setIgnorePartFile(true);
$this->rootView->rename($target, $source);
View::setIgnorePartFile(false);
list($storage, $internalPath) = $this->rootView->resolvePath($source);
//Update the encrypted column in file cache to zero, as the file is decrypted
$storage->getCache()->put($internalPath, ['encrypted' => 0]);
Expand Down
16 changes: 15 additions & 1 deletion lib/private/Files/View.php
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,8 @@ class View {

private $eventDispatcher;

private static $ignorePartFile = false;

/**
* @param string $root
* @throws \Exception If $root contains an invalid path
Expand Down Expand Up @@ -837,7 +839,7 @@ public function rename($path1, $path2) {
$result = $storage2->moveFromStorage($storage1, $internalPath1, $internalPath2);
}

if ((Cache\Scanner::isPartialFile($path1) && !Cache\Scanner::isPartialFile($path2)) && $result !== false) {
if ((Cache\Scanner::isPartialFile($path1) && !Cache\Scanner::isPartialFile($path2)) && $result !== false && (self::$ignorePartFile === false)) {
// if it was a rename from a part file to a regular file it was a write and not a rename operation

$this->writeUpdate($storage2, $internalPath2);
Expand Down Expand Up @@ -2192,4 +2194,16 @@ private function createParentDirectories($filePath) {
$this->mkdir($filePath);
return true;
}

/**
* User can create part files example to a call for rename(), in effect
* it might not be a part file. So for better control in such cases this
* method would help to let the method in rename() to know if it is a
* part file.
*
* @param bool $isIgnored
*/
public static function setIgnorePartFile($isIgnored) {
self::$ignorePartFile = $isIgnored;
}
}
2 changes: 2 additions & 0 deletions tests/lib/Files/ViewTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1297,7 +1297,9 @@ public function testRenameOverWrite() {
$scanner->scan('');
Filesystem::mount($storage, [], '/test/');
$view = new View('');
\OC::$server->getConfig()->setAppValue('core', 'ignorepartfile', 'true');
$this->assertTrue($view->rename('/test/foo.txt', '/test/foo/bar.txt'));
\OC::$server->getConfig()->deleteAppValue('core', 'ignorepartfile');
}

public function testSetMountOptionsInStorage() {
Expand Down

0 comments on commit 370f0a6

Please sign in to comment.