mirror of
https://github.com/nextcloud/server.git
synced 2026-06-09 00:32:29 -04:00
Merge pull request #14573 from owncloud/enc-migrate-disable-updater
Disable the cache updater when doing the encryption migration
This commit is contained in:
commit
e61aa3723e
4 changed files with 70 additions and 14 deletions
|
|
@ -1,5 +1,5 @@
|
|||
<?php
|
||||
/**
|
||||
/**
|
||||
* ownCloud
|
||||
*
|
||||
* @copyright (C) 2014 ownCloud, Inc.
|
||||
|
|
@ -35,6 +35,7 @@ class Migration {
|
|||
|
||||
public function __construct() {
|
||||
$this->view = new \OC\Files\View();
|
||||
$this->view->getUpdater()->disable();
|
||||
$this->public_share_key_id = Helper::getPublicShareKeyId();
|
||||
$this->recovery_key_id = Helper::getRecoveryKeyId();
|
||||
}
|
||||
|
|
@ -50,7 +51,7 @@ class Migration {
|
|||
$this->reorganizeFolderStructureForUser($user);
|
||||
}
|
||||
$offset += $limit;
|
||||
} while(count($users) >= $limit);
|
||||
} while (count($users) >= $limit);
|
||||
}
|
||||
|
||||
public function reorganizeSystemFolderStructure() {
|
||||
|
|
@ -74,6 +75,10 @@ class Migration {
|
|||
$this->view->deleteAll('/owncloud_private_key');
|
||||
$this->view->deleteAll('/files_encryption/share-keys');
|
||||
$this->view->deleteAll('/files_encryption/keyfiles');
|
||||
$storage = $this->view->getMount('')->getStorage();
|
||||
$storage->getScanner()->scan('files_encryption');
|
||||
$storage->getCache()->remove('owncloud_private_key');
|
||||
$storage->getCache()->remove('public-keys');
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -96,6 +101,7 @@ class Migration {
|
|||
}
|
||||
// delete old folders
|
||||
$this->deleteOldKeys($user);
|
||||
$this->view->getMount('/' . $user)->getStorage()->getScanner()->scan('files_encryption');
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -127,7 +133,7 @@ class Migration {
|
|||
while (($oldPublicKey = readdir($dh)) !== false) {
|
||||
if (!\OC\Files\Filesystem::isIgnoredDir($oldPublicKey)) {
|
||||
$newPublicKey = substr($oldPublicKey, 0, strlen($oldPublicKey) - strlen('.public.key')) . '.publicKey';
|
||||
$this->view->rename('public-keys/' . $oldPublicKey , 'files_encryption/public_keys/' . $newPublicKey);
|
||||
$this->view->rename('public-keys/' . $oldPublicKey, 'files_encryption/public_keys/' . $newPublicKey);
|
||||
}
|
||||
}
|
||||
closedir($dh);
|
||||
|
|
@ -141,7 +147,7 @@ class Migration {
|
|||
while (($oldPrivateKey = readdir($dh)) !== false) {
|
||||
if (!\OC\Files\Filesystem::isIgnoredDir($oldPrivateKey)) {
|
||||
$newPrivateKey = substr($oldPrivateKey, 0, strlen($oldPrivateKey) - strlen('.private.key')) . '.privateKey';
|
||||
$this->view->rename('owncloud_private_key/' . $oldPrivateKey , 'files_encryption/' . $newPrivateKey);
|
||||
$this->view->rename('owncloud_private_key/' . $oldPrivateKey, 'files_encryption/' . $newPrivateKey);
|
||||
}
|
||||
}
|
||||
closedir($dh);
|
||||
|
|
@ -149,10 +155,10 @@ class Migration {
|
|||
}
|
||||
|
||||
private function renameUsersPrivateKey($user) {
|
||||
$oldPrivateKey = $user . '/files_encryption/' . $user . '.private.key';
|
||||
$newPrivateKey = substr($oldPrivateKey, 0, strlen($oldPrivateKey) - strlen('.private.key')) . '.privateKey';
|
||||
$oldPrivateKey = $user . '/files_encryption/' . $user . '.private.key';
|
||||
$newPrivateKey = substr($oldPrivateKey, 0, strlen($oldPrivateKey) - strlen('.private.key')) . '.privateKey';
|
||||
|
||||
$this->view->rename($oldPrivateKey, $newPrivateKey);
|
||||
$this->view->rename($oldPrivateKey, $newPrivateKey);
|
||||
}
|
||||
|
||||
private function getFileName($file, $trash) {
|
||||
|
|
@ -186,7 +192,7 @@ class Migration {
|
|||
}
|
||||
|
||||
private function getFilePath($path, $user, $trash) {
|
||||
$offset = $trash ? strlen($user . '/files_trashbin/keyfiles') : strlen($user . '/files_encryption/keyfiles');
|
||||
$offset = $trash ? strlen($user . '/files_trashbin/keyfiles') : strlen($user . '/files_encryption/keyfiles');
|
||||
return substr($path, $offset);
|
||||
}
|
||||
|
||||
|
|
@ -215,7 +221,7 @@ class Migration {
|
|||
$extension = $this->getExtension($file, $trash);
|
||||
$targetDir = $this->getTargetDir($user, $filePath, $filename, $extension, $trash);
|
||||
$this->createPathForKeys($targetDir);
|
||||
$this->view->copy($path . '/' . $file, $targetDir . '/fileKey');
|
||||
$this->view->rename($path . '/' . $file, $targetDir . '/fileKey');
|
||||
$this->renameShareKeys($user, $filePath, $filename, $targetDir, $trash);
|
||||
}
|
||||
}
|
||||
|
|
@ -258,10 +264,10 @@ class Migration {
|
|||
if ($this->view->is_dir($oldShareKeyPath . '/' . $file)) {
|
||||
continue;
|
||||
} else {
|
||||
if (substr($file, 0, strlen($filename) +1) === $filename . '.') {
|
||||
if (substr($file, 0, strlen($filename) + 1) === $filename . '.') {
|
||||
|
||||
$uid = $this->getUidFromShareKey($file, $filename, $trash);
|
||||
$this->view->copy($oldShareKeyPath . '/' . $file, $target . '/' . $uid . '.shareKey');
|
||||
$this->view->rename($oldShareKeyPath . '/' . $file, $target . '/' . $uid . '.shareKey');
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
19
lib/private/files/cache/updater.php
vendored
19
lib/private/files/cache/updater.php
vendored
|
|
@ -12,6 +12,11 @@ namespace OC\Files\Cache;
|
|||
* Update the cache and propagate changes
|
||||
*/
|
||||
class Updater {
|
||||
/**
|
||||
* @var bool
|
||||
*/
|
||||
protected $enabled = true;
|
||||
|
||||
/**
|
||||
* @var \OC\Files\View
|
||||
*/
|
||||
|
|
@ -30,6 +35,14 @@ class Updater {
|
|||
$this->propagator = new ChangePropagator($view);
|
||||
}
|
||||
|
||||
public function disable() {
|
||||
$this->enabled = false;
|
||||
}
|
||||
|
||||
public function enable() {
|
||||
$this->enabled = true;
|
||||
}
|
||||
|
||||
public function propagate($path, $time = null) {
|
||||
if (Scanner::isPartialFile($path)) {
|
||||
return;
|
||||
|
|
@ -45,7 +58,7 @@ class Updater {
|
|||
* @param int $time
|
||||
*/
|
||||
public function update($path, $time = null) {
|
||||
if (Scanner::isPartialFile($path)) {
|
||||
if (!$this->enabled or Scanner::isPartialFile($path)) {
|
||||
return;
|
||||
}
|
||||
/**
|
||||
|
|
@ -70,7 +83,7 @@ class Updater {
|
|||
* @param string $path
|
||||
*/
|
||||
public function remove($path) {
|
||||
if (Scanner::isPartialFile($path)) {
|
||||
if (!$this->enabled or Scanner::isPartialFile($path)) {
|
||||
return;
|
||||
}
|
||||
/**
|
||||
|
|
@ -97,7 +110,7 @@ class Updater {
|
|||
* @param string $target
|
||||
*/
|
||||
public function rename($source, $target) {
|
||||
if (Scanner::isPartialFile($source) or Scanner::isPartialFile($target)) {
|
||||
if (!$this->enabled or Scanner::isPartialFile($source) or Scanner::isPartialFile($target)) {
|
||||
return;
|
||||
}
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -1528,4 +1528,11 @@ class View {
|
|||
$mount
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Updater
|
||||
*/
|
||||
public function getUpdater(){
|
||||
return $this->updater;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
30
tests/lib/files/cache/updater.php
vendored
30
tests/lib/files/cache/updater.php
vendored
|
|
@ -146,4 +146,34 @@ class Updater extends \Test\TestCase {
|
|||
$this->assertEquals($cached['size'], $cachedTarget['size']);
|
||||
$this->assertEquals($cached['fileid'], $cachedTarget['fileid']);
|
||||
}
|
||||
|
||||
public function testNewFileDisabled() {
|
||||
$this->storage->file_put_contents('foo.txt', 'bar');
|
||||
$this->assertFalse($this->cache->inCache('foo.txt'));
|
||||
|
||||
$this->updater->disable();
|
||||
$this->updater->update('/foo.txt');
|
||||
|
||||
$this->assertFalse($this->cache->inCache('foo.txt'));
|
||||
}
|
||||
|
||||
public function testMoveDisabled() {
|
||||
$this->storage->file_put_contents('foo.txt', 'qwerty');
|
||||
$this->updater->update('foo.txt');
|
||||
|
||||
$this->assertTrue($this->cache->inCache('foo.txt'));
|
||||
$this->assertFalse($this->cache->inCache('bar.txt'));
|
||||
$cached = $this->cache->get('foo.txt');
|
||||
|
||||
$this->storage->rename('foo.txt', 'bar.txt');
|
||||
|
||||
$this->assertTrue($this->cache->inCache('foo.txt'));
|
||||
$this->assertFalse($this->cache->inCache('bar.txt'));
|
||||
|
||||
$this->updater->disable();
|
||||
$this->updater->rename('foo.txt', 'bar.txt');
|
||||
|
||||
$this->assertTrue($this->cache->inCache('foo.txt'));
|
||||
$this->assertFalse($this->cache->inCache('bar.txt'));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue