aboutsummaryrefslogtreecommitdiff
path: root/stdlib/source/program/compositor/import.lux
blob: d69915cbb66e202942ee1d26f3fe1ad5c6b46898 (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
(.module:
  [lux #*
   [abstract
    ["." monad (#+ Monad do)]]
   [control
    ["." try (#+ Try)]
    ["." exception (#+ exception:)]
    [concurrency
     ["." promise (#+ Promise) ("#@." monad)]]
    [security
     ["!" capability]]
    ["<>" parser
     ["<b>" binary]]]
   [data
    [binary (#+ Binary)]
    ["." text]
    [collection
     ["." dictionary (#+ Dictionary)]
     ["." row]]
    [format
     ["." tar]]]
   [world
    ["." file (#+ Path File)]]]
  [//
   [cli (#+ Library)]])

(def: Action
  (type (All [a] (Promise (Try a)))))

(exception: #export useless-tar-entry)

(type: #export Import
  (Dictionary Path Binary))

(def: (import-library system library import)
  (-> (file.System Promise) Library Import (Action Import))
  (do (try.with promise.monad)
    [library (: (Action (File Promise))
                (!.use (:: system file) [library]))
     binary (!.use (:: library content) [])]
    (promise@wrap
     (do {! try.monad}
       [tar (<b>.run tar.parser binary)]
       (monad.fold ! (function (_ entry import)
                       (case entry
                         (#tar.Normal [path instant mode ownership content])
                         (dictionary.try-put (tar.from-path path)
                                             (tar.data content)
                                             import)
                         
                         _
                         (exception.throw ..useless-tar-entry [])))
                   import
                   (row.to-list tar))))))

(def: #export (import system libraries)
  (-> (file.System Promise) (List Library) (Action Import))
  (monad.fold (: (Monad Action)
                 (try.with promise.monad))
              (..import-library system)
              (dictionary.new text.hash)
              libraries))