Check if array elements exist before using them

It seems that in some recent upgrade here. Not always the entries we
expect are returned. So we should first check if they exist. As to not
spam the log.

Signed-off-by: Roeland Jago Douma <roeland@famdouma.nl>
This commit is contained in:
Roeland Jago Douma 2020-10-23 12:40:12 +02:00 committed by backportbot[bot]
parent 238435f9b5
commit 2cafd81d23
1 changed files with 7 additions and 1 deletions

View File

@ -164,7 +164,13 @@ class AmazonS3 extends \OC\Files\Storage\Common {
'MaxKeys' => 1,
'Delimiter' => '/',
]);
$this->directoryCache[$path] = ($result['Contents'][0]['Key'] === rtrim($path, '/') . '/') || $result['CommonPrefixes'];
if ((isset($result['Contents'][0]['Key']) && $result['Contents'][0]['Key'] === rtrim($path, '/') . '/')
|| isset($result['CommonPrefixes'])) {
$this->directoryCache[$path] = true;
} else {
$this->directoryCache[$path] = false;
}
} catch (S3Exception $e) {
if ($e->getStatusCode() === 403) {
$this->directoryCache[$path] = false;