X-Git-Url: http://git.vrable.net/?a=blobdiff_plain;f=bluesky%2Fstore.c;h=af25ca366eb4ddbab12d0d1b940104b234d31832;hb=bf1b396c85d03f9c16eee6cd84c71c82503c3ec4;hp=5cc475efcdbd2dc7c8ae0a08cc4b947a5f0641cb;hpb=4e24d47abcb5b0e97ab13afc8f97f8fdcab14843;p=bluesky.git diff --git a/bluesky/store.c b/bluesky/store.c index 5cc475e..af25ca3 100644 --- a/bluesky/store.c +++ b/bluesky/store.c @@ -87,6 +87,11 @@ void bluesky_store_free(BlueSkyStore *store) g_free(store); } +char *bluesky_store_lookup_last(BlueSkyStore *store, const char *prefix) +{ + return store->impl->lookup_last(store->handle, prefix); +} + BlueSkyStoreAsync *bluesky_store_async_new(BlueSkyStore *store) { BlueSkyStoreAsync *async; @@ -494,11 +499,35 @@ static void filestore_cleanup(gpointer store, BlueSkyStoreAsync *async) { } +static char *filestore_lookup_last(gpointer store, const char *prefix) +{ + char *last = NULL; + GDir *dir = g_dir_open(".", 0, NULL); + if (dir == NULL) { + g_warning("Unable to open directory for listing"); + return NULL; + } + + const gchar *file; + while ((file = g_dir_read_name(dir)) != NULL) { + if (strncmp(file, prefix, strlen(prefix)) == 0) { + if (last == NULL || strcmp(file, last) > 0) { + g_free(last); + last = g_strdup(file); + } + } + } + g_dir_close(dir); + + return last; +} + static BlueSkyStoreImplementation filestore_impl = { .create = filestore_create, .destroy = filestore_destroy, .submit = filestore_submit, .cleanup = filestore_cleanup, + .lookup_last = filestore_lookup_last, }; /* A store implementation which simply discards all data, for testing. */