blob: addb978210e033939a0b8ea5d63707b3367b4140 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
|
(.using
[library
[lux (.except)
[abstract
[predicate (.only Predicate)]
["[0]" monad (.only Monad do)]]
[control
["[0]" try (.only Try) (.open: "[1]#[0]" functor)]
[concurrency
["[0]" async (.only Async)]]]
[data
["[0]" text (.open: "[1]#[0]" equivalence)]
[collection
["[0]" list (.open: "[1]#[0]" mix functor)]
["[0]" dictionary (.only Dictionary)]
["[0]" set]]]
[math
[number
["n" nat]]]
[world
["[0]" file]]]]
["[0]" //
["[1][0]" module]
["[0]" dependency
["[1]" module]]
["/[1]" //
[context (.only Context)]
["/[1]" // (.only Input)]
["[0]" archive (.only)
[registry (.only Registry)]
["[0]" module (.only)
["[0]" descriptor (.only Descriptor)]]]]])
(type: .public Cache
[Bit descriptor.Module module.ID (module.Module Any) Registry])
(type: .public Purge
(Dictionary descriptor.Module module.ID))
... TODO: Make the monad parameterizable.
(def: .public (purge! fs context @module)
(-> (file.System Async) Context module.ID (Async (Try Any)))
(do [! (try.with async.monad)]
[.let [cache (//module.path fs context @module)]
_ (|> cache
(at fs directory_files)
(at ! each (monad.each ! (at fs delete)))
(at ! conjoint))]
(at fs delete cache)))
(def: .public (valid? expected actual)
(-> Descriptor Input Bit)
(and (text#= (the descriptor.#name expected)
(the ////.#module actual))
(text#= (the descriptor.#file expected)
(the ////.#file actual))
(n.= (the descriptor.#hash expected)
(the ////.#hash actual))))
(def: initial
(-> (List Cache) Purge)
(|>> (list.all (function (_ [valid? module_name @module _])
(if valid?
{.#None}
{.#Some [module_name @module]})))
(dictionary.of_list text.hash)))
(def: .public (purge caches load_order)
(-> (List Cache) (dependency.Order Any) Purge)
(list#mix (function (_ [module_name [@module entry]] purge)
(let [purged? (is (Predicate descriptor.Module)
(dictionary.key? purge))]
(if (purged? module_name)
purge
(if (|> entry
(the [archive.#module module.#descriptor descriptor.#references])
set.list
(list.any? purged?))
(dictionary.has module_name @module purge)
purge))))
(..initial caches)
load_order))
|