diff --git a/hledger-lib/Hledger/Read.hs b/hledger-lib/Hledger/Read.hs index 8b3dedd05..ff5b0d0ea 100644 --- a/hledger-lib/Hledger/Read.hs +++ b/hledger-lib/Hledger/Read.hs @@ -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 diff --git a/hledger-lib/Hledger/Utils/IO.hs b/hledger-lib/Hledger/Utils/IO.hs index 07bbbc9d2..ce5c4cf3c 100644 --- a/hledger-lib/Hledger/Utils/IO.hs +++ b/hledger-lib/Hledger/Utils/IO.hs @@ -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, diff --git a/hledger/Hledger/Cli/Utils.hs b/hledger/Hledger/Cli/Utils.hs index ae8080762..de87a5e2f 100644 --- a/hledger/Hledger/Cli/Utils.hs +++ b/hledger/Hledger/Cli/Utils.hs @@ -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