aboutsummaryrefslogtreecommitdiff
path: root/CLPM/Util.icl
diff options
context:
space:
mode:
Diffstat (limited to 'CLPM/Util.icl')
-rw-r--r--CLPM/Util.icl34
1 files changed, 34 insertions, 0 deletions
diff --git a/CLPM/Util.icl b/CLPM/Util.icl
index 2d4004e..282c580 100644
--- a/CLPM/Util.icl
+++ b/CLPM/Util.icl
@@ -15,10 +15,26 @@ import Data.Tuple
import Internet.HTTP
+import System.Directory
+import System.File
+import System.FilePath
+
from Text import instance + String
TIMEOUT :== Just 10000
+instance Parse Int
+where
+ Parse [] = Error "Empty string for Int."
+ Parse cs
+ | all isDigit cs = Ok $ toInt $ toString cs
+ | otherwise = Error "Unexpected character in Int."
+
+instance Parse (Maybe Int)
+where
+ Parse ['?'] = Ok $ Nothing
+ Parse cs = Just <$> Parse cs
+
parse :: (String -> MaybeErrorString a) | Parse a
parse = Parse o fromString
@@ -68,3 +84,21 @@ syscall :: !String !*World -> !*(!Int, !*World)
syscall cmd w = code {
ccall system "s:I:A"
}
+
+recursivelyRemove :: !FilePath !*World -> *(MaybeErrorString (), !*World)
+recursivelyRemove fp w
+| isMember (last $ takeWhile ((<>) "") $ iterate (snd o splitFileName) fp)
+ [".", ".."] = (Ok (), w)
+# (inf,w) = getFileInfo fp w
+| isError inf = cast (inf, w)
+| not (fromOk inf).directory = cast $ deleteFile fp w
+# (fps,w) = readDirectory fp w
+| isError fps = cast (fps,w)
+# (rem,w) = appFst sequence $
+ seqList (map (recursivelyRemove o ((</>) fp)) (fromOk fps)) w
+| isError rem = (Error $ fromError rem,w)
+= cast $ removeDirectory fp w
+where
+ cast :: (MaybeOSError a, *World) -> (MaybeErrorString (), *World)
+ cast (Error e, w) = (Error $ snd e, w)
+ cast (Ok _, w) = (Ok (), w)