From 9acb1f728c6feabdf7c9527c0b922bee2df48d88 Mon Sep 17 00:00:00 2001 From: Harshavardhana Date: Fri, 27 Feb 2015 17:50:55 -0800 Subject: [PATCH] Sort list of objects --- pkg/api/minioapi/response.go | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/pkg/api/minioapi/response.go b/pkg/api/minioapi/response.go index 9f65fe3d5..17a29a8ea 100644 --- a/pkg/api/minioapi/response.go +++ b/pkg/api/minioapi/response.go @@ -17,6 +17,8 @@ package minioapi import ( + "sort" + mstorage "github.com/minio-io/minio/pkg/storage" ) @@ -52,6 +54,12 @@ func generateBucketsListResult(buckets []mstorage.BucketMetadata) BucketListResp return data } +type ItemKey []*Item + +func (b ItemKey) Len() int { return len(b) } +func (b ItemKey) Swap(i, j int) { b[i], b[j] = b[j], b[i] } +func (b ItemKey) Less(i, j int) bool { return b[i].Key < b[j].Key } + // takes a set of objects and prepares the objects for serialization // input: // bucket name @@ -78,6 +86,7 @@ func generateObjectsListResult(bucket string, objects []mstorage.ObjectMetadata, content.Owner = owner contents = append(contents, content) } + sort.Sort(ItemKey(contents)) data.Name = bucket data.Contents = contents data.MaxKeys = MAX_OBJECT_LIST