aboutsummaryrefslogtreecommitdiffstats
path: root/apps
diff options
context:
space:
mode:
authorChristoph Wurst <christoph@winzerhof-wurst.at>2023-06-01 20:19:24 +0200
committerSimon L <szaimen@e.mail.de>2023-06-12 09:44:48 +0200
commitb8c61b3515ef406c4feafc851f12262e417ba157 (patch)
tree5c45a7174c899ef5dc1618158f57948cf7a551ff /apps
parentc93be182dc0172eed377ba70ce54cd7c83689764 (diff)
downloadnextcloud-server-b8c61b3515ef406c4feafc851f12262e417ba157.tar.gz
nextcloud-server-b8c61b3515ef406c4feafc851f12262e417ba157.zip
fix(caching): Avoid checking existence before fetching
The cache might expire between checking for key existence and fetching the value. In this rare case the code continues with a null value when it doesn't expect one. Signed-off-by: Christoph Wurst <christoph@winzerhof-wurst.at>
Diffstat (limited to 'apps')
-rw-r--r--apps/files_external/lib/Lib/Storage/Swift.php5
-rw-r--r--apps/files_sharing/lib/External/Storage.php5
-rw-r--r--apps/files_sharing/lib/SharedMount.php5
3 files changed, 9 insertions, 6 deletions
diff --git a/apps/files_external/lib/Lib/Storage/Swift.php b/apps/files_external/lib/Lib/Storage/Swift.php
index 85b3727f4db..26e6c5315cb 100644
--- a/apps/files_external/lib/Lib/Storage/Swift.php
+++ b/apps/files_external/lib/Lib/Storage/Swift.php
@@ -126,9 +126,10 @@ class Swift extends \OC\Files\Storage\Common {
* @throws \OCP\Files\StorageNotAvailableException
*/
private function fetchObject(string $path) {
- if ($this->objectCache->hasKey($path)) {
+ $cached = $this->objectCache->get($path);
+ if ($cached !== null) {
// might be "false" if object did not exist from last check
- return $this->objectCache->get($path);
+ return $cached;
}
try {
$object = $this->getContainer()->getObject($path);
diff --git a/apps/files_sharing/lib/External/Storage.php b/apps/files_sharing/lib/External/Storage.php
index 506a2f83c2d..9e6c169e140 100644
--- a/apps/files_sharing/lib/External/Storage.php
+++ b/apps/files_sharing/lib/External/Storage.php
@@ -265,8 +265,9 @@ class Storage extends DAV implements ISharedStorage, IDisableEncryptionStorage,
private function testRemoteUrl(string $url): bool {
$cache = $this->memcacheFactory->createDistributed('files_sharing_remote_url');
- if ($cache->hasKey($url)) {
- return (bool)$cache->get($url);
+ $cached = $cache->get($url);
+ if ($cached !== null) {
+ return (bool)$cached;
}
$client = $this->httpClient->newClient();
diff --git a/apps/files_sharing/lib/SharedMount.php b/apps/files_sharing/lib/SharedMount.php
index 943f14dc2bd..6cde9f82bec 100644
--- a/apps/files_sharing/lib/SharedMount.php
+++ b/apps/files_sharing/lib/SharedMount.php
@@ -117,8 +117,9 @@ class SharedMount extends MountPoint implements MoveableMount {
$this->eventDispatcher->dispatchTyped($event);
$parent = $event->getParent();
- if ($folderExistCache->hasKey($parent)) {
- $parentExists = $folderExistCache->get($parent);
+ $cached = $folderExistCache->get($parent);
+ if ($cached) {
+ $parentExists = $cached;
} else {
$parentExists = $this->recipientView->is_dir($parent);
$folderExistCache->set($parent, $parentExists);