From 0d5c7a11e287f44ad556d29b952c57c9ec11dfaa Mon Sep 17 00:00:00 2001 From: Bjoern Schiessle Date: Mon, 11 May 2015 10:35:42 +0200 Subject: use hooks to update encryption keys instead of the storage wrapper if a file gets renamed/restored, as long as we are in the storage wrapper the file cache isn't up-to-date --- lib/private/encryption/hookmanager.php | 8 ++++++ lib/private/encryption/update.php | 34 +++++++++++++++++++++++- lib/private/files/storage/wrapper/encryption.php | 8 +----- 3 files changed, 42 insertions(+), 8 deletions(-) (limited to 'lib/private') diff --git a/lib/private/encryption/hookmanager.php b/lib/private/encryption/hookmanager.php index c62583b4b47..31ecb2fbcf6 100644 --- a/lib/private/encryption/hookmanager.php +++ b/lib/private/encryption/hookmanager.php @@ -37,6 +37,14 @@ class HookManager { self::getUpdate()->postUnshared($params); } + public static function postRename($params) { + self::getUpdate()->postRename($params); + } + + public static function postRestore($params) { + self::getUpdate()->postRestore($params); + } + /** * @return Update */ diff --git a/lib/private/encryption/update.php b/lib/private/encryption/update.php index ddcee3bae93..02579fd9136 100644 --- a/lib/private/encryption/update.php +++ b/lib/private/encryption/update.php @@ -107,6 +107,38 @@ class Update { } } + /** + * inform encryption module that a file was restored from the trash bin, + * e.g. to update the encryption keys + * + * @param array $params + */ + public function postRestore($params) { + if ($this->encryptionManager->isEnabled()) { + $path = Filesystem::normalizePath('/' . $this->uid . '/files/' . $params['filePath']); + $this->update($path); + } + } + + /** + * inform encryption module that a file was renamed, + * e.g. to update the encryption keys + * + * @param array $params + */ + public function postRename($params) { + $source = $params['oldpath']; + $target = $params['newpath']; + if( + $this->encryptionManager->isEnabled() && + dirname($source) !== dirname($target) + ) { + list($owner, $ownerPath) = $this->getOwnerPath($target); + $absPath = '/' . $owner . '/files/' . $ownerPath; + $this->update($absPath); + } + } + /** * get owner and path relative to data//files * @@ -114,7 +146,7 @@ class Update { * @return array ['owner' => $owner, 'path' => $path] * @throw \InvalidArgumentException */ - private function getOwnerPath($path) { + protected function getOwnerPath($path) { $info = Filesystem::getFileInfo($path); $owner = Filesystem::getOwner($path); $view = new View('/' . $owner . '/files'); diff --git a/lib/private/files/storage/wrapper/encryption.php b/lib/private/files/storage/wrapper/encryption.php index c0c4c6979c2..c42e6d439fd 100644 --- a/lib/private/files/storage/wrapper/encryption.php +++ b/lib/private/files/storage/wrapper/encryption.php @@ -231,13 +231,7 @@ class Encryption extends Wrapper { if (isset($this->unencryptedSize[$source])) { $this->unencryptedSize[$target] = $this->unencryptedSize[$source]; } - $keysRenamed = $this->keyStorage->renameKeys($source, $target); - if ($keysRenamed && - dirname($source) !== dirname($target) && - $this->util->isFile($target) - ) { - $this->update->update($target); - } + $this->keyStorage->renameKeys($source, $target); } } -- cgit v1.2.3