From b147fbccd1228358a1d346ef6e9e0a9487fd164a Mon Sep 17 00:00:00 2001 From: adam Date: Mon, 15 Jul 2013 12:31:26 +0700 Subject: [PATCH] #59 #72 --- .gitignore | 1 + tcejdb/ejdb.c | 9 +++++---- tcejdb/ejdb.h | 18 ++++++++++++++++-- 3 files changed, 22 insertions(+), 6 deletions(-) diff --git a/.gitignore b/.gitignore index 662db7c..76e490d 100644 --- a/.gitignore +++ b/.gitignore @@ -83,6 +83,7 @@ config.status /tcejdb/testejdb/t2 /tcejdb/testejdb/t3 /tcejdb/testejdb/t4 +/tcejdb/testejdb/test* */nbproject/private/* diff --git a/tcejdb/ejdb.c b/tcejdb/ejdb.c index 649e074..566e913 100644 --- a/tcejdb/ejdb.c +++ b/tcejdb/ejdb.c @@ -954,9 +954,7 @@ bool ejdbexport(EJDB *jb, const char *path, TCLIST *cnames, int flags) { assert(jb && path); bool err = false; bool isdir = false; - if (!tcstatfile(path, &isdir, NULL, NULL)) { - return false; - } + tcstatfile(path, &isdir, NULL, NULL); if (!isdir) { if (mkdir(path, 00755)) { _ejdbsetecode(jb, TCEMKDIR, __FILE__, __LINE__, __func__); @@ -997,7 +995,7 @@ finish: static bool _exportcoll(EJCOLL *coll, const char *dpath, int flags) { bool err = false; - char *fpath = tcsprintf("%s%c%s%s", dpath, MYPATHCHR, coll->cname, ".bson"); + char *fpath = tcsprintf("%s%c%s%s", dpath, MYPATHCHR, coll->cname, (flags & JBJSONEXPORT) ? ".json" : ".bson"); char *fpathm = tcsprintf("%s%c%s%s", dpath, MYPATHCHR, coll->cname, "-meta.json"); TCHDB *hdb = coll->tdb->hdb; TCXSTR *skbuf = tcxstrnew3(sizeof (bson_oid_t) + 1); @@ -1073,6 +1071,9 @@ wfinish: } } bson_finish(&mbs); + bson_print_raw(bson_data(&mbs), 0); + + char *wbuf = NULL; int wsiz; if (bson2json(bson_data(&mbs), &wbuf, &wsiz) != BSON_OK) { diff --git a/tcejdb/ejdb.h b/tcejdb/ejdb.h index fcaf726..92c24f6 100644 --- a/tcejdb/ejdb.h +++ b/tcejdb/ejdb.h @@ -503,20 +503,34 @@ EJDB_EXPORT bson* ejdbmeta(EJDB *jb); /** Export settings */ enum { - JBJSONEXPORT = 1 //If set json collection data will be exported into JSON instead of BSON + JBJSONEXPORT = 1, //If set json collection data will be exported into JSON instead of BSON. + JBIMPORTUPDATE = 2, //Update existing collection entries with imported ones. Collection options are ignored. + JBIMPORTREPLACE = 3 //Recreate existing collections and replace all collection entries with imported data. + }; /** * Export database collections data to the specified location. * Database read lock will be taken on each collection * @param path Directory name in which data will exported. - * @param colnames List of collection names to export. If NULL all collections will be exported. + * @param colnames List of collection names to export. If its value is `NULL` then all existing collections will be exported. * @param flags. Can be set to `JBJSONEXPORT` in order to export collection data into JSON instead of BSON. * @return on sucess `true` */ EJDB_EXPORT bool ejdbexport(EJDB *jb, const char *path, TCLIST *cnames, int flags); +/** + * + * @param jb + * @param path + * @param cnames + * @param flags + * @return + */ +EJDB_EXPORT bool ejdbimport(EJDB *jb, const char *path, TCLIST *cnames, int flags); + + EJDB_EXTERN_C_END #endif /* EJDB_H */ -- 2.7.4