on master help sign in
Stop relying on Task in File.IO
commit2760e840dbd32c55c6894e7c5be5c1e6b9343926 authorEvan Czaplicki <evancz@users.noreply.github.com> dateThu 27 Dec 2018, 12:27 (8 years ago) parentc0d4e35
1 file changed+17−31
builder/src/File/IO.hs+17−31
builder/src/File/IO.hs+17−31
@@ -16,7 +16,6 @@ module File.IO
1616
1717
1818import Control.Exception (catch)
19−import Control.Monad.Trans (liftIO)
2019import qualified Data.Binary as Binary
2120import qualified Data.ByteString as BS
2221import qualified Data.ByteString.Internal as BS
@@ -30,45 +29,33 @@ import qualified System.FilePath as FP
3029import qualified System.IO as IO
3130import System.IO.Error (ioeGetErrorType, annotateIOError, modifyIOError)
3231
33−import qualified Elm.PerUserCache as PerUserCache
34−import qualified Reporting.Exit as Exit
35−import qualified Reporting.Exit.Assets as E
36−import qualified Reporting.Task as Task
37−
3832
3933
4034-- BINARY
4135
4236
43−writeBinary :: (Binary.Binary a) => FilePath -> a -> Task.Task ()
37+writeBinary :: (Binary.Binary a) => FilePath -> a -> IO ()
4438writeBinary path value =
45− liftIO $
46− do let dir = FP.dropFileName path
47− Dir.createDirectoryIfMissing True dir
48− Binary.encodeFile path value
39+ do let dir = FP.dropFileName path
40+ Dir.createDirectoryIfMissing True dir
41+ Binary.encodeFile path value
4942
5043
51−readBinary :: (Binary.Binary a) => FilePath -> Task.Task a
44+readBinary :: (Binary.Binary a) => FilePath -> IO (Maybe a)
5245readBinary path =
53− do exists_ <- liftIO (Dir.doesFileExist path)
46+ do exists_ <- Dir.doesFileExist path
5447 if not exists_
55− then throwCorruptBinary path
48+ then return Nothing
5649 else
57− do result <- liftIO (Binary.decodeFileOrFail path)
50+ do result <- Binary.decodeFileOrFail path
5851 case result of
5952 Left _ ->
60− throwCorruptBinary path
53+ return Nothing
6154
6255 Right value ->
6356 return value
6457
6558
66−throwCorruptBinary :: FilePath -> Task.Task a
67−throwCorruptBinary filePath =
68− do elmHome <- liftIO PerUserCache.getElmHome
69− Task.throw (Exit.Assets (E.CorruptBinary elmHome filePath))
70−
71−
7259
7360-- WRITE UTF-8
7461
@@ -188,22 +175,21 @@ putHelp source sink =
188175-- EXISTS
189176
190177
191−exists :: FilePath -> Task.Task_ e Bool
192−exists filePath =
193− liftIO $ Dir.doesFileExist filePath
178+exists :: FilePath -> IO Bool
179+exists =
180+ Dir.doesFileExist
194181
195182
196183
197184-- REMOVE FILES
198185
199186
200−remove :: FilePath -> Task.Task_ e ()
187+remove :: FilePath -> IO ()
201188remove filePath =
202− liftIO $
203− do exists_ <- Dir.doesFileExist filePath
204− if exists_
205− then Dir.removeFile filePath
206− else return ()
189+ do exists_ <- Dir.doesFileExist filePath
190+ if exists_
191+ then Dir.removeFile filePath
192+ else return ()
207193
208194
209195removeDir :: FilePath -> IO ()