Skip to content

Commit 5cb2786

Browse files
committed
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 715378f commit 5cb2786

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
@@ -344,7 +344,9 @@ public function getMetaData(string $path): ?array {
344344
if ($cacheEntry instanceof CacheEntry) {
345345
$data['storage_mtime'] = $cacheEntry->getStorageMTime();
346346
} elseif (!$this->isRoot($path) && $directoryMarker = $this->headObject($path . '/')) {
347-
$data['storage_mtime'] = strtotime($directoryMarker['LastModified']);
347+
if (isset($directoryMarker['LastModified'])) {
348+
$data['storage_mtime'] = strtotime($directoryMarker['LastModified']);
349+
}
348350
}
349351
}
350352
return $data;
@@ -673,12 +675,14 @@ public function getDirectoryContent(string $directory): \Traversable {
673675
}
674676

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

0 commit comments

Comments
 (0)