示例#1
0
/* perform optimize command */
static int procoptimize(const char *path, int lmemb, int nmemb,
        int bnum, int apow, int fpow, TCCMP cmp, int opts, int omode, bool df) {
    TCBDB *bdb = tcbdbnew();
    if (!INVALIDHANDLE(g_dbgfd)) tcbdbsetdbgfd(bdb, g_dbgfd);
    if (cmp && !tcbdbsetcmpfunc(bdb, cmp, NULL)) printerr(bdb);
    if (!tcbdbsetcodecfunc(bdb, _tc_recencode, NULL, _tc_recdecode, NULL)) printerr(bdb);
    if (!tcbdbopen(bdb, path, BDBOWRITER | omode)) {
        printerr(bdb);
        tcbdbdel(bdb);
        return 1;
    }
    bool err = false;
    if (df) {
        if (!tcbdbdefrag(bdb, INT64_MAX)) {
            printerr(bdb);
            err = true;
        }
    } else {
        if (!tcbdboptimize(bdb, lmemb, nmemb, bnum, apow, fpow, opts)) {
            printerr(bdb);
            err = true;
        }
    }
    if (!tcbdbclose(bdb)) {
        if (!err) printerr(bdb);
        err = true;
    }
    tcbdbdel(bdb);
    return err ? 1 : 0;
}
示例#2
0
static int
dfrg(rotz_t ctx)
{
	if (!tcbdbdefrag(ctx->db, INT64_MAX)) {
		return -1;
	}
	return 0;
}