diff --git a/src/CosAdapter.php b/src/CosAdapter.php index 8c8125f..c2aeaf5 100644 --- a/src/CosAdapter.php +++ b/src/CosAdapter.php @@ -400,10 +400,18 @@ protected function normalizeFileInfo(array $content) */ protected function listObjects($directory = '', $recursive = false) { - return $this->getBucketClient()->getObjects([ + $result = $this->getBucketClient()->getObjects([ 'prefix' => ('' === (string) $directory) ? '' : ($directory.'/'), 'delimiter' => $recursive ? '' : '/', ])['ListBucketResult']; + + $result['Contents'] = $result['Contents'] ?? []; + + if (($key = \key($result['Contents'])) !== 0) { + $result['Contents'] = \is_null($key) ? [] : [$result['Contents']]; + } + + return $result; } /**