(.module: [lux (#- Module) [abstract ["." monad (#+ Monad do)]] [control ["." try (#+ Try)] ["." exception (#+ exception:)] [concurrency ["." promise (#+ Promise) ("#\." monad)]] [security ["!" capability]] ["<>" parser ["" binary]]] [data [binary (#+ Binary)] ["." text ["%" format (#+ format)]] [collection ["." dictionary (#+ Dictionary)] ["." row]] [format ["." tar]]] [tool [compiler [meta [archive [descriptor (#+ Module)]]]]] [world ["." file (#+ Path File)]]] [// [cli (#+ Library)]]) (def: Action (type (All [a] (Promise (Try a))))) (exception: #export useless_tar_entry) (exception: #export (duplicate {library Library} {module Module}) (exception.report ["Module" (%.text module)] ["Library" (%.text library)])) (type: #export Import (Dictionary Path Binary)) (def: (import_library system library import) (-> (file.System Promise) Library Import (Action Import)) (do (try.with promise.monad) [file (: (Action (File Promise)) (!.use (\ system file) [library])) binary (!.use (\ file content) [])] (promise\wrap (do {! try.monad} [tar (.run tar.parser binary)] (monad.fold ! (function (_ entry import) (case entry (#tar.Normal [path instant mode ownership content]) (let [path (tar.from_path path)] (case (dictionary.try_put path (tar.data content) import) (#try.Success import) (wrap import) (#try.Failure error) (exception.throw ..duplicate [library path]))) _ (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))