convert from readFileStrict

This removes that function, using file-io readFile' instead.

Had to deal with newline conversion, which readFileStrict does on
Windows. In a few cases, that was pretty ugly to deal with.

Sponsored-by: Kevin Mueller
This commit is contained in:
Joey Hess 2025-01-22 16:19:06 -04:00
parent de1af273e0
commit 6e27b0d4d1
No known key found for this signature in database
GPG key ID: DB12DB0FF05F8F38
19 changed files with 94 additions and 71 deletions

View file

@ -47,6 +47,7 @@ import qualified Utility.RawFilePath as R
import qualified Utility.FileIO as F
import qualified Data.Set as S
import qualified Data.ByteString as B
import qualified Data.ByteString.Lazy as L
import qualified System.FilePath.ByteString as P
@ -263,7 +264,9 @@ explodePackedRefsFile r = do
let f = packedRefsFile r
let f' = toRawFilePath f
whenM (doesFileExist f) $ do
rs <- mapMaybe parsePacked . lines
rs <- mapMaybe parsePacked
. map decodeBS
. fileLines'
<$> catchDefaultIO "" (safeReadFile f')
forM_ rs makeref
removeWhenExistsWith R.removeLink f'
@ -474,7 +477,7 @@ displayList items header
-}
preRepair :: Repo -> IO ()
preRepair g = do
unlessM (validhead <$> catchDefaultIO "" (safeReadFile headfile)) $ do
unlessM (validhead <$> catchDefaultIO "" (decodeBS <$> safeReadFile headfile)) $ do
removeWhenExistsWith R.removeLink headfile
writeFile (fromRawFilePath headfile) "ref: refs/heads/master"
explodePackedRefsFile g
@ -652,7 +655,7 @@ runRepair' removablebranch fsckresult forced referencerepo g = do
successfulRepair :: (Bool, [Branch]) -> Bool
successfulRepair = fst
safeReadFile :: RawFilePath -> IO String
safeReadFile :: RawFilePath -> IO B.ByteString
safeReadFile f = do
allowRead f
readFileStrict (fromRawFilePath f)
F.readFile' (toOsPath f)