summaryrefslogtreecommitdiffstats
path: root/apps/files_versions
diff options
context:
space:
mode:
authorLukas Reschke <lukas@owncloud.com>2016-03-02 20:37:13 +0100
committerLukas Reschke <lukas@owncloud.com>2016-03-03 14:15:36 +0100
commit72c8187cbb24b460edf7d1c5c2cbfaee12c22fd6 (patch)
tree1b0787304c35c36afde7d7cc48992f948eeed025 /apps/files_versions
parent4f25f341788b3edad1bf4baf739cd632785c9abb (diff)
downloadnextcloud-server-72c8187cbb24b460edf7d1c5c2cbfaee12c22fd6.tar.gz
nextcloud-server-72c8187cbb24b460edf7d1c5c2cbfaee12c22fd6.zip
Keep "encryptedVersion" when calling `\OC\Files\View::copy`
When calling `\OC\Files\View::copy` we should also keep the version to ensure that the file will always have the correct version attached and can be successfully decrypted. To test this the following steps are necessary (from https://github.com/owncloud/core/issues/22781#issuecomment-191328982): 1. setup a new ownCloud 9.0 beta2 2. enable encryption 2. upload a docx (5.7MB large) 3. upload the same file again and overwrite the existing file 4. I can download the original file and the first version 5. I restore the first version 6. restored version can no longer be downloaded with the error described above The manual cache operation in `\OCA\Files_Versions\Storage` is unfortunately necessary since `\OCA\Files_Versions\Storage::copyFileContents` is not using `\OCP\Files\Storage::moveFromStorage` in the case when an object storage is used. Due to the workaround added in https://github.com/owncloud/core/commit/54cea05271b887f1c8062c034741df869bc0f055 the stream is directly copied and thus bypassing the FS.
Diffstat (limited to 'apps/files_versions')
-rw-r--r--apps/files_versions/lib/storage.php22
1 files changed, 12 insertions, 10 deletions
diff --git a/apps/files_versions/lib/storage.php b/apps/files_versions/lib/storage.php
index b4111d88e30..a213ea75238 100644
--- a/apps/files_versions/lib/storage.php
+++ b/apps/files_versions/lib/storage.php
@@ -191,12 +191,7 @@ class Storage {
$mtime = $users_view->filemtime('files/' . $filename);
$users_view->copy('files/' . $filename, 'files_versions/' . $filename . '.v' . $mtime);
// call getFileInfo to enforce a file cache entry for the new version
- $newFileInfo = $users_view->getFileInfo('files_versions/' . $filename . '.v' . $mtime);
-
- // Keep the "encrypted" value of the original file
- $oldVersion = $files_view->getFileInfo($filename)->getEncryptedVersion();
- $cache = $newFileInfo->getStorage()->getCache();
- $cache->update($newFileInfo->getId(), ['encrypted' => $oldVersion, 'encryptedVersion' => $oldVersion]);
+ $users_view->getFileInfo('files_versions/' . $filename . '.v' . $mtime);
}
}
@@ -331,15 +326,22 @@ class Storage {
//first create a new version
$version = 'files_versions'.$filename.'.v'.$users_view->filemtime('files'.$filename);
- if ( !$users_view->file_exists($version)) {
-
+ if (!$users_view->file_exists($version)) {
$users_view->copy('files'.$filename, 'files_versions'.$filename.'.v'.$users_view->filemtime('files'.$filename));
-
$versionCreated = true;
}
+ $fileToRestore = 'files_versions' . $filename . '.v' . $revision;
+
+ // 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();
+ $newFileInfo = $files_view->getFileInfo($filename);
+ $cache = $newFileInfo->getStorage()->getCache();
+ $cache->update($newFileInfo->getId(), ['encrypted' => $oldVersion, 'encryptedVersion' => $oldVersion]);
+
// rollback
- if (self::copyFileContents($users_view, 'files_versions' . $filename . '.v' . $revision, 'files' . $filename)) {
+ if (self::copyFileContents($users_view, $fileToRestore, 'files' . $filename)) {
$files_view->touch($file, $revision);
Storage::scheduleExpire($uid, $file);
\OC_Hook::emit('\OCP\Versions', 'rollback', array(