aboutsummaryrefslogtreecommitdiffstats
path: root/lib/Scratch.ml
blob: 0779db3889dad03b73f888a8532d5eb449fcf1a6 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
module LMDB = Backend.Storage.LMDB
module I = Kernel.Initialization.Make (LMDB)

let rec remove path =
  if Sys.is_directory path then begin
    Array.iter (fun name -> remove (Filename.concat path name)) (Sys.readdir path);
    Sys.rmdir path
  end
  else Sys.remove path

let root ?(evaluators = ["fol", Evaluators.FOL.make ()]) () =
  let open Utilities.Result in
  let directory = Filename.temp_dir "rnt-scratch" "" in
  let* connection =
    Sexplib.Sexp.(
      List [Atom "lmdb"; List [Atom "path"; Atom directory]; List [Atom "mode"; Atom "420"]] )
    |> Concepts.Configuration.term_of_sexp
    |> LMDB.connect
  in
  at_exit (fun () ->
      LMDB.disconnect connection;
      try remove directory with Sys_error _ -> () );
  I.initialize ~evaluators connection