+ BFiles bfs = (BFiles) xmalloc(sizeof(*bfs));
+ bfs->commit_area = 0;
+ bfs->base = 0;
+ bfs->cache_fname = 0;
+ if (base)
+ bfs->base = xstrdup(base);
+ bfs->register_area = mf_init("register", spec, base, 0);
+ if (!bfs->register_area)
+ {
+ bfs_destroy(bfs);
+ return 0;
+ }
+ return bfs;
+}
+
+void bfs_destroy(BFiles bfs)
+{
+ if (!bfs)
+ return;
+ xfree(bfs->cache_fname);
+ xfree(bfs->base);
+ mf_destroy(bfs->commit_area);
+ mf_destroy(bfs->register_area);
+ xfree(bfs);
+}
+
+static FILE *open_cache(BFiles bfs, const char *flags)
+{
+ FILE *file;
+
+ file = fopen(bfs->cache_fname, flags);
+ return file;
+}
+
+static void unlink_cache(BFiles bfs)
+{
+ if (bfs->cache_fname)
+ unlink(bfs->cache_fname);
+}
+
+ZEBRA_RES bf_cache(BFiles bfs, const char *spec)
+{
+ if (spec)
+ {
+ yaz_log(YLOG_LOG, "enabling shadow spec=%s", spec);
+ if (!bfs->commit_area)
+ bfs->commit_area = mf_init("shadow", spec, bfs->base, 1);
+ if (bfs->commit_area)
+ {
+ bfs->cache_fname = xmalloc(strlen(bfs->commit_area->dirs->name)+
+ 8);
+ strcpy(bfs->cache_fname, bfs->commit_area->dirs->name);
+ strcat(bfs->cache_fname, "/cache");
+ yaz_log(YLOG_LOG, "cache_fname = %s", bfs->cache_fname);
+ }
+ else
+ {
+ yaz_log(YLOG_WARN, "shadow could not be enabled");
+ return ZEBRA_FAIL;
+ }
+ }
+ else
+ bfs->commit_area = 0;
+ return ZEBRA_OK;