diff options
author | Björn Schießle <bjoern@schiessle.org> | 2015-08-28 20:44:55 +0200 |
---|---|---|
committer | Björn Schießle <bjoern@schiessle.org> | 2015-08-28 20:44:55 +0200 |
commit | 6e210d960c23c3ab9bb28ba6b1fa3a77c8b951c8 (patch) | |
tree | 420049bcc149225465c4eabe03c09fb6d382bf35 /lib | |
parent | dc04b618bcd9ed795a81b7a88bc2a97725c629a8 (diff) | |
parent | e51fe617d89fd515e9e6836f205f67c613939b41 (diff) | |
download | nextcloud-server-6e210d960c23c3ab9bb28ba6b1fa3a77c8b951c8.tar.gz nextcloud-server-6e210d960c23c3ab9bb28ba6b1fa3a77c8b951c8.zip |
Merge pull request #18423 from owncloud/occ_encrypt_all
occ command line tool to encrypt all files
Diffstat (limited to 'lib')
-rw-r--r-- | lib/private/files/storage/wrapper/encryption.php | 44 | ||||
-rw-r--r-- | lib/public/encryption/iencryptionmodule.php | 12 |
2 files changed, 27 insertions, 29 deletions
diff --git a/lib/private/files/storage/wrapper/encryption.php b/lib/private/files/storage/wrapper/encryption.php index 4ba9b21ddb4..805a2bc1ad0 100644 --- a/lib/private/files/storage/wrapper/encryption.php +++ b/lib/private/files/storage/wrapper/encryption.php @@ -67,7 +67,6 @@ class Encryption extends Wrapper { /** @var IMountPoint */ private $mount; - /** @var IStorage */ private $keyStorage; @@ -300,33 +299,15 @@ class Encryption extends Wrapper { public function copy($path1, $path2) { $source = $this->getFullPath($path1); - $target = $this->getFullPath($path2); if ($this->util->isExcluded($source)) { return $this->storage->copy($path1, $path2); } - $result = $this->storage->copy($path1, $path2); - - if ($result && $this->encryptionManager->isEnabled()) { - $keysCopied = $this->copyKeys($source, $target); - - if ($keysCopied && - dirname($source) !== dirname($target) && - $this->util->isFile($target) - ) { - $this->update->update($target); - } - - $data = $this->getMetaData($path1); - - if (isset($data['encrypted'])) { - $this->getCache()->put($path2, ['encrypted' => $data['encrypted']]); - } - if (isset($data['size'])) { - $this->updateUnencryptedSize($target, $data['size']); - } - } + // need to stream copy file by file in case we copy between a encrypted + // and a unencrypted storage + $this->unlink($path2); + $result = $this->copyFromStorage($this, $path1, $path2); return $result; } @@ -511,12 +492,17 @@ class Encryption extends Wrapper { } } } else { - $source = $sourceStorage->fopen($sourceInternalPath, 'r'); - $target = $this->fopen($targetInternalPath, 'w'); - list(, $result) = \OC_Helper::streamCopy($source, $target); - fclose($source); - fclose($target); - + try { + $source = $sourceStorage->fopen($sourceInternalPath, 'r'); + $target = $this->fopen($targetInternalPath, 'w'); + list(, $result) = \OC_Helper::streamCopy($source, $target); + fclose($source); + fclose($target); + } catch (\Exception $e) { + fclose($source); + fclose($target); + throw $e; + } if($result) { if ($preserveMtime) { $this->touch($targetInternalPath, $sourceStorage->filemtime($sourceInternalPath)); diff --git a/lib/public/encryption/iencryptionmodule.php b/lib/public/encryption/iencryptionmodule.php index 183b322e714..a5cd7075691 100644 --- a/lib/public/encryption/iencryptionmodule.php +++ b/lib/public/encryption/iencryptionmodule.php @@ -23,6 +23,8 @@ */ namespace OCP\Encryption; +use Symfony\Component\Console\Input\InputInterface; +use Symfony\Component\Console\Output\OutputInterface; /** * Interface IEncryptionModule @@ -134,4 +136,14 @@ interface IEncryptionModule { */ public function isReadable($path, $uid); + /** + * Initial encryption of all files + * + * @param InputInterface $input + * @param OutputInterface $output write some status information to the terminal during encryption + * @return bool + * @since 8.2.0 + */ + public function encryptAll(InputInterface $input, OutputInterface $output); + } |