Skip to content

Commit a0ed68f

Browse files
committed
fix(AmazonS3#headObject): normalize root cache key
1 parent 187183b commit a0ed68f

1 file changed

Lines changed: 11 additions & 6 deletions

File tree

apps/files_external/lib/Lib/Storage/AmazonS3.php

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -115,25 +115,30 @@ private function invalidateCache(string $key): void {
115115
}
116116

117117
private function headObject(string $key): array|false {
118-
if (!isset($this->objectCache[$key])) {
118+
// Normalize only the cache key so callers can keep using the original S3 object key.
119+
$cacheKey = match ($key) {
120+
'', '.' => '.',
121+
default => $key,
122+
};
123+
if (!isset($this->objectCache[$cacheKey])) {
119124
try {
120-
$this->objectCache[$key] = $this->getConnection()->headObject([
125+
$this->objectCache[$cacheKey] = $this->getConnection()->headObject([
121126
'Bucket' => $this->bucket,
122127
'Key' => $key
123128
] + $this->getServerSideEncryptionParameters())->toArray();
124129
} catch (S3Exception $e) {
125130
if ($e->getStatusCode() >= 500) {
126131
throw $e;
127132
}
128-
$this->objectCache[$key] = false;
133+
$this->objectCache[$cacheKey] = false;
129134
}
130135
}
131136

132-
if (is_array($this->objectCache[$key]) && !isset($this->objectCache[$key]['Key'])) {
137+
if (is_array($this->objectCache[$cacheKey]) && !isset($this->objectCache[$cacheKey]['Key'])) {
133138
/** @psalm-suppress InvalidArgument Psalm doesn't understand nested arrays well */
134-
$this->objectCache[$key]['Key'] = $key;
139+
$this->objectCache[$cacheKey]['Key'] = $key;
135140
}
136-
return $this->objectCache[$key];
141+
return $this->objectCache[$cacheKey];
137142
}
138143

139144
/**

0 commit comments

Comments
 (0)