Skip to content

Commit

Permalink
Merge pull request akamai#9 from lookaflyingdonkey/fix-list-contents
Browse files Browse the repository at this point in the history
Fix listContents in base dir
  • Loading branch information
dshafik authored Apr 4, 2017
2 parents 6d8a720 + ca60723 commit c4150c3
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions src/FileStoreAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ public function has($path)
*/
public function listContents($directory = '', $recursive = false)
{
$response = $this->httpClient->get($this->applyPathPrefix($directory), [
$response = $this->httpClient->get(rtrim($this->applyPathPrefix($directory), '\\/'), [
'headers' => [
'X-Akamai-ACS-Action' => $this->getAcsActionHeaderValue('dir')
]
Expand All @@ -251,8 +251,12 @@ public function listContents($directory = '', $recursive = false)
foreach ($xml->file as $file) {
$meta = $this->handleFileMetaData($directory, $file);
$dir[$meta['path']] = $meta;
if ($recursive && $meta['type'] == 'dir') {
$dir[$meta['path']]['children'] = $this->listContents($meta['path'], $recursive);
if ($meta['type'] == 'dir') {
if($recursive) {
$dir[$meta['path']]['children'] = $this->listContents($meta['path'], $recursive);
} else {
$dir[$meta['path']]['children'] = [];
}
}
}

Expand Down Expand Up @@ -465,9 +469,15 @@ protected function getAcsActionHeaderValue($action, array $options = null)
*/
protected function handleFileMetaData($baseDir, $file = null)
{
if($baseDir == '') {
$metaPath = (string) $file['name'];
} else {
$metaPath = (string) $baseDir . '/' . (string) $file['name'];
}

$meta = [
'type' => (string) $file['type'],
'path' => (string) $baseDir . '/' . (string) $file['name'],
'path' => $metaPath,
'visibility' => 'public',
'timestamp' => (string) $file['mtime'],
];
Expand Down

0 comments on commit c4150c3

Please sign in to comment.