2 * Copyright (C) 2013 Steven McDonald <steven@steven-mcdonald.id.au>
4 * This program is free software. It comes without any warranty, to the
5 * extent permitted by applicable law. You can redistribute it and/or
6 * modify it under the terms of the Do What The Fuck You Want To Public
7 * License, Version 2, as published by Sam Hocevar. See the file
8 * COPYING.WTFPL accompanying this distribution or http://www.wtfpl.net/
17 static char *keys[TROVEFS_MAX_LIST_KEYS];
19 typedef struct list_bucket_callback_data
22 char nextMarker[1024];
25 } list_bucket_callback_data;
28 responsePropertiesCallback (const S3ResponseProperties *properties, void *callbackData)
34 responseCompleteCallback (S3Status status, const S3ErrorDetails *error, void *callbackData)
40 list_bucket_callback (
42 const char *nextMarker,
44 const S3ListBucketContent *contents,
45 int commonPrefixesCount,
46 const char **commonPrefixes,
49 list_bucket_callback_data *data = (list_bucket_callback_data *) callbackData;
51 data->isTruncated = isTruncated;
53 if ((!nextMarker || !nextMarker[0]) && contentsCount)
55 nextMarker = contents[contentsCount - 1].key;
59 snprintf (data->nextMarker, sizeof (data->nextMarker), "%s", nextMarker);
63 data->nextMarker[0] = 0;
66 for (int i = 0; i < contentsCount; i++)
68 const S3ListBucketContent *content = &(contents[i]);
69 keys[i] = malloc (sizeof (content->key));
70 strcpy (keys[i], content->key);
72 keys[contentsCount] = malloc (1);
73 keys[contentsCount][0] = '\0';
78 trovefs_s3_get_names (struct trovefs_dir *dir)
81 struct trovefs *fs = dir->fs;
82 S3BucketContext *bucket = fs->s3_ctx;
84 S3ListBucketHandler list_bucket_handler =
86 { &responsePropertiesCallback, &responseCompleteCallback },
90 list_bucket_callback_data data;
97 TROVEFS_MAX_LIST_KEYS,
103 struct trovefs_dir_entry *e = 0;
104 struct trovefs_dir_entry *p;
106 for (int i = 0; i < TROVEFS_MAX_LIST_KEYS; i++)
108 if (!keys[i] || keys[i][0] == '\0')
111 e = lookup (dir, keys[i], 1);
118 if (! e->ordered_self_p)
120 e->ordered_self_p = p ? &p->next : &dir->ordered;
121 if (*e->ordered_self_p)
122 (*e->ordered_self_p)->ordered_self_p = &e->ordered_next;
123 e->ordered_next = *e->ordered_self_p;
124 *e->ordered_self_p = e;