Use Util.Persistent to reimplemented promoted files store

Signed-off-by: Rudi Grinberg <rudi.grinberg@gmail.com>
This commit is contained in:
Rudi Grinberg 2018-06-28 15:06:35 +06:30
parent af6f003d13
commit 2a80d034fa
1 changed files with 11 additions and 10 deletions

View File

@ -10,6 +10,11 @@ let alias_dir = Path.(relative build_dir) ".aliases"
let misc_dir = Path.(relative build_dir) ".misc"
module Promoted_to_delete = struct
module P = Utils.Persistent(struct
type t = Path.t list
let name = "PROMOTED-TO-DELETE"
let version = 1
end)
let db = ref []
let fn = Path.relative Path.build_dir ".to-delete-in-source-tree"
@ -17,19 +22,15 @@ module Promoted_to_delete = struct
let add p = db := p :: !db
let load () =
if Path.exists fn then
Io.Sexp.load fn ~mode:Many
|> List.map ~f:(Sexp.Of_sexp.parse Path.t Univ_map.empty)
else
[]
Option.value ~default:[] (P.load fn)
let dump () =
let db = Path.Set.union (Path.Set.of_list !db) (Path.Set.of_list (load ())) in
if Path.build_dir_exists () then
Io.write_file fn
(String.concat ~sep:""
(List.map (Path.Set.to_list db) ~f:(fun p ->
Sexp.to_string ~syntax:Dune (Path.sexp_of_t p) ^ "\n")))
load ()
|> Path.Set.of_list
|> Path.Set.union (Path.Set.of_list !db)
|> Path.Set.to_list
|> P.dump fn
end
let files_in_source_tree_to_delete () =