From d99c47989a1047cd24019fd5ce434e701b5d3519 Mon Sep 17 00:00:00 2001 From: Eduardo Julian Date: Sun, 7 Feb 2021 04:56:58 -0400 Subject: Mo' updates, less problems. --- stdlib/source/program/aedifex/repository/local.lux | 22 +++++++++----- .../source/program/aedifex/repository/remote.lux | 34 ++++++++++++---------- 2 files changed, 32 insertions(+), 24 deletions(-) (limited to 'stdlib/source/program/aedifex/repository') diff --git a/stdlib/source/program/aedifex/repository/local.lux b/stdlib/source/program/aedifex/repository/local.lux index f313b3176..7ac384efa 100644 --- a/stdlib/source/program/aedifex/repository/local.lux +++ b/stdlib/source/program/aedifex/repository/local.lux @@ -19,7 +19,8 @@ ["." uri (#+ URI)]]]] ["." // ["/#" // #_ - ["#." local]]]) + ["#." local] + ["#." metadata]]]) (def: (root /) (-> Text Path) @@ -29,18 +30,23 @@ (-> Text URI Path) (text.replace_all uri.separator)) -(def: (file program system uri) +(def: (file program system create? uri) (-> (Program Promise) (file.System Promise) + Bit URI (Promise (Try (File Promise)))) (do {! promise.monad} - [home (\ program home []) + [#let [uri (text.replace_once ///metadata.remote_file ///metadata.local_file uri)] + home (\ program home []) #let [/ (\ system separator) absolute_path (format home / (..root /) / (..path / uri))]] - (do {! (try.with !)} - [_ (: (Promise (Try Path)) - (file.make_directories promise.monad system (file.parent system absolute_path)))] + (if create? + (do {! (try.with !)} + [_ (: (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))) (!.use (\ system file) absolute_path))))) @@ -49,10 +55,10 @@ (def: (download uri) (do {! (try.with promise.monad)} - [file (..file program system uri)] + [file (..file program system false uri)] (!.use (\ file content) []))) (def: (upload uri content) (do {! (try.with promise.monad)} - [file (..file program system uri)] + [file (..file program system true uri)] (!.use (\ file over_write) [content])))) diff --git a/stdlib/source/program/aedifex/repository/remote.lux b/stdlib/source/program/aedifex/repository/remote.lux index 4979e5429..4b61bc36c 100644 --- a/stdlib/source/program/aedifex/repository/remote.lux +++ b/stdlib/source/program/aedifex/repository/remote.lux @@ -26,7 +26,7 @@ ["." // ["#." identity (#+ Identity)] ["/#" // #_ - ["#." artifact (#+ Artifact) + ["#." artifact (#+ Version Artifact) [extension (#+ Extension)]]]]) (type: #export Address @@ -75,9 +75,9 @@ (exception.report ["Code" (%.int code)])) -(def: #export (uri artifact extension) - (-> Artifact Extension URI) - (format (///artifact.uri artifact) extension)) +(def: #export (uri version_template artifact extension) + (-> Version Artifact Extension URI) + (format (///artifact.uri version_template artifact) extension)) (def: buffer_size (n.* 512 1,024)) @@ -99,19 +99,21 @@ input (|> connection java/net/URLConnection::getInputStream (\ ! map (|>> java/io/BufferedInputStream::new))) - #let [buffer (binary.create ..buffer_size)]] - (loop [output (\ binary.monoid identity)] - (do ! - [bytes_read (java/io/BufferedInputStream::read buffer +0 (.int ..buffer_size) input)] - (case bytes_read - -1 (do ! - [_ (java/lang/AutoCloseable::close input)] - (wrap output)) - _ (if (n.= ..buffer_size bytes_read) - (recur (\ binary.monoid compose output buffer)) + #let [buffer (binary.create ..buffer_size)] + output (loop [output (\ binary.monoid identity)] (do ! - [chunk (\ io.monad wrap (binary.slice 0 (.nat bytes_read) buffer))] - (recur (\ binary.monoid compose output chunk))))))))) + [bytes_read (java/io/BufferedInputStream::read buffer +0 (.int ..buffer_size) input)] + (case bytes_read + -1 (do ! + [_ (java/lang/AutoCloseable::close input)] + (wrap output)) + +0 (recur output) + _ (if (n.= ..buffer_size bytes_read) + (recur (\ binary.monoid compose output buffer)) + (do ! + [chunk (\ io.monad wrap (binary.slice 0 (dec (.nat bytes_read)) buffer))] + (recur (\ binary.monoid compose output chunk)))))))] + (wrap output))) (def: (upload uri content) (case identity -- cgit v1.2.3