From f56e58073ae447b0020f91ad0c673e8a0a107879 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20M=C3=BCller?= <1005065+DeepDiver1975@users.noreply.github.com> Date: Fri, 26 Nov 2021 14:43:41 +0100 Subject: [PATCH] fix: trashbin pre_restore hook and encryption version on move --- apps/files_trashbin/lib/Trashbin.php | 14 +++++++++++--- lib/private/Files/Storage/Wrapper/Encryption.php | 10 +++++++--- 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/apps/files_trashbin/lib/Trashbin.php b/apps/files_trashbin/lib/Trashbin.php index 74b581f7b64b..e4d7e67c248f 100644 --- a/apps/files_trashbin/lib/Trashbin.php +++ b/apps/files_trashbin/lib/Trashbin.php @@ -370,8 +370,10 @@ public static function move2trash($file_path) { if (!$result) { Util::writeLog('files_trashbin', 'trash bin database couldn\'t be updated', Util::ERROR); } - Util::emitHook('\OCA\Files_Trashbin\Trashbin', 'post_moveToTrash', ['filePath' => Filesystem::normalizePath($file_path), - 'trashPath' => Filesystem::normalizePath($filename . '.d' . $timestamp)]); + Util::emitHook('\OCA\Files_Trashbin\Trashbin', 'post_moveToTrash', [ + 'filePath' => Filesystem::normalizePath($file_path), + 'trashPath' => Filesystem::normalizePath($filename . '.d' . $timestamp) + ]); self::retainVersions($filename, $owner, $ownerPath, $timestamp, $sourceStorage); @@ -551,6 +553,12 @@ public static function restore($file, $filename, $timestamp, $targetLocation = n } $mtime = $view->filemtime($source); + Util::emitHook('\OCA\Files_Trashbin\Trashbin', 'pre_restore', [ + 'user' => $user, + 'source' => $source, + 'target' => $target + ]); + // restore file $restoreResult = $view->rename($source, $target); @@ -695,7 +703,7 @@ protected static function emitTrashbinPreDelete($uid, $path, $fileInfo) { * @throws HintException * @throws ServerNotAvailableException */ - protected static function emitTrashbinPostDelete($uid, $path, $fileInfo, $originalLocation) { + protected static function emitTrashbinPostDelete($uid, $path, $fileInfo, $originalLocation = null) { \OC_Hook::emit( '\OCP\Trashbin', 'delete', diff --git a/lib/private/Files/Storage/Wrapper/Encryption.php b/lib/private/Files/Storage/Wrapper/Encryption.php index e33c357562bd..057fb9aefb2c 100644 --- a/lib/private/Files/Storage/Wrapper/Encryption.php +++ b/lib/private/Files/Storage/Wrapper/Encryption.php @@ -479,11 +479,15 @@ public function fopen($path, $mode) { return false; } + $sourceFileOfRename = null; if (isset($this->sourcePath[$path])) { $sourceFileOfRename = $this->sourcePath[$path]; - } else { - $sourceFileOfRename = null; + $mount = $this->mountManager->find($sourceFileOfRename); + if ($mount) { + $data = $mount->getStorage()->getCache()->get($mount->getInternalPath($sourceFileOfRename)); + } } + $encryptedVersion = $data['encryptedVersion'] ?? null; $handle = \OC\Files\Stream\Encryption::wrap( $source, $path, @@ -501,7 +505,7 @@ public function fopen($path, $mode) { $headerSize, $signed, $sourceFileOfRename, - null # TODO: maybe fill it? + $encryptedVersion, ); unset($this->sourcePath[$path]);