Skip to content
Open
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
11 changes: 11 additions & 0 deletions apps/files_versions/lib/Storage.php
Original file line number Diff line number Diff line change
Expand Up @@ -374,6 +374,17 @@
$version = 'files_versions' . $filename . '.v' . $users_view->filemtime('files' . $filename);
if (!$users_view->file_exists($version)) {
$users_view->copy('files' . $filename, 'files_versions' . $filename . '.v' . $users_view->filemtime('files' . $filename));

$encryptedVersion = $fileInfo->getEncryptedVersion();
$versionFileInfo = $users_view->getFileInfo($version);
$versionCache = $versionFileInfo->getStorage()->getCache();
$versionCache->update(
$versionFileInfo->getId(), [
'encrypted' => $encryptedVersion,
'encryptedVersion' => $encryptedVersion,

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

encrypted should probably not get set or at least not to the version?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When I tested it, just setting encryptedVersion "corrupts" the version but also setting encrypted fixes the issue.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess we already do some of this below too, but I feel like we should be letting the Encryption storage wrapper deal with these matters -- e.g.

private function copyBetweenStorage(
Storage\IStorage $sourceStorage,
string $sourceInternalPath,
string $targetInternalPath,
bool $preserveMtime,
bool $isRename,
): bool {
// for versions we have nothing to do, because versions should always use the
// key from the original file. Just create a 1:1 copy and done
if ($this->isVersion($targetInternalPath)
|| $this->isVersion($sourceInternalPath)) {

]
);

$versionCreated = true;
}

Expand All @@ -382,7 +393,7 @@
// Restore encrypted version of the old file for the newly restored file
// This has to happen manually here since the file is manually copied below
$oldVersion = $users_view->getFileInfo($fileToRestore)->getEncryptedVersion();
$oldFileInfo = $users_view->getFileInfo($fileToRestore);

Check failure on line 396 in apps/files_versions/lib/Storage.php

View workflow job for this annotation

GitHub Actions / static-code-analysis

InternalMethod

apps/files_versions/lib/Storage.php:396:31: InternalMethod: The method OC\Files\View::getFileInfo is internal to OC but called from OCA\Files_Versions\Storage::rollback (see https://psalm.dev/175)
$cache = $fileInfo->getStorage()->getCache();
$cache->update(
$fileInfo->getId(), [
Expand Down
Loading