Use Util.Persistent to reimplemented promoted files store
Signed-off-by: Rudi Grinberg <rudi.grinberg@gmail.com>
This commit is contained in:
parent
af6f003d13
commit
2a80d034fa
|
@ -10,6 +10,11 @@ let alias_dir = Path.(relative build_dir) ".aliases"
|
||||||
let misc_dir = Path.(relative build_dir) ".misc"
|
let misc_dir = Path.(relative build_dir) ".misc"
|
||||||
|
|
||||||
module Promoted_to_delete = struct
|
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 db = ref []
|
||||||
|
|
||||||
let fn = Path.relative Path.build_dir ".to-delete-in-source-tree"
|
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 add p = db := p :: !db
|
||||||
|
|
||||||
let load () =
|
let load () =
|
||||||
if Path.exists fn then
|
Option.value ~default:[] (P.load fn)
|
||||||
Io.Sexp.load fn ~mode:Many
|
|
||||||
|> List.map ~f:(Sexp.Of_sexp.parse Path.t Univ_map.empty)
|
|
||||||
else
|
|
||||||
[]
|
|
||||||
|
|
||||||
let dump () =
|
let dump () =
|
||||||
let db = Path.Set.union (Path.Set.of_list !db) (Path.Set.of_list (load ())) in
|
|
||||||
if Path.build_dir_exists () then
|
if Path.build_dir_exists () then
|
||||||
Io.write_file fn
|
load ()
|
||||||
(String.concat ~sep:""
|
|> Path.Set.of_list
|
||||||
(List.map (Path.Set.to_list db) ~f:(fun p ->
|
|> Path.Set.union (Path.Set.of_list !db)
|
||||||
Sexp.to_string ~syntax:Dune (Path.sexp_of_t p) ^ "\n")))
|
|> Path.Set.to_list
|
||||||
|
|> P.dump fn
|
||||||
end
|
end
|
||||||
|
|
||||||
let files_in_source_tree_to_delete () =
|
let files_in_source_tree_to_delete () =
|
||||||
|
|
Loading…
Reference in New Issue