Skip to content

Commit

Permalink
Fixed #81: Dropbox listing refactored, it had double prefixing.
Browse files Browse the repository at this point in the history
  • Loading branch information
frankdejonge committed Feb 16, 2014
1 parent dedd25e commit 0c09cca
Showing 1 changed file with 10 additions and 12 deletions.
22 changes: 10 additions & 12 deletions src/Adapter/Dropbox.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public function __construct(Client $client, $prefix = null)
{
$prefix = trim($prefix, '/');
$this->client = $client;
$this->prefix = '/' . (empty($prefix) ? '' : $prefix . '/');
$this->prefix = '/' . $prefix;
}

/**
Expand Down Expand Up @@ -207,26 +207,22 @@ public function getTimestamp($path)
}

public function listContents($directory = '', $recursive = false)
{
return $this->retrieveListing($this->prefix($directory), $recursive);
}

public function retrieveListing($dir, $recursive = true)
{
$listing = array();
$directory = rtrim($dir, '/.');
$length = strlen($directory) + 1;
$location = $this->prefix($directory);
$directory = trim($directory, '/.');
$prefixLength = strlen($this->prefix);
$location = rtrim($this->prefix($directory), '/');

if ( ! $result = $this->client->getMetadataWithChildren($location)) {
return array();
}

foreach ($result['contents'] as $object) {
$listing[] = $this->normalizeObject($object, substr($object['path'], $length));
$path = substr($object['path'], $prefixLength);
$listing[] = $this->normalizeObject($object, trim($path, '/'));

if ($recursive && $object['is_dir']) {
$listing = array_merge($listing, $this->retrieveListing($object['path']));
$listing = array_merge($listing, $this->listContents($path));
}
}

Expand All @@ -249,6 +245,8 @@ protected function normalizeObject($object, $path = null)

protected function prefix($path)
{
return $this->prefix.$path;
$prefix = rtrim($this->prefix, '/');

return $prefix . '/' . ltrim($path, '/');
}
}

0 comments on commit 0c09cca

Please sign in to comment.