static int si_dropmark(si *i, sr *r) { /* create drop file */ char path[1024]; snprintf(path, sizeof(path), "%s/drop", i->conf->path); srfile drop; sr_fileinit(&drop, r->a); int rc = sr_filenew(&drop, path); if (srunlikely(rc == -1)) { sr_malfunction(r->e, "drop file '%s' create error: %s", path, strerror(errno)); return -1; } sr_fileclose(&drop); return 0; }
int si_nodecreate(sinode *n, sr *r, siconf *conf, sdid *id, sdindex *i, sdbuild *build) { si_branchset(&n->self, i); srpath path; sr_pathAB(&path, conf->path, id->parent, id->id, ".db.incomplete"); int rc = sr_filenew(&n->file, path.path); if (srunlikely(rc == -1)) { sr_malfunction(r->e, "db file '%s' create error: %s", path.path, strerror(errno)); return -1; } rc = sd_buildwrite(build, r, &n->self.index, &n->file); if (srunlikely(rc == -1)) return -1; n->branch = &n->self; n->branch_count++; return 0; }
sd_indexinit(&index); t( sd_indexbegin(&index, &r, 0) == 0 ); int rc; rc = sd_indexadd(&index, &r, &b); t( rc == 0 ); t( sd_buildcommit(&b) == 0 ); sdid id; memset(&id, 0, sizeof(id)); t( sd_indexcommit(&index, &r, &id) == 0 ); srfile f; sr_fileinit(&f, &a); t( sr_filenew(&f, "./0000.db") == 0 ); t( sd_commit(&b, &r, &index, &f) == 0 ); srmap map; t( sr_mapfile(&map, &f, 1) == 0 ); sdindex i; sd_indexinit(&i); i.h = (sdindexheader*)(map.p); sriter it; sr_iterinit(sd_iter, &it, &r); sr_iteropen(sd_iter, &it, &i, map.p, 1, 0, NULL); t( sr_iteratorhas(&it) == 1 ); sv *v = sr_iteratorof(&it); t( *(int*)sv_key(v, &r, 0) == 7);