From cd654b732384d42784fb995ac94940a57223ab32 Mon Sep 17 00:00:00 2001 From: Michael Vrable Date: Fri, 10 Sep 2010 13:30:52 -0700 Subject: [PATCH] Implement a list operation for the S3 storage backend. --- bluesky/store-s3.c | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/bluesky/store-s3.c b/bluesky/store-s3.c index e34fafd..e762ebd 100644 --- a/bluesky/store-s3.c +++ b/bluesky/store-s3.c @@ -34,10 +34,16 @@ struct get_info { }; struct put_info { + int success; BlueSkyRCStr *val; gint offset; }; +struct list_info { + int success; + char *last_entry; +}; + static S3Status s3store_get_handler(int bufferSize, const char *buffer, void *callbackData) { @@ -126,6 +132,42 @@ static void s3store_task(gpointer a, gpointer s) bluesky_store_async_unref(async); } +static S3Status s3store_list_handler(int isTruncated, + const char *nextMarker, + int contentsCount, + const S3ListBucketContent *contents, + int commonPrefixesCount, + const char **commonPrefixes, + void *callbackData) +{ + struct list_info *info = (struct list_info *)callbackData; + if (contentsCount > 0) { + g_free(info->last_entry); + info->last_entry = g_strdup(contents[contentsCount - 1].key); + } + return S3StatusOK; +} + +static char *s3store_lookup_last(gpointer s, const char *prefix) +{ + S3Store *store = (S3Store *)s; + struct list_info info = {0, NULL}; + + struct S3ListBucketHandler handler; + handler.responseHandler.propertiesCallback + = s3store_properties_callback; + handler.responseHandler.completeCallback = s3store_response_callback; + handler.listBucketCallback = s3store_list_handler; + + char *marker = NULL; + + S3_list_bucket(&store->bucket, prefix, marker, NULL, 1024, NULL, &handler, &info); + + g_print("Last key: %s\n", info.last_entry); + + return S3StatusOK; +} + static gpointer s3store_new(const gchar *path) { S3Store *store = g_new(S3Store, 1); @@ -192,6 +234,7 @@ static BlueSkyStoreImplementation store_impl = { .destroy = s3store_destroy, .submit = s3store_submit, .cleanup = s3store_cleanup, + .lookup_last = s3store_lookup_last, }; void bluesky_store_init_s3(void) -- 2.20.1