Skip to content

Commit a0923d9

Browse files
committed
reset encryptionVersion to '1' if a file was stream copied, because this means that we basically write the file from scratch
Signed-off-by: Bjoern Schiessle <bjoern@schiessle.org>
1 parent ed239d7 commit a0923d9

2 files changed

Lines changed: 9 additions & 8 deletions

File tree

lib/private/Files/Storage/Wrapper/Encryption.php

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -652,21 +652,22 @@ public function copyFromStorage(Storage\IStorage $sourceStorage, $sourceInternal
652652
* @param string $sourceInternalPath
653653
* @param string $targetInternalPath
654654
* @param bool $isRename
655+
* @param bool $keepEncryptionVersion
655656
*/
656-
private function updateEncryptedVersion(Storage\IStorage $sourceStorage, $sourceInternalPath, $targetInternalPath, $isRename) {
657-
$isEncrypted = $this->encryptionManager->isEnabled() && $this->shouldEncrypt($targetInternalPath) ? 1 : 0;
657+
private function updateEncryptedVersion(Storage\IStorage $sourceStorage, $sourceInternalPath, $targetInternalPath, $isRename, $keepEncryptionVersion) {
658+
$isEncrypted = $this->encryptionManager->isEnabled() && $this->shouldEncrypt($targetInternalPath);
658659
$cacheInformation = [
659-
'encrypted' => (bool)$isEncrypted,
660+
'encrypted' => $isEncrypted,
660661
];
661-
if($isEncrypted === 1) {
662+
if($isEncrypted) {
662663
$encryptedVersion = $sourceStorage->getCache()->get($sourceInternalPath)['encryptedVersion'];
663664

664665
// In case of a move operation from an unencrypted to an encrypted
665666
// storage the old encrypted version would stay with "0" while the
666667
// correct value would be "1". Thus we manually set the value to "1"
667668
// for those cases.
668669
// See also https://github.com/owncloud/core/issues/23078
669-
if($encryptedVersion === 0) {
670+
if($encryptedVersion === 0 || !$keepEncryptionVersion) {
670671
$encryptedVersion = 1;
671672
}
672673

@@ -714,7 +715,7 @@ private function copyBetweenStorage(Storage\IStorage $sourceStorage, $sourceInte
714715
$info['size']
715716
);
716717
}
717-
$this->updateEncryptedVersion($sourceStorage, $sourceInternalPath, $targetInternalPath, $isRename);
718+
$this->updateEncryptedVersion($sourceStorage, $sourceInternalPath, $targetInternalPath, $isRename, true);
718719
}
719720
return $result;
720721
}
@@ -757,7 +758,7 @@ private function copyBetweenStorage(Storage\IStorage $sourceStorage, $sourceInte
757758
if ($preserveMtime) {
758759
$this->touch($targetInternalPath, $sourceStorage->filemtime($sourceInternalPath));
759760
}
760-
$this->updateEncryptedVersion($sourceStorage, $sourceInternalPath, $targetInternalPath, $isRename);
761+
$this->updateEncryptedVersion($sourceStorage, $sourceInternalPath, $targetInternalPath, $isRename, false);
761762
} else {
762763
// delete partially written target file
763764
$this->unlink($targetInternalPath);

tests/lib/Files/Storage/Wrapper/EncryptionTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -802,7 +802,7 @@ public function testCopyBetweenStorage($encryptionEnabled, $mountPointEncryption
802802
'encrypted' => $expectedEncrypted,
803803
];
804804
if($expectedEncrypted === true) {
805-
$expectedCachePut['encryptedVersion'] = 12345;
805+
$expectedCachePut['encryptedVersion'] = 1;
806806
}
807807

808808
$this->arrayCache->expects($this->never())->method('set');

0 commit comments

Comments
 (0)