diff options
author | Robin Appelman <robin@icewind.nl> | 2022-10-21 16:24:32 +0200 |
---|---|---|
committer | Robin Appelman <robin@icewind.nl> | 2022-11-30 14:54:56 +0100 |
commit | e9b87c73faf4c2cdabca9e14762b7a5b67a57526 (patch) | |
tree | a0c92cfe729c6a918231a3eb17fc6d1bd4252a44 /lib/private/Files/Storage/Wrapper | |
parent | 8434259b1bfef22adbf30b166043e29763bf9507 (diff) | |
download | nextcloud-server-e9b87c73faf4c2cdabca9e14762b7a5b67a57526.tar.gz nextcloud-server-e9b87c73faf4c2cdabca9e14762b7a5b67a57526.zip |
fix reading newly written encrypted files before their cache entry is written
Signed-off-by: Robin Appelman <robin@icewind.nl>
Diffstat (limited to 'lib/private/Files/Storage/Wrapper')
-rw-r--r-- | lib/private/Files/Storage/Wrapper/Encryption.php | 16 |
1 files changed, 12 insertions, 4 deletions
diff --git a/lib/private/Files/Storage/Wrapper/Encryption.php b/lib/private/Files/Storage/Wrapper/Encryption.php index 21db6b7bf9d..eaecc0570d9 100644 --- a/lib/private/Files/Storage/Wrapper/Encryption.php +++ b/lib/private/Files/Storage/Wrapper/Encryption.php @@ -45,6 +45,7 @@ use OC\Files\Mount\Manager; use OC\Files\ObjectStore\ObjectStoreStorage; use OC\Files\Storage\LocalTempFileTrait; use OC\Memcache\ArrayCache; +use OCP\Cache\CappedMemoryCache; use OCP\Encryption\Exceptions\GenericEncryptionException; use OCP\Encryption\IFile; use OCP\Encryption\IManager; @@ -95,6 +96,9 @@ class Encryption extends Wrapper { /** @var ArrayCache */ private $arrayCache; + /** @var CappedMemoryCache<bool> */ + private CappedMemoryCache $encryptedPaths; + /** * @param array $parameters */ @@ -122,6 +126,7 @@ class Encryption extends Wrapper { $this->update = $update; $this->mountManager = $mountManager; $this->arrayCache = $arrayCache; + $this->encryptedPaths = new CappedMemoryCache(); parent::__construct($parameters); } @@ -461,6 +466,7 @@ class Encryption extends Wrapper { } if ($shouldEncrypt === true && $encryptionModule !== null) { + $this->encryptedPaths->set($this->util->stripPartialFileExtension($path), true); $headerSize = $this->getHeaderSize($path); $source = $this->storage->fopen($path, $mode); if (!is_resource($source)) { @@ -970,11 +976,13 @@ class Encryption extends Wrapper { $result = []; - // first check if it is an encrypted file at all - // We would do query to filecache only if we know that entry in filecache exists + $isEncrypted = $this->encryptedPaths->get($realFile); + if (is_null($isEncrypted)) { + $info = $this->getCache()->get($path); + $isEncrypted = isset($info['encrypted']) && $info['encrypted'] === true; + } - $info = $this->getCache()->get($path); - if (isset($info['encrypted']) && $info['encrypted'] === true) { + if ($isEncrypted) { $firstBlock = $this->readFirstBlock($path); $result = $this->parseRawHeader($firstBlock); |