Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

We’re showing branches in this repository, but you can also compare across forks.

base fork: couchbaselabs/libcbio
base: c5994e2712
...
head fork: couchbaselabs/libcbio
compare: e3206f8e55
  • 2 commits
  • 5 files changed
  • 0 commit comments
  • 1 contributor
10 Makefile.am
View
@@ -39,33 +39,43 @@ check_PROGRAMS = tests/test_open_empty_filename \
TESTS=${check_PROGRAMS}
tests_test_open_empty_filename_SOURCES = tests/testapp.c
+tests_test_open_empty_filename_DEPENDENCIES = libcbio.la
tests_test_open_empty_filename_LDFLAGS = libcbio.la
tests_test_create_database_SOURCES = tests/testapp.c
+tests_test_create_database_DEPENDENCIES = libcbio.la
tests_test_create_database_LDFLAGS = libcbio.la
tests_test_get_hit_SOURCES = tests/testapp.c
+tests_test_get_hit_DEPENDENCIES = libcbio.la
tests_test_get_hit_LDFLAGS = libcbio.la
tests_test_get_miss_SOURCES = tests/testapp.c
+tests_test_get_miss_DEPENDENCIES = libcbio.la
tests_test_get_miss_LDFLAGS = libcbio.la
tests_test_store_single_document_SOURCES = tests/testapp.c
+tests_test_store_single_document_DEPENDENCIES = libcbio.la
tests_test_store_single_document_LDFLAGS = libcbio.la
tests_test_delete_document_SOURCES = tests/testapp.c
+tests_test_delete_document_DEPENDENCIES = libcbio.la
tests_test_delete_document_LDFLAGS = libcbio.la
tests_test_delete_nonexistent_document_SOURCES = tests/testapp.c
+tests_test_delete_nonexistent_document_DEPENDENCIES = libcbio.la
tests_test_delete_nonexistent_document_LDFLAGS = libcbio.la
tests_test_get_deleted_document_SOURCES = tests/testapp.c
+tests_test_get_deleted_document_DEPENDENCIES = libcbio.la
tests_test_get_deleted_document_LDFLAGS = libcbio.la
tests_test_bulk_store_documents_SOURCES = tests/testapp.c
+tests_test_bulk_store_documents_DEPENDENCIES = libcbio.la
tests_test_bulk_store_documents_LDFLAGS = libcbio.la
tests_test_changes_since_SOURCES = tests/testapp.c
+tests_test_changes_since_DEPENDENCIES = libcbio.la
tests_test_changes_since_LDFLAGS = libcbio.la
17 src/document.c
View
@@ -20,6 +20,16 @@
#include <stdlib.h>
#include <string.h>
+int cbio_is_local_id(const void *data, size_t nb)
+{
+ return (nb > 6 && memcmp(data, "_local/", 7) == 0) ? 1 : 0;
+}
+
+int cbio_is_local_document(DocInfo *info)
+{
+ return cbio_is_local_id(info->id.buf, info->id.size);
+}
+
LIBCBIO_API
void cbio_document_release(libcbio_document_t doc)
{
@@ -50,7 +60,11 @@ void cbio_document_reinitialize(libcbio_document_t doc)
free(doc->doc);
} else {
if (doc->info != NULL) {
- couchstore_free_docinfo(doc->info);
+ if (cbio_is_local_document(doc->info)) {
+ couchstore_free_local_document((LocalDoc*)doc->info);
+ } else {
+ couchstore_free_docinfo(doc->info);
+ }
}
if (doc->doc) {
couchstore_free_document(doc->doc);
@@ -101,7 +115,6 @@ cbio_error_t cbio_document_set_id(libcbio_document_t doc,
return CBIO_SUCCESS;
}
-
LIBCBIO_API
cbio_error_t cbio_document_set_meta(libcbio_document_t doc,
const void *meta,
45 src/instance.c
View
@@ -68,6 +68,17 @@ off_t cbio_get_header_position(libcbio_t handle)
return (off_t)couchstore_get_header_position(handle->couchstore_handle);
}
+static cbio_error_t cbio_get_local_document(libcbio_t handle,
+ const void *id,
+ size_t nid,
+ libcbio_document_t doc)
+{
+ couchstore_error_t err;
+ err = couchstore_open_local_document(handle->couchstore_handle, id,
+ nid, (LocalDoc**)&doc->info);
+ return cbio_remap_error(err);
+}
+
LIBCBIO_API
cbio_error_t cbio_get_document(libcbio_t handle,
const void *id,
@@ -81,7 +92,18 @@ cbio_error_t cbio_get_document(libcbio_t handle,
return CBIO_ERROR_ENOMEM;
}
- err = couchstore_docinfo_by_id(handle->couchstore_handle, id, nid, &ret->info);
+ if (cbio_is_local_id(id, nid)) {
+ cbio_error_t e = cbio_get_local_document(handle, id, nid, ret);
+ if (e == CBIO_SUCCESS) {
+ *doc = ret;
+ } else {
+ cbio_document_release(ret);
+ }
+ return e;
+ }
+
+ err = couchstore_docinfo_by_id(handle->couchstore_handle, id,
+ nid, &ret->info);
if (err != COUCHSTORE_SUCCESS) {
cbio_document_release(ret);
return cbio_remap_error(err);
@@ -109,6 +131,21 @@ cbio_error_t cbio_store_document(libcbio_t handle,
return cbio_store_documents(handle, &doc, 1);
}
+static cbio_error_t cbio_store_local_documents(libcbio_t handle,
+ libcbio_document_t *doc,
+ size_t ndocs)
+{
+ for (int ii = 0; ii < ndocs; ++ii) {
+ couchstore_error_t err;
+ err = couchstore_save_local_document(handle->couchstore_handle,
+ (LocalDoc *)doc[ii]->info);
+ if (err != COUCHSTORE_SUCCESS) {
+ return cbio_remap_error(err);
+ }
+ }
+ return CBIO_SUCCESS;
+}
+
LIBCBIO_API
cbio_error_t cbio_store_documents(libcbio_t handle,
libcbio_document_t *doc,
@@ -119,10 +156,14 @@ cbio_error_t cbio_store_documents(libcbio_t handle,
size_t ii;
couchstore_error_t err;
- if (handle->mode == CBIO_OPEN_RDONLY) {
+ if (handle->mode == CBIO_OPEN_RDONLY || ndocs == 0) {
return CBIO_ERROR_EINVAL;
}
+ if (cbio_is_local_document(doc[0]->info)) {
+ return cbio_store_local_documents(handle, doc, ndocs);
+ }
+
docs = calloc(ndocs, sizeof(Doc *));
info = calloc(ndocs, sizeof(DocInfo *));
if (docs == NULL || info == NULL) {
2  src/internal.h
View
@@ -44,5 +44,7 @@ struct libcbio_document_st {
};
cbio_error_t cbio_remap_error(couchstore_error_t in);
+int cbio_is_local_id(const void *data, size_t nb);
+int cbio_is_local_document(DocInfo *info);
#endif
8 tests/testapp.c
View
@@ -117,6 +117,14 @@ static int get_miss(void)
return 1;
}
+ err = cbio_get_document(handle, "_local/hi-there",
+ sizeof("_local/hi-there"), &doc);
+ if (err != CBIO_ERROR_ENOENT) {
+ report("I did not expect to find \"_local/hi-there\" in the database"
+ ", but I got \"%s\"", cbio_strerror(err));
+ return 1;
+ }
+
cbio_close_handle(handle);
return 0;
}

No commit comments for this range

Something went wrong with that request. Please try again.