From ccbefb6e7506f5ad7cc23c9ae50971f8ea18b463 Mon Sep 17 00:00:00 2001 From: Bjoern Schiessle Date: Wed, 13 May 2015 14:39:27 +0200 Subject: [PATCH] delete all file keys doesn't need the encryption module as parameter; implement rmdir; getFileKeyDir should also work for part files and complete directories --- apps/encryption/lib/keymanager.php | 2 +- lib/private/encryption/keys/storage.php | 14 +++------- .../files/storage/wrapper/encryption.php | 27 ++++++++++++++++--- lib/public/encryption/keys/istorage.php | 3 +-- 4 files changed, 28 insertions(+), 18 deletions(-) diff --git a/apps/encryption/lib/keymanager.php b/apps/encryption/lib/keymanager.php index aa9614812b..05d2387348 100644 --- a/apps/encryption/lib/keymanager.php +++ b/apps/encryption/lib/keymanager.php @@ -483,7 +483,7 @@ class KeyManager { } public function deleteAllFileKeys($path) { - return $this->keyStorage->deleteAllFileKeys($path, Encryption::ID); + return $this->keyStorage->deleteAllFileKeys($path); } /** diff --git a/lib/private/encryption/keys/storage.php b/lib/private/encryption/keys/storage.php index 118c8dc920..6aa00c5b5e 100644 --- a/lib/private/encryption/keys/storage.php +++ b/lib/private/encryption/keys/storage.php @@ -125,10 +125,9 @@ class Storage implements IStorage { /** * @inheritdoc */ - public function deleteAllFileKeys($path, $encryptionModuleId) { - $keyDir = $this->getFileKeyDir($encryptionModuleId, $path); - $path = dirname($keyDir); - return !$this->view->file_exists($path) || $this->view->deleteAll($path); + public function deleteAllFileKeys($path) { + $keyDir = $this->getFileKeyDir('', $path); + return !$this->view->file_exists($keyDir) || $this->view->deleteAll($keyDir); } /** @@ -208,17 +207,10 @@ class Storage implements IStorage { * @param string $encryptionModuleId * @param string $path path to the file, relative to data/ * @return string - * @throws GenericEncryptionException - * @internal param string $keyId */ private function getFileKeyDir($encryptionModuleId, $path) { - if ($this->view->is_dir($path)) { - throw new GenericEncryptionException("file was expected but directory was given: $path"); - } - list($owner, $filename) = $this->util->getUidAndFilename($path); - $filename = $this->util->stripPartialFileExtension($filename); // in case of system wide mount points the keys are stored directly in the data directory if ($this->util->isSystemWideMountPoint($filename, $owner)) { diff --git a/lib/private/files/storage/wrapper/encryption.php b/lib/private/files/storage/wrapper/encryption.php index c42e6d439f..f7759d9149 100644 --- a/lib/private/files/storage/wrapper/encryption.php +++ b/lib/private/files/storage/wrapper/encryption.php @@ -206,8 +206,7 @@ class Encryption extends Wrapper { $encryptionModule = $this->getEncryptionModule($path); if ($encryptionModule) { - $this->keyStorage->deleteAllFileKeys($this->getFullPath($path), - $encryptionModule->getId()); + $this->keyStorage->deleteAllFileKeys($this->getFullPath($path)); } return $this->storage->unlink($path); @@ -238,6 +237,21 @@ class Encryption extends Wrapper { return $result; } + /** + * see http://php.net/manual/en/function.rmdir.php + * + * @param string $path + * @return bool + */ + public function rmdir($path) { + $result = $this->storage->rmdir($path); + if ($result && $this->encryptionManager->isEnabled()) { + $this->keyStorage->deleteAllFileKeys($this->getFullPath($path)); + } + + return $result; + } + /** * see http://php.net/manual/en/function.copy.php * @@ -269,8 +283,13 @@ class Encryption extends Wrapper { } } $data = $this->getMetaData($path1); - $this->getCache()->put($path2, ['encrypted' => $data['encrypted']]); - $this->updateUnencryptedSize($fullPath2, $data['size']); + + if (isset($data['encrypted'])) { + $this->getCache()->put($path2, ['encrypted' => $data['encrypted']]); + } + if (isset($data['size'])) { + $this->updateUnencryptedSize($fullPath2, $data['size']); + } } return $result; diff --git a/lib/public/encryption/keys/istorage.php b/lib/public/encryption/keys/istorage.php index 752c073375..1767781410 100644 --- a/lib/public/encryption/keys/istorage.php +++ b/lib/public/encryption/keys/istorage.php @@ -129,12 +129,11 @@ interface IStorage { * delete all file keys for a given file * * @param string $path to the file - * @param string $encryptionModuleId * * @return boolean False when the keys could not be deleted * @since 8.1.0 */ - public function deleteAllFileKeys($path, $encryptionModuleId); + public function deleteAllFileKeys($path); /** * delete system-wide encryption keys not related to a specific user,