From 60d0dc9c766f39a59e2103d76ed20f14c70ddbb7 Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Wed, 22 Jan 2025 14:43:37 -0400 Subject: [PATCH] convert from readFileStrict More of these still to convert, but need to be careful of newline translation. --- Annex/AdjustedBranch.hs | 11 ++++++----- Build/Version.hs | 14 ++++++++------ Upgrade/V1.hs | 2 +- 3 files changed, 15 insertions(+), 12 deletions(-) diff --git a/Annex/AdjustedBranch.hs b/Annex/AdjustedBranch.hs index 4eafcadfe2..5d5458fa82 100644 --- a/Annex/AdjustedBranch.hs +++ b/Annex/AdjustedBranch.hs @@ -70,6 +70,7 @@ import Logs.View (is_branchView) import Logs.AdjustedBranchUpdate import Utility.FileMode import qualified Utility.RawFilePath as R +import qualified Utility.FileIO as F import Data.Time.Clock.POSIX import qualified Data.Map as M @@ -268,7 +269,7 @@ updateAdjustedBranch adj (AdjBranch currbranch) origbranch -- origbranch. _ <- propigateAdjustedCommits' True origbranch adj commitlck - origheadfile <- inRepo $ readFileStrict . fromRawFilePath . Git.Ref.headFile + origheadfile <- inRepo $ F.readFile' . toOsPath . Git.Ref.headFile origheadsha <- inRepo (Git.Ref.sha currbranch) b <- adjustBranch adj origbranch @@ -280,8 +281,8 @@ updateAdjustedBranch adj (AdjBranch currbranch) origbranch newheadfile <- case origheadsha of Just s -> do inRepo $ \r -> do - let newheadfile = fromRef s - writeFile (fromRawFilePath (Git.Ref.headFile r)) newheadfile + let newheadfile = fromRef' s + F.writeFile' (toOsPath (Git.Ref.headFile r)) newheadfile return (Just newheadfile) _ -> return Nothing @@ -295,9 +296,9 @@ updateAdjustedBranch adj (AdjBranch currbranch) origbranch unless ok $ case newheadfile of Nothing -> noop Just v -> preventCommits $ \_commitlck -> inRepo $ \r -> do - v' <- readFileStrict (fromRawFilePath (Git.Ref.headFile r)) + v' <- F.readFile' (toOsPath (Git.Ref.headFile r)) when (v == v') $ - writeFile (fromRawFilePath (Git.Ref.headFile r)) origheadfile + F.writeFile' (toOsPath (Git.Ref.headFile r)) origheadfile return ok | otherwise = preventCommits $ \commitlck -> do diff --git a/Build/Version.hs b/Build/Version.hs index 0d95dc7b26..e3b905919d 100644 --- a/Build/Version.hs +++ b/Build/Version.hs @@ -1,6 +1,6 @@ {- Package version determination. -} -{-# LANGUAGE LambdaCase #-} +{-# LANGUAGE LambdaCase, OverloadedStrings #-} {-# OPTIONS_GHC -fno-warn-tabs #-} module Build.Version where @@ -14,7 +14,9 @@ import Prelude import Utility.Monad import Utility.Exception -import Utility.Misc +import Utility.OsPath +import Utility.FileSystemEncoding +import qualified Utility.FileIO as F type Version = String @@ -56,11 +58,11 @@ getChangelogVersion = do middle = drop 1 . init writeVersion :: Version -> IO () -writeVersion ver = catchMaybeIO (readFileStrict f) >>= \case +writeVersion ver = catchMaybeIO (F.readFile' f) >>= \case Just s | s == body -> return () - _ -> writeFile f body + _ -> F.writeFile' f body where - body = unlines $ concat + body = encodeBS $ unlines $ concat [ header , ["packageversion :: String"] , ["packageversion = \"" ++ ver ++ "\""] @@ -71,4 +73,4 @@ writeVersion ver = catchMaybeIO (readFileStrict f) >>= \case , "" ] footer = [] - f = "Build/Version" + f = toOsPath "Build/Version" diff --git a/Upgrade/V1.hs b/Upgrade/V1.hs index b1e0d83c95..5540844a70 100644 --- a/Upgrade/V1.hs +++ b/Upgrade/V1.hs @@ -204,7 +204,7 @@ writeLog1 file ls = viaTmp F.writeFile readLog1 :: FilePath -> IO [LogLine] readLog1 file = catchDefaultIO [] $ - parseLog . encodeBL <$> readFileStrict file + parseLog <$> F.readFile (toOsPath (toRawFilePath file)) lookupKey1 :: FilePath -> Annex (Maybe (Key, Backend)) lookupKey1 file = do