Skip to content

Commit 27c0b22

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 c1628ea commit 27c0b22

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
@@ -372,7 +372,9 @@ public function getMetaData(string $path): ?array {
372372
if ($cacheEntry instanceof CacheEntry) {
373373
$data['storage_mtime'] = $cacheEntry->getStorageMTime();
374374
} elseif (!$this->isRoot($path) && $directoryMarker = $this->headObject($path . '/')) {
375-
$data['storage_mtime'] = strtotime($directoryMarker['LastModified']);
375+
if (isset($directoryMarker['LastModified'])) {
376+
$data['storage_mtime'] = strtotime($directoryMarker['LastModified']);
377+
}
376378
}
377379
}
378380
return $data;
@@ -694,12 +696,14 @@ public function getDirectoryContent(string $directory): \Traversable {
694696
}
695697

696698
private function objectToMetaData(array $object): array {
699+
$mtime = isset($object['LastModified']) ? strtotime($object['LastModified']) : time();
700+
$etag = isset($object['ETag']) ? trim($object['ETag'], '"') : '';
697701
return [
698702
'name' => basename($object['Key']),
699703
'mimetype' => $this->mimeDetector->detectPath($object['Key']),
700-
'mtime' => strtotime($object['LastModified']),
701-
'storage_mtime' => strtotime($object['LastModified']),
702-
'etag' => trim($object['ETag'], '"'),
704+
'mtime' => $mtime,
705+
'storage_mtime' => $mtime,
706+
'etag' => $etag,
703707
'permissions' => Constants::PERMISSION_ALL - Constants::PERMISSION_CREATE,
704708
'size' => (int)($object['Size'] ?? $object['ContentLength']),
705709
];

0 commit comments

Comments
 (0)