Default sort on S3 bucket.list() method?

911 views
Skip to first unread message

Richa

unread,
Apr 17, 2008, 8:03:25 PM4/17/08
to boto-users
Hi,

I'm wondering whether there is a default sort on the list returned by
bucket.list(). If so, what is it? Alphabetical? Please let me know.

Thanks,
Richa

JJ Geewax

unread,
Apr 17, 2008, 10:37:52 PM4/17/08
to boto-users
Hi Richa,

I'm not particularly versed in this area of the code, but it looks
like the list method creates a new BucketListResultSet object from the
current bucket (based on your prefix and delimiter).
The BucketListResultSet
(boto.s3.bucketlistresultset.BucketListResultSet) object continues to
call the bucket's get_all_keys method (which is deprecated, so it's
not recommended that you use that directly) until the result set is no
longer truncated (ie, the last "page" of the result set).

Put simply, it appears that the order of the results is really
determined by Amazon's returned result set on each page of results.
That is, the results you get back are in exactly the order that Amazon
returns them in a set of pages of results.

That said, if you need them sorted in a particular way, you can
iterate through all of the keys in the list, store them locally in a
list, and then sort that any way you want. I think the idea behind an
iterator was to avoid holding (possibly) enormous lists of keys
locally when most commonly the list() method is for iterating through
the keys to find the one you want.

Hope that answers your question,

JJ

Richa

unread,
Apr 21, 2008, 2:04:42 PM4/21/08
to boto-users
> Hope that answers your question,

Thanks, JJ. It does.

> That said, if you need them sorted in a particular way, you can
> iterate through all of the keys in the list, store them locally in a
> list, and then sort that any way you want. I think the idea behind an
> iterator was to avoid holding (possibly) enormous lists of keys
> locally when most commonly the list() method is for iterating through
> the keys to find the one you want.

Yes; I'm using S3 to store nightly server backups, and every so often
I want to go in and remove older backups, so I need to be able to sort
the bucket key list. I was hoping I wouldn't have to do the local-list
thing, but it looks like that can't be avoided.

Thanks again,
Richa
Reply all
Reply to author
Forward
0 new messages