diff options
author | Julius Härtl <jus@bitgrid.net> | 2021-03-11 11:32:29 +0100 |
---|---|---|
committer | backportbot[bot] <backportbot[bot]@users.noreply.github.com> | 2021-04-01 07:56:41 +0000 |
commit | d6bad03a5c4b33724297b1180f14be3db5549a51 (patch) | |
tree | df09627ccbc18916d693c20186bb06b27b514f0e /lib | |
parent | 052c9abfdfcb3262c2086bad9e49f9db0d7400da (diff) | |
download | nextcloud-server-d6bad03a5c4b33724297b1180f14be3db5549a51.tar.gz nextcloud-server-d6bad03a5c4b33724297b1180f14be3db5549a51.zip |
Log and continue when failing to update encryption keys during for individual files
Signed-off-by: Julius Härtl <jus@bitgrid.net>
Diffstat (limited to 'lib')
-rw-r--r-- | lib/private/Encryption/EncryptionWrapper.php | 2 | ||||
-rw-r--r-- | lib/private/Encryption/HookManager.php | 2 | ||||
-rw-r--r-- | lib/private/Encryption/Update.php | 34 |
3 files changed, 26 insertions, 12 deletions
diff --git a/lib/private/Encryption/EncryptionWrapper.php b/lib/private/Encryption/EncryptionWrapper.php index 0ae9c2c9357..596b90e7872 100644 --- a/lib/private/Encryption/EncryptionWrapper.php +++ b/lib/private/Encryption/EncryptionWrapper.php @@ -31,6 +31,7 @@ use OC\Memcache\ArrayCache; use OCP\Files\Mount\IMountPoint; use OCP\Files\Storage; use OCP\ILogger; +use Psr\Log\LoggerInterface; /** * Class EncryptionWrapper @@ -100,6 +101,7 @@ class EncryptionWrapper { Filesystem::getMountManager(), $this->manager, $fileHelper, + \OC::$server->get(LoggerInterface::class), $uid ); return new Encryption( diff --git a/lib/private/Encryption/HookManager.php b/lib/private/Encryption/HookManager.php index 8ddd506b691..16d45556b2f 100644 --- a/lib/private/Encryption/HookManager.php +++ b/lib/private/Encryption/HookManager.php @@ -25,6 +25,7 @@ namespace OC\Encryption; use OC\Files\Filesystem; use OC\Files\View; +use Psr\Log\LoggerInterface; class HookManager { /** @@ -67,6 +68,7 @@ class HookManager { Filesystem::getMountManager(), \OC::$server->getEncryptionManager(), \OC::$server->getEncryptionFilesHelper(), + \OC::$server->get(LoggerInterface::class), $uid ); } diff --git a/lib/private/Encryption/Update.php b/lib/private/Encryption/Update.php index beb76a223b7..f4e7f4d94be 100644 --- a/lib/private/Encryption/Update.php +++ b/lib/private/Encryption/Update.php @@ -26,40 +26,43 @@ namespace OC\Encryption; +use Exception; +use InvalidArgumentException; +use OC; use OC\Files\Filesystem; use OC\Files\Mount; use OC\Files\View; +use OCP\Encryption\Exceptions\GenericEncryptionException; +use OCP\ILogger; +use Psr\Log\LoggerInterface; /** * update encrypted files, e.g. because a file was shared */ class Update { - /** @var \OC\Files\View */ + /** @var View */ protected $view; - /** @var \OC\Encryption\Util */ + /** @var Util */ protected $util; /** @var \OC\Files\Mount\Manager */ protected $mountManager; - /** @var \OC\Encryption\Manager */ + /** @var Manager */ protected $encryptionManager; /** @var string */ protected $uid; - /** @var \OC\Encryption\File */ + /** @var File */ protected $file; + /** @var LoggerInterface */ + protected $logger; + /** - * - * @param \OC\Files\View $view - * @param \OC\Encryption\Util $util - * @param \OC\Files\Mount\Manager $mountManager - * @param \OC\Encryption\Manager $encryptionManager - * @param \OC\Encryption\File $file * @param string $uid */ public function __construct( @@ -68,6 +71,7 @@ class Update { Mount\Manager $mountManager, Manager $encryptionManager, File $file, + LoggerInterface $logger, $uid ) { $this->view = $view; @@ -75,6 +79,7 @@ class Update { $this->mountManager = $mountManager; $this->encryptionManager = $encryptionManager; $this->file = $file; + $this->logger = $logger; $this->uid = $uid; } @@ -155,7 +160,7 @@ class Update { $view = new View('/' . $owner . '/files'); $path = $view->getPath($info->getId()); if ($path === null) { - throw new \InvalidArgumentException('No file found for ' . $info->getId()); + throw new InvalidArgumentException('No file found for ' . $info->getId()); } return [$owner, $path]; @@ -187,7 +192,12 @@ class Update { foreach ($allFiles as $file) { $usersSharing = $this->file->getAccessList($file); - $encryptionModule->update($file, $this->uid, $usersSharing); + try { + $encryptionModule->update($file, $this->uid, $usersSharing); + } catch (GenericEncryptionException $e) { + // If the update of an individual file fails e.g. due to a corrupt key we should continue the operation and just log the failure + $this->logger->error('Failed to update encryption module for ' . $this->uid . ' ' . $file, [ 'exception' => $e ]); + } } } } |