2020-02-01 21:06:35 +03:00
|
|
|
module System.Directory
|
|
|
|
|
|
|
|
import public System.File
|
|
|
|
|
2020-02-01 21:43:28 +03:00
|
|
|
toFileError : Int -> FileError
|
|
|
|
toFileError 1 = FileReadError
|
|
|
|
toFileError 2 = FileWriteError
|
|
|
|
toFileError 3 = FileNotFound
|
|
|
|
toFileError 4 = PermissionDenied
|
|
|
|
toFileError x = GenericFileError (x - 256)
|
2020-02-01 21:06:35 +03:00
|
|
|
|
2020-02-01 21:43:28 +03:00
|
|
|
fpure : Either Int a -> IO (Either FileError a)
|
|
|
|
fpure (Left err) = pure (Left (toFileError err))
|
|
|
|
fpure (Right x) = pure (Right x)
|
2020-02-01 21:06:35 +03:00
|
|
|
|
2020-02-01 21:43:28 +03:00
|
|
|
%foreign "scheme:blodwen-current-directory"
|
|
|
|
prim_currentDir : PrimIO String
|
2020-02-01 21:06:35 +03:00
|
|
|
|
2020-02-01 21:43:28 +03:00
|
|
|
%foreign "scheme:blodwen-change-directory"
|
|
|
|
prim_changeDir : String -> PrimIO Int
|
2020-02-01 21:06:35 +03:00
|
|
|
|
2020-02-01 21:43:28 +03:00
|
|
|
%foreign "scheme:blodwen-create-directory"
|
|
|
|
prim_createDir : String -> PrimIO (Either Int ())
|
2020-02-01 21:06:35 +03:00
|
|
|
|
|
|
|
export
|
|
|
|
createDir : String -> IO (Either FileError ())
|
2020-02-01 21:43:28 +03:00
|
|
|
createDir dir
|
|
|
|
= do ok <- primIO (prim_createDir dir)
|
|
|
|
fpure ok
|
2020-02-01 21:06:35 +03:00
|
|
|
|
|
|
|
export
|
|
|
|
changeDir : String -> IO Bool
|
2020-02-01 21:43:28 +03:00
|
|
|
changeDir dir
|
|
|
|
= do ok <- primIO (prim_changeDir dir)
|
|
|
|
pure (ok /= 0)
|
2020-02-01 21:06:35 +03:00
|
|
|
|
|
|
|
export
|
|
|
|
currentDir : IO String
|
2020-02-01 21:43:28 +03:00
|
|
|
currentDir = primIO prim_currentDir
|