lib: move readFileStrictly to Hledger.Utils.IO
This commit is contained in:
parent
7899b992b7
commit
d1635a55f8
@ -405,9 +405,6 @@ latestDatesFileFor f = dir </> ".latest" <.> fname
|
||||
where
|
||||
(dir, fname) = splitFileName f
|
||||
|
||||
readFileStrictly :: FilePath -> IO Text
|
||||
readFileStrictly f = readFilePortably f >>= \t -> C.evaluate (T.length t) >> return t
|
||||
|
||||
-- | Given zero or more latest dates (all the same, representing the
|
||||
-- latest previously seen transaction date, and how many transactions
|
||||
-- were seen on that date), remove transactions with earlier dates
|
||||
|
||||
@ -80,6 +80,7 @@ module Hledger.Utils.IO (
|
||||
expandGlob,
|
||||
sortByModTime,
|
||||
readFileOrStdinPortably,
|
||||
readFileStrictly,
|
||||
readFilePortably,
|
||||
readHandlePortably,
|
||||
-- hereFileRelative,
|
||||
@ -91,6 +92,7 @@ module Hledger.Utils.IO (
|
||||
)
|
||||
where
|
||||
|
||||
import qualified Control.Exception as C (evaluate)
|
||||
import Control.Monad (when, forM)
|
||||
import Data.Colour.RGBSpace (RGB(RGB))
|
||||
import Data.Colour.RGBSpace.HSL (lightness)
|
||||
@ -461,6 +463,10 @@ sortByModTime fs = do
|
||||
ftimes <- forM fs $ \f -> do {t <- getModificationTime f; return (t,f)}
|
||||
return $ map snd $ reverse $ sort ftimes
|
||||
|
||||
-- | Like readFilePortably, but read all of the file before proceeding.
|
||||
readFileStrictly :: FilePath -> IO T.Text
|
||||
readFileStrictly f = readFilePortably f >>= \t -> C.evaluate (T.length t) >> return t
|
||||
|
||||
-- | Read text from a file,
|
||||
-- converting any \r\n line endings to \n,,
|
||||
-- using the system locale's text encoding,
|
||||
|
||||
@ -20,7 +20,6 @@ module Hledger.Cli.Utils
|
||||
openBrowserOn,
|
||||
writeFileWithBackup,
|
||||
writeFileWithBackupIfChanged,
|
||||
readFileStrictly,
|
||||
pivotByOpts,
|
||||
anonymiseByOpts,
|
||||
journalSimilarTransaction,
|
||||
@ -29,7 +28,6 @@ module Hledger.Cli.Utils
|
||||
)
|
||||
where
|
||||
|
||||
import Control.Exception as C
|
||||
import Control.Monad.Except (ExceptT)
|
||||
import Control.Monad.IO.Class (liftIO)
|
||||
import Data.List
|
||||
@ -223,9 +221,6 @@ writeFileWithBackupIfChanged f t = do
|
||||
writeFileWithBackup :: FilePath -> String -> IO ()
|
||||
writeFileWithBackup f t = backUpFile f >> writeFile f t
|
||||
|
||||
readFileStrictly :: FilePath -> IO T.Text
|
||||
readFileStrictly f = readFilePortably f >>= \s -> C.evaluate (T.length s) >> return s
|
||||
|
||||
-- | Back up this file with a (incrementing) numbered suffix, or give an error.
|
||||
backUpFile :: FilePath -> IO ()
|
||||
backUpFile fp = do
|
||||
|
||||
Loading…
Reference in New Issue
Block a user