aboutsummaryrefslogtreecommitdiff
path: root/CLPM/Package.icl
diff options
context:
space:
mode:
Diffstat (limited to 'CLPM/Package.icl')
-rw-r--r--CLPM/Package.icl38
1 files changed, 38 insertions, 0 deletions
diff --git a/CLPM/Package.icl b/CLPM/Package.icl
index 3f3001f..fedb224 100644
--- a/CLPM/Package.icl
+++ b/CLPM/Package.icl
@@ -19,8 +19,12 @@ import Data.Functor
import Data.List
import Data.Tuple
+import Internet.HTTP
+
+import System.Directory
import System.File
import System.FilePath
+import System.Platform
from Text import class Text(indexOf,subString),
instance Text String, instance + String
@@ -247,3 +251,37 @@ optionsToFlags opts
++ ["-h " + toString opts.Options.heap_size + "k"]
++ ["-s " + toString opts.Options.stack_size + "k"]
++ opts.Options.extra_flags
+
+install :: Dependency Version *World -> *(MaybeErrorString (), *World)
+install d v w
+# (tar,w) = doRequest req w
+| isError tar
+ = (Error $ fromError tar, w)
+# (err,w) = writeFile (depName d + ".tar.gz") (fromOk tar).rsp_data w
+| isError err
+ = (Error $ toString (fromError err) + " while installing " + depName d + ".", w)
+# (err,w) = createDirectory (MODULE_DIR </> depName d) w
+| isError err
+ = (Error $ snd (fromError err) + " while installing " + depName d + ".", w)
+# (r,w) = syscall ("tar xzf '" + depName d + ".tar.gz' -C '" + MODULE_DIR </> depName d + "' --strip-components=1\0") w
+# (err,w) = deleteFile (depName d + ".tar.gz") w
+| r <> 0
+ = (Error $ "Failed to unpack " + depName d + ".tar.gz.", w)
+| isError err
+ = (Error $ snd (fromError err) + " while installing " + depName d + ".", w)
+= (Ok (), w)
+where
+ req =
+ { newHTTPRequest
+ & req_path = "/repo/" + depName d + "/" + toString v + "/" + platform + ".tar.gz"
+ , server_name = REPOSITORY
+ , server_port = PORT
+ }
+
+ platform :: String
+ platform = case CURRENT_PLATFORM of
+ Linux32 = "linux32"
+ Linux64 = "linux64"
+ Mac = "mac"
+ Windows32 = "win32"
+ Windows64 = "win64"