Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[stable10] Fix error logs due to deletion of keys #28934

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions apps/files_trashbin/lib/Storage.php
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,28 @@ private function doDelete($path, $method) {
return $result;
}

/**
* Retain the encryption keys
*
* @param $filename
* @param $owner
* @param $ownerPath
* @param $timestamp
* @param $sourceStorage
* @return bool
*/

public function retainKeys($filename, $owner, $ownerPath, $timestamp, $sourceStorage) {
if (\OC::$server->getEncryptionManager()->isEnabled()) {
if ($sourceStorage !== null) {
$sourcePath = '/' . $owner . '/files_trashbin/files/'. $filename . '.d' . $timestamp;
$targetPath = '/' . $owner . '/files/' . $ownerPath;
return $sourceStorage->copyKeys($sourcePath, $targetPath);
}
}
return false;
}

/**
* Setup the storate wrapper callback
*/
Expand Down
20 changes: 17 additions & 3 deletions apps/files_trashbin/lib/Trashbin.php
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ public static function copyBackupForOwner($ownerPath, $owner, $timestamp) {
$view = new View('/');
self::copy_recursive($source, $target, $view);

self::retainVersions($targetFilename, $owner, $ownerPath, $timestamp, true);
self::retainVersions($targetFilename, $owner, $ownerPath, $timestamp, null, true);

if ($view->file_exists($target)) {
self::insertTrashEntry($owner, $targetFilename, $targetLocation, $timestamp);
Expand Down Expand Up @@ -304,7 +304,7 @@ public static function move2trash($file_path) {
\OCP\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);
self::retainVersions($filename, $owner, $ownerPath, $timestamp, $sourceStorage);

// if owner !== user we need to also add a copy to the owners trash
if ($user !== $owner) {
Expand All @@ -331,9 +331,19 @@ public static function move2trash($file_path) {
* @param integer $timestamp when the file was deleted
* @param bool $forceCopy true to only make a copy of the versions into the trashbin
*/
private static function retainVersions($filename, $owner, $ownerPath, $timestamp, $forceCopy = false) {
private static function retainVersions($filename, $owner, $ownerPath, $timestamp, $sourceStorage = null, $forceCopy = false) {
if (\OCP\App::isEnabled('files_versions') && !empty($ownerPath)) {

$copyKeysResult = false;

/**
* In case if encryption is enabled then we need to retain the keys which were
* deleted due to move operation to trashbin.
*/
if ($sourceStorage !== null) {
$copyKeysResult = $sourceStorage->retainKeys($filename, $owner, $ownerPath, $timestamp, $sourceStorage);
}

$user = User::getUser();
$rootView = new View('/');

Expand All @@ -355,6 +365,10 @@ private static function retainVersions($filename, $owner, $ownerPath, $timestamp
}
}
}

if ($copyKeysResult === true) {
$sourceStorage->deleteAllFileKeys($filename);
}
}
}

Expand Down
12 changes: 12 additions & 0 deletions lib/private/Files/Storage/Wrapper/Encryption.php
Original file line number Diff line number Diff line change
Expand Up @@ -1028,6 +1028,18 @@ protected function copyKeys($source, $target) {
return false;
}

/**
*
* delete file keys of the file
*
* @param $path path of the file key to delete
* @return bool
*/
protected function deleteAllFileKeys($path) {
$fullPath = $this->getFullPath($path);
return $this->keyStorage->deleteAllFileKeys($fullPath);
}

/**
* check if path points to a files version
*
Expand Down