-
Notifications
You must be signed in to change notification settings - Fork 18
List directory contents non-recursively #13
Conversation
36a8a8f
to
1a4a633
Compare
@@ -438,7 +448,7 @@ public function listContents($dirname = '', $recursive = false) | |||
*/ | |||
protected function normalizeResponse(array $object, $path = null) | |||
{ | |||
$result = ['path' => $path ?: $this->removePathPrefix($object['Key'])]; | |||
$result = ['path' => $path ?: $this->removePathPrefix(isset($object['Key']) ? $object['Key'] : $object['Prefix'])]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What case is this addressing? Is this the response for the top level directory? Something else?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If content is listed non-recursively prefixes are listed without Key
attribute. The path of the directory is stored as Prefix
. Directory level doesn't matter here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure I follow... If the directory is stored as Prefix, then all the files would be named the same, which wouldn't be correct. Or is the file path returned under the Prefix key?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry for the delay. I've created a gist showing how the response from S3 looks like:
https://gist.github.com/zaak/6b0788dfbc1391849dbb, should be more clear.
I have a set of tests in our app that use Flysystem quite intensely, so I assume this change shouldn't break anything, as they all pass.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And the best comment on a PR award goes tooooooooo ... @zaak! Seriously, thanks for this, this is exactly what I wanted to know.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Btw, @zaak, could we use this for the V3 as well?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@frankdejonge I think yes, haven't checked it yet though.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@zaak version 1.0.3 is tagged and should be available shortly.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@frankdejonge Awesome! Thanks! :)
List directory contents non-recursively
This PR allows for non-recursive content listing. The previous approach was always fetching all objects recursively (by prefix), which is really inefficient in case if some of the subdirectories contains a large number of files.
http://docs.aws.amazon.com/AmazonS3/latest/dev/ListingKeysHierarchy.html
http://codereview.stackexchange.com/questions/6847/list-objects-in-a-amazon-s3-folder-without-also-listing-objects-in-sub-folders/6850#6850