aboutsummaryrefslogtreecommitdiff
path: root/stdlib/source/program/aedifex/repository
diff options
context:
space:
mode:
authorEduardo Julian2021-07-06 21:34:21 -0400
committerEduardo Julian2021-07-06 21:34:21 -0400
commit2b909032e7a0bd10cd7db52067d2fb701bfa95e5 (patch)
tree0e2aaef228f80f3336715327f7f34065c309de22 /stdlib/source/program/aedifex/repository
parent5cf4efa861075f8276f43a2516f5beacaf610b44 (diff)
Simplified the API for file-system operations.
Diffstat (limited to 'stdlib/source/program/aedifex/repository')
-rw-r--r--stdlib/source/program/aedifex/repository/local.lux62
-rw-r--r--stdlib/source/program/aedifex/repository/remote.lux2
2 files changed, 32 insertions, 32 deletions
diff --git a/stdlib/source/program/aedifex/repository/local.lux b/stdlib/source/program/aedifex/repository/local.lux
index 8ceaf5ffc..b4ba0e22c 100644
--- a/stdlib/source/program/aedifex/repository/local.lux
+++ b/stdlib/source/program/aedifex/repository/local.lux
@@ -1,10 +1,9 @@
(.module:
[lux #*
- [ffi (#+ import:)]
[abstract
[monad (#+ do)]]
[control
- ["." try (#+ Try)]
+ ["." try]
[concurrency
["." promise (#+ Promise)]]]
[data
@@ -12,7 +11,7 @@
["%" format (#+ format)]]]
[world
[program (#+ Program)]
- ["." file (#+ Path File)]
+ ["." file]
[net
["." uri (#+ URI)]]]]
["." //
@@ -21,40 +20,39 @@
["#." metadata]]])
(def: (root /)
- (-> Text Path)
+ (-> Text file.Path)
(text.replace_all uri.separator / ///local.repository))
-(def: path
- (-> Text URI Path)
- (text.replace_all uri.separator))
+(def: (path /)
+ (-> Text (-> URI file.Path))
+ (text.replace_all uri.separator /))
-(def: (file program system create? uri)
- (-> (Program Promise)
- (file.System Promise)
- Bit
- URI
- (Promise (Try (File Promise))))
- (let [uri (text.replace_once ///metadata.remote_file ///metadata.local_file uri)
- / (\ system separator)
- absolute_path (format (..root /) / (..path / uri))]
- (if create?
- (do {! (try.with promise.monad)}
- [_ (: (Promise (Try Path))
- (file.make_directories promise.monad system (file.parent system absolute_path)))]
- (: (Promise (Try (File Promise)))
- (file.get_file promise.monad system absolute_path)))
- (: (Promise (Try (File Promise)))
- (\ system file absolute_path)))))
+(def: (absolute_path /)
+ (-> Text (-> URI file.Path))
+ (|>> ///metadata.local_uri
+ (..path /)
+ (format (..root /) /)))
-(implementation: #export (repository program system)
+(implementation: #export (repository program fs)
(-> (Program Promise) (file.System Promise) (//.Repository Promise))
- (def: (download uri)
- (do {! (try.with promise.monad)}
- [file (..file program system false uri)]
- (\ file content [])))
+ (def: description
+ (..root (\ fs separator)))
+ (def: download
+ (|>> (..absolute_path (\ fs separator))
+ (\ fs read)))
(def: (upload uri content)
- (do {! (try.with promise.monad)}
- [file (..file program system true uri)]
- (\ file over_write content))))
+ (do {! promise.monad}
+ [#let [absolute_path (..absolute_path (\ fs separator) uri)]
+ ? (\ fs file? absolute_path)
+ _ (if ?
+ (wrap [])
+ (case (file.parent fs absolute_path)
+ (#.Some parent)
+ (file.make_directories promise.monad fs parent)
+
+ _
+ (let [! (try.with promise.monad)]
+ (\ ! wrap []))))]
+ (\ fs write content absolute_path))))
diff --git a/stdlib/source/program/aedifex/repository/remote.lux b/stdlib/source/program/aedifex/repository/remote.lux
index 50115f123..7feaa9710 100644
--- a/stdlib/source/program/aedifex/repository/remote.lux
+++ b/stdlib/source/program/aedifex/repository/remote.lux
@@ -56,6 +56,8 @@
(implementation: #export (repository http identity address)
(All [s] (-> (http.Client IO) (Maybe Identity) Address (//.Repository IO)))
+ (def: description
+ address)
(def: (download uri)
(do {! (try.with io.monad)}
[[status message] (: (IO (Try (@http.Response IO)))