Skip to content

Commit

Permalink
fix: trashbin pre_restore hook and encryption version on move
Browse files Browse the repository at this point in the history
  • Loading branch information
DeepDiver1975 committed Dec 15, 2021
1 parent 92ca08f commit f56e580
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 6 deletions.
14 changes: 11 additions & 3 deletions apps/files_trashbin/lib/Trashbin.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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',
Expand Down
10 changes: 7 additions & 3 deletions lib/private/Files/Storage/Wrapper/Encryption.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -501,7 +505,7 @@ public function fopen($path, $mode) {
$headerSize,
$signed,
$sourceFileOfRename,
null # TODO: maybe fill it?
$encryptedVersion,
);
unset($this->sourcePath[$path]);

Expand Down

0 comments on commit f56e580

Please sign in to comment.