Skip to content

Commit f972374

Browse files
committed
fix reading newly written encrypted files before their cache entry is written
Signed-off-by: Robin Appelman <robin@icewind.nl>
1 parent 56fe33f commit f972374

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

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

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
use OC\Files\ObjectStore\ObjectStoreStorage;
4646
use OC\Files\Storage\LocalTempFileTrait;
4747
use OC\Memcache\ArrayCache;
48+
use OCP\Cache\CappedMemoryCache;
4849
use OCP\Encryption\Exceptions\GenericEncryptionException;
4950
use OCP\Encryption\IFile;
5051
use OCP\Encryption\IManager;
@@ -95,6 +96,9 @@ class Encryption extends Wrapper {
9596
/** @var ArrayCache */
9697
private $arrayCache;
9798

99+
/** @var CappedMemoryCache<bool> */
100+
private CappedMemoryCache $encryptedPaths;
101+
98102
/**
99103
* @param array $parameters
100104
*/
@@ -122,6 +126,7 @@ public function __construct(
122126
$this->update = $update;
123127
$this->mountManager = $mountManager;
124128
$this->arrayCache = $arrayCache;
129+
$this->encryptedPaths = new CappedMemoryCache();
125130
parent::__construct($parameters);
126131
}
127132

@@ -461,6 +466,7 @@ public function fopen($path, $mode) {
461466
}
462467

463468
if ($shouldEncrypt === true && $encryptionModule !== null) {
469+
$this->encryptedPaths->set($this->util->stripPartialFileExtension($path), true);
464470
$headerSize = $this->getHeaderSize($path);
465471
$source = $this->storage->fopen($path, $mode);
466472
if (!is_resource($source)) {
@@ -973,8 +979,13 @@ protected function getHeader($path) {
973979
// first check if it is an encrypted file at all
974980
// We would do query to filecache only if we know that entry in filecache exists
975981

976-
$info = $this->getCache()->get($path);
977-
if (isset($info['encrypted']) && $info['encrypted'] === true) {
982+
$isEncrypted = $this->encryptedPaths->get($realFile);
983+
if (is_null($isEncrypted)) {
984+
$info = $this->getCache()->get($path);
985+
$isEncrypted = isset($info['encrypted']) && $info['encrypted'] === true;
986+
}
987+
988+
if ($isEncrypted) {
978989
$firstBlock = $this->readFirstBlock($path);
979990
$result = $this->parseRawHeader($firstBlock);
980991

0 commit comments

Comments
 (0)