Skip to content

Commit 7b60056

Browse files
Antreesybackportbot[bot]
authored andcommitted
fix(AmazonS3): handle missing LastModified and ETag in S3 responses
Add null-safety checks to handle S3 responses that don't include LastModified and ETag fields. This prevents 'Undefined array key' warnings and deprecation notices when processing directory metadata or incomplete S3 responses. - objectToMetaData(): Check if LastModified/ETag exist before accessing - getMetaData(): Check if LastModified exists before using in strtotime() Fixes test failures in testStat where hasUpdated('/', time) would fail when encountering S3 objects without complete metadata. Assisted-by: ClaudeCode:claude-sonnet-4-6 Signed-off-by: Maksim Sukharev <antreesy.web@gmail.com>
1 parent 11ce85c commit 7b60056

1 file changed

Lines changed: 8 additions & 4 deletions

File tree

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

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -345,7 +345,9 @@ public function getMetaData(string $path): ?array {
345345
if ($cacheEntry instanceof CacheEntry) {
346346
$data['storage_mtime'] = $cacheEntry->getStorageMTime();
347347
} elseif (!$this->isRoot($path) && $directoryMarker = $this->headObject($path . '/')) {
348-
$data['storage_mtime'] = strtotime($directoryMarker['LastModified']);
348+
if (isset($directoryMarker['LastModified'])) {
349+
$data['storage_mtime'] = strtotime($directoryMarker['LastModified']);
350+
}
349351
}
350352
}
351353
return $data;
@@ -674,12 +676,14 @@ public function getDirectoryContent(string $directory): \Traversable {
674676
}
675677

676678
private function objectToMetaData(array $object): array {
679+
$mtime = isset($object['LastModified']) ? strtotime($object['LastModified']) : time();
680+
$etag = isset($object['ETag']) ? trim($object['ETag'], '"') : '';
677681
return [
678682
'name' => basename($object['Key']),
679683
'mimetype' => $this->mimeDetector->detectPath($object['Key']),
680-
'mtime' => strtotime($object['LastModified']),
681-
'storage_mtime' => strtotime($object['LastModified']),
682-
'etag' => trim($object['ETag'], '"'),
684+
'mtime' => $mtime,
685+
'storage_mtime' => $mtime,
686+
'etag' => $etag,
683687
'permissions' => Constants::PERMISSION_ALL - Constants::PERMISSION_CREATE,
684688
'size' => (int)($object['Size'] ?? $object['ContentLength']),
685689
];

0 commit comments

Comments
 (0)