Skip to content

Commit

Permalink
Fixed error of Storage::lastModified()
Browse files Browse the repository at this point in the history
  • Loading branch information
jacobcyl authored Aug 11, 2016
1 parent f050d95 commit 7d17a38
Showing 1 changed file with 11 additions and 11 deletions.
22 changes: 11 additions & 11 deletions src/AliOssAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -304,65 +304,65 @@ public function listDirObjects($dirname = '', $recursive = false)

//存储结果
$result = [];

while(true){
$options = [
'delimiter' => $delimiter,
'prefix' => $dirname,
'max-keys' => $maxkeys,
'marker' => $nextMarker,
];

try {
$listObjectInfo = $this->client->listObjects($this->bucket, $options);
} catch (OssException $e) {
$this->logErr(__FUNCTION__, $e);
return false;
}

$nextMarker = $listObjectInfo->getNextMarker(); // 得到nextMarker,从上一次listObjects读到的最后一个文件的下一个文件开始继续获取文件列表
$objectList = $listObjectInfo->getObjectList(); // 文件列表
$prefixList = $listObjectInfo->getPrefixList(); // 目录列表

if (!empty($objectList)) {
foreach ($objectList as $objectInfo) {

$object['Prefix'] = $dirname;
$object['Key'] = $objectInfo->getKey();
$object['LastModified'] = $objectInfo->getLastModified();
$object['eTag'] = $objectInfo->getETag();
$object['Type'] = $objectInfo->getType();
$object['Size'] = $objectInfo->getSize();
$object['StorageClass'] = $objectInfo->getStorageClass();

$result['objects'][] = $object;
}
}else{
$result["objects"] = [];
}

if (!empty($prefixList)) {
foreach ($prefixList as $prefixInfo) {
$result['prefix'][] = $prefixInfo->getPrefix();
}
}else{
$result['prefix'] = [];
}

//递归查询子目录所有文件
if($recursive){
foreach( $result['prefix'] as $pfix){
$next = $this->listDirObjects($pfix , $recursive);
$result["objects"] = array_merge($result['objects'], $next["objects"]);
}
}

//没有更多结果了
if ($nextMarker === '') {
break;
}
}

return $result;
}

Expand Down Expand Up @@ -508,7 +508,7 @@ public function getMimetype($path)
public function getTimestamp($path)
{
if( $object = $this->getMetadata($path))
$object['mimetype'] = $object['content-type'];
$object['timestamp'] = $object['last-modified'];
return $object;
}

Expand Down

0 comments on commit 7d17a38

Please sign in to comment.