Skip to content
This repository has been archived by the owner on Jan 27, 2024. It is now read-only.

Allow list contents to return more than 5000 blobs #19

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 14 additions & 3 deletions src/AzureAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -218,12 +218,23 @@ public function listContents($directory = '', $recursive = false)
$options->setDelimiter('/');
}

/** @var ListBlobsResult $listResults */
$listResults = $this->client->listBlobs($this->container, $options);
$blobs = [];

while (true) {
/** @var ListBlobsResult $listResults */
$listResults = $this->client->listBlobs($this->container, $options);
$blobs = array_merge($blobs, $listResults->getBlobs());

if (!$nextMarker = $listResults->getNextMarker()) {
break;
}

$options->setMarker($nextMarker);
}

$contents = [];

foreach ($listResults->getBlobs() as $blob) {
foreach ($blobs as $blob) {
$contents[] = $this->normalizeBlobProperties($blob->getName(), $blob->getProperties());
}

Expand Down
45 changes: 45 additions & 0 deletions tests/AzureTests.php
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,8 @@ public function testListContents()

$blobsList->shouldReceive('getBlobPrefixes')->once()->andReturn([]);

$blobsList->shouldReceive('getNextMarker')->once()->andReturn(null);

$this->azure->shouldReceive('listBlobs')->once()->andReturn($blobsList);

$this->assertSame([
Expand All @@ -278,6 +280,45 @@ public function testListContents()
], $this->adapter->listContents());
}

public function testListContentsWithMarker()
{
$properties = Mockery::mock('MicrosoftAzure\Storage\Blob\Models\BlobProperties');
$properties->shouldReceive('getLastModified')->twice()->andReturn(\DateTime::createFromFormat(\DateTime::RFC1123, 'Tue, 02 Dec 2014 08:09:01 +0000'));
$properties->shouldReceive('getContentType')->twice()->andReturn('text/plain');
$properties->shouldReceive('getContentLength')->twice()->andReturn(42);

$blob = Mockery::mock('MicrosoftAzure\Storage\Blob\Models\Blob');
$blob->shouldReceive('getName')->twice()->andReturnValues(['foo.txt', 'foo2.txt']);
$blob->shouldReceive('getProperties')->twice()->andReturn($properties);

$blobsList = Mockery::mock('MicrosoftAzure\Storage\Blob\Models\ListBlobsResult');
$blobsList->shouldReceive('getBlobs')->twice()->andReturn([$blob]);

$blobsList->shouldReceive('getBlobPrefixes')->once()->andReturn([]);

$blobsList->shouldReceive('getNextMarker')->twice()->andReturnValues(["marker_id", null]);

$this->azure->shouldReceive('listBlobs')->twice()->andReturn($blobsList);

$this->assertSame([
[
'path' => 'foo.txt',
'timestamp' => 1417507741,
'dirname' => '',
'mimetype' => 'text/plain',
'size' => 42,
'type' => 'file',
], [
'path' => 'foo2.txt',
'timestamp' => 1417507741,
'dirname' => '',
'mimetype' => 'text/plain',
'size' => 42,
'type' => 'file',
],
], $this->adapter->listContents());
}

public function testDirectoryEmulationInListContents()
{
$properties = Mockery::mock('MicrosoftAzure\Storage\Blob\Models\BlobProperties');
Expand All @@ -298,6 +339,8 @@ public function testDirectoryEmulationInListContents()

$blobsList->shouldReceive('getBlobPrefixes')->once()->andReturn([]);

$blobsList->shouldReceive('getNextMarker')->once()->andReturn(null);

$this->azure->shouldReceive('listBlobs')->once()->andReturn($blobsList);

$listing = $this->adapter->listContents();
Expand Down Expand Up @@ -342,6 +385,8 @@ public function testPrefixesInListContents()
$blobsList->shouldReceive('getBlobs')->once()->andReturn([$blob]);
$blobsList->shouldReceive('getBlobPrefixes')->once()->andReturn([$blobPrefix]);

$blobsList->shouldReceive('getNextMarker')->once()->andReturn(null);

$this->azure->shouldReceive('listBlobs')->once()->andReturn($blobsList);

$this->assertSame([
Expand Down