Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
  • 2 commits
  • 5 files changed
  • 0 comments
  • 1 contributor
10 Makefile.am
@@ -39,33 +39,43 @@ check_PROGRAMS = tests/test_open_empty_filename \
39 39 TESTS=${check_PROGRAMS}
40 40
41 41 tests_test_open_empty_filename_SOURCES = tests/testapp.c
  42 +tests_test_open_empty_filename_DEPENDENCIES = libcbio.la
42 43 tests_test_open_empty_filename_LDFLAGS = libcbio.la
43 44
44 45 tests_test_create_database_SOURCES = tests/testapp.c
  46 +tests_test_create_database_DEPENDENCIES = libcbio.la
45 47 tests_test_create_database_LDFLAGS = libcbio.la
46 48
47 49 tests_test_get_hit_SOURCES = tests/testapp.c
  50 +tests_test_get_hit_DEPENDENCIES = libcbio.la
48 51 tests_test_get_hit_LDFLAGS = libcbio.la
49 52
50 53 tests_test_get_miss_SOURCES = tests/testapp.c
  54 +tests_test_get_miss_DEPENDENCIES = libcbio.la
51 55 tests_test_get_miss_LDFLAGS = libcbio.la
52 56
53 57 tests_test_store_single_document_SOURCES = tests/testapp.c
  58 +tests_test_store_single_document_DEPENDENCIES = libcbio.la
54 59 tests_test_store_single_document_LDFLAGS = libcbio.la
55 60
56 61 tests_test_delete_document_SOURCES = tests/testapp.c
  62 +tests_test_delete_document_DEPENDENCIES = libcbio.la
57 63 tests_test_delete_document_LDFLAGS = libcbio.la
58 64
59 65 tests_test_delete_nonexistent_document_SOURCES = tests/testapp.c
  66 +tests_test_delete_nonexistent_document_DEPENDENCIES = libcbio.la
60 67 tests_test_delete_nonexistent_document_LDFLAGS = libcbio.la
61 68
62 69 tests_test_get_deleted_document_SOURCES = tests/testapp.c
  70 +tests_test_get_deleted_document_DEPENDENCIES = libcbio.la
63 71 tests_test_get_deleted_document_LDFLAGS = libcbio.la
64 72
65 73 tests_test_bulk_store_documents_SOURCES = tests/testapp.c
  74 +tests_test_bulk_store_documents_DEPENDENCIES = libcbio.la
66 75 tests_test_bulk_store_documents_LDFLAGS = libcbio.la
67 76
68 77 tests_test_changes_since_SOURCES = tests/testapp.c
  78 +tests_test_changes_since_DEPENDENCIES = libcbio.la
69 79 tests_test_changes_since_LDFLAGS = libcbio.la
70 80
71 81
17 src/document.c
@@ -20,6 +20,16 @@
20 20 #include <stdlib.h>
21 21 #include <string.h>
22 22
  23 +int cbio_is_local_id(const void *data, size_t nb)
  24 +{
  25 + return (nb > 6 && memcmp(data, "_local/", 7) == 0) ? 1 : 0;
  26 +}
  27 +
  28 +int cbio_is_local_document(DocInfo *info)
  29 +{
  30 + return cbio_is_local_id(info->id.buf, info->id.size);
  31 +}
  32 +
23 33 LIBCBIO_API
24 34 void cbio_document_release(libcbio_document_t doc)
25 35 {
@@ -50,7 +60,11 @@ void cbio_document_reinitialize(libcbio_document_t doc)
50 60 free(doc->doc);
51 61 } else {
52 62 if (doc->info != NULL) {
53   - couchstore_free_docinfo(doc->info);
  63 + if (cbio_is_local_document(doc->info)) {
  64 + couchstore_free_local_document((LocalDoc*)doc->info);
  65 + } else {
  66 + couchstore_free_docinfo(doc->info);
  67 + }
54 68 }
55 69 if (doc->doc) {
56 70 couchstore_free_document(doc->doc);
@@ -101,7 +115,6 @@ cbio_error_t cbio_document_set_id(libcbio_document_t doc,
101 115 return CBIO_SUCCESS;
102 116 }
103 117
104   -
105 118 LIBCBIO_API
106 119 cbio_error_t cbio_document_set_meta(libcbio_document_t doc,
107 120 const void *meta,
45 src/instance.c
@@ -68,6 +68,17 @@ off_t cbio_get_header_position(libcbio_t handle)
68 68 return (off_t)couchstore_get_header_position(handle->couchstore_handle);
69 69 }
70 70
  71 +static cbio_error_t cbio_get_local_document(libcbio_t handle,
  72 + const void *id,
  73 + size_t nid,
  74 + libcbio_document_t doc)
  75 +{
  76 + couchstore_error_t err;
  77 + err = couchstore_open_local_document(handle->couchstore_handle, id,
  78 + nid, (LocalDoc**)&doc->info);
  79 + return cbio_remap_error(err);
  80 +}
  81 +
71 82 LIBCBIO_API
72 83 cbio_error_t cbio_get_document(libcbio_t handle,
73 84 const void *id,
@@ -81,7 +92,18 @@ cbio_error_t cbio_get_document(libcbio_t handle,
81 92 return CBIO_ERROR_ENOMEM;
82 93 }
83 94
84   - err = couchstore_docinfo_by_id(handle->couchstore_handle, id, nid, &ret->info);
  95 + if (cbio_is_local_id(id, nid)) {
  96 + cbio_error_t e = cbio_get_local_document(handle, id, nid, ret);
  97 + if (e == CBIO_SUCCESS) {
  98 + *doc = ret;
  99 + } else {
  100 + cbio_document_release(ret);
  101 + }
  102 + return e;
  103 + }
  104 +
  105 + err = couchstore_docinfo_by_id(handle->couchstore_handle, id,
  106 + nid, &ret->info);
85 107 if (err != COUCHSTORE_SUCCESS) {
86 108 cbio_document_release(ret);
87 109 return cbio_remap_error(err);
@@ -109,6 +131,21 @@ cbio_error_t cbio_store_document(libcbio_t handle,
109 131 return cbio_store_documents(handle, &doc, 1);
110 132 }
111 133
  134 +static cbio_error_t cbio_store_local_documents(libcbio_t handle,
  135 + libcbio_document_t *doc,
  136 + size_t ndocs)
  137 +{
  138 + for (int ii = 0; ii < ndocs; ++ii) {
  139 + couchstore_error_t err;
  140 + err = couchstore_save_local_document(handle->couchstore_handle,
  141 + (LocalDoc *)doc[ii]->info);
  142 + if (err != COUCHSTORE_SUCCESS) {
  143 + return cbio_remap_error(err);
  144 + }
  145 + }
  146 + return CBIO_SUCCESS;
  147 +}
  148 +
112 149 LIBCBIO_API
113 150 cbio_error_t cbio_store_documents(libcbio_t handle,
114 151 libcbio_document_t *doc,
@@ -119,10 +156,14 @@ cbio_error_t cbio_store_documents(libcbio_t handle,
119 156 size_t ii;
120 157 couchstore_error_t err;
121 158
122   - if (handle->mode == CBIO_OPEN_RDONLY) {
  159 + if (handle->mode == CBIO_OPEN_RDONLY || ndocs == 0) {
123 160 return CBIO_ERROR_EINVAL;
124 161 }
125 162
  163 + if (cbio_is_local_document(doc[0]->info)) {
  164 + return cbio_store_local_documents(handle, doc, ndocs);
  165 + }
  166 +
126 167 docs = calloc(ndocs, sizeof(Doc *));
127 168 info = calloc(ndocs, sizeof(DocInfo *));
128 169 if (docs == NULL || info == NULL) {
2  src/internal.h
@@ -44,5 +44,7 @@ struct libcbio_document_st {
44 44 };
45 45
46 46 cbio_error_t cbio_remap_error(couchstore_error_t in);
  47 +int cbio_is_local_id(const void *data, size_t nb);
  48 +int cbio_is_local_document(DocInfo *info);
47 49
48 50 #endif
8 tests/testapp.c
@@ -117,6 +117,14 @@ static int get_miss(void)
117 117 return 1;
118 118 }
119 119
  120 + err = cbio_get_document(handle, "_local/hi-there",
  121 + sizeof("_local/hi-there"), &doc);
  122 + if (err != CBIO_ERROR_ENOENT) {
  123 + report("I did not expect to find \"_local/hi-there\" in the database"
  124 + ", but I got \"%s\"", cbio_strerror(err));
  125 + return 1;
  126 + }
  127 +
120 128 cbio_close_handle(handle);
121 129 return 0;
122 130 }

No commit comments for this range

Something went wrong with that request. Please try again.