|
45 | 45 | use OC\Files\ObjectStore\ObjectStoreStorage; |
46 | 46 | use OC\Files\Storage\LocalTempFileTrait; |
47 | 47 | use OC\Memcache\ArrayCache; |
| 48 | +use OCP\Cache\CappedMemoryCache; |
48 | 49 | use OCP\Encryption\Exceptions\GenericEncryptionException; |
49 | 50 | use OCP\Encryption\IFile; |
50 | 51 | use OCP\Encryption\IManager; |
@@ -95,6 +96,9 @@ class Encryption extends Wrapper { |
95 | 96 | /** @var ArrayCache */ |
96 | 97 | private $arrayCache; |
97 | 98 |
|
| 99 | + /** @var CappedMemoryCache<bool> */ |
| 100 | + private CappedMemoryCache $encryptedPaths; |
| 101 | + |
98 | 102 | /** |
99 | 103 | * @param array $parameters |
100 | 104 | */ |
@@ -122,6 +126,7 @@ public function __construct( |
122 | 126 | $this->update = $update; |
123 | 127 | $this->mountManager = $mountManager; |
124 | 128 | $this->arrayCache = $arrayCache; |
| 129 | + $this->encryptedPaths = new CappedMemoryCache(); |
125 | 130 | parent::__construct($parameters); |
126 | 131 | } |
127 | 132 |
|
@@ -461,6 +466,7 @@ public function fopen($path, $mode) { |
461 | 466 | } |
462 | 467 |
|
463 | 468 | if ($shouldEncrypt === true && $encryptionModule !== null) { |
| 469 | + $this->encryptedPaths->set($this->util->stripPartialFileExtension($path), true); |
464 | 470 | $headerSize = $this->getHeaderSize($path); |
465 | 471 | $source = $this->storage->fopen($path, $mode); |
466 | 472 | if (!is_resource($source)) { |
@@ -973,8 +979,13 @@ protected function getHeader($path) { |
973 | 979 | // first check if it is an encrypted file at all |
974 | 980 | // We would do query to filecache only if we know that entry in filecache exists |
975 | 981 |
|
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) { |
978 | 989 | $firstBlock = $this->readFirstBlock($path); |
979 | 990 | $result = $this->parseRawHeader($firstBlock); |
980 | 991 |
|
|
0 commit comments