convert all bytestring readFile/writeFile to use Utility.FileIO
authorJoey Hess <joeyh@joeyh.name>
Fri, 5 Sep 2025 16:05:13 +0000 (12:05 -0400)
committerJoey Hess <joeyh@joeyh.name>
Fri, 5 Sep 2025 16:13:28 +0000 (12:13 -0400)
This is groundwork for setting the close-on-exec flag when opening
files, which will be done in Utility.FileIO or a similar module using the same
function names. The bytestring library does not set that flag, even though it
could, and IMHO should.

Note that there are many calls to the Prelude's readFile/writeFile/appendFile
still in git-annex, and this does not address those.

Sponsored-by: the NIH-funded NICEMAN (ReproNim TR&D3) project
Build/Standalone.hs
Remote/Directory/LegacyChunked.hs
Remote/Helper/Special.hs
Utility/FileIO.hs

index b9a683fb0bbf8556a7ae2ce6cff1735751646605..e0e9e56bee20c7a6a191643cbed791032972e451 100644 (file)
@@ -15,7 +15,6 @@ import System.Environment (getArgs)
 import Control.Monad.IfElse
 import System.Posix.Files
 import Control.Monad
-import qualified Data.ByteString.Lazy as L
 import qualified Data.Map as M
 
 import Utility.SafeCommand
@@ -26,6 +25,7 @@ import Utility.Path.AbsRel
 import Utility.Directory
 import Utility.Env
 import Utility.SystemDirectory
+import qualified Utility.FileIO as F
 import Build.BundledPrograms
 #ifdef darwin_HOST_OS
 import System.IO
@@ -98,7 +98,7 @@ installGitLibs topdir = do
                                                let linktarget' = progDir topdir </> takeFileName linktarget
                                                unlessM (doesFileExist linktarget') $ do
                                                        createDirectoryIfMissing True (takeDirectory linktarget')
-                                                       L.readFile f' >>= L.writeFile (fromOsPath linktarget')
+                                                       F.readFile f >>= F.writeFile linktarget'
                                                removeWhenExistsWith removeFile destf
                                                rellinktarget <- relPathDirToFile
                                                        (takeDirectory destf)
index 03dd7e398d94ebb495aea580cd34c64933bc5c28..3773ed9172c6ed072104be58a62dc1b81cf623c7 100644 (file)
@@ -52,7 +52,7 @@ storeLegacyChunked _ _ [] _ = error "bad storeLegacyChunked call"
 storeLegacyChunked meterupdate chunksize alldests@(firstdest:_) b
        | L.null b = do
                -- always write at least one file, even for empty
-               L.writeFile firstdest b
+               F.writeFile (toOsPath firstdest) b
                return [firstdest]
        | otherwise = storeLegacyChunked' meterupdate chunksize alldests (L.toChunks b) []
 storeLegacyChunked' :: MeterUpdate -> ChunkSize -> [FilePath] -> [S.ByteString] -> [FilePath] -> IO [FilePath]
@@ -103,7 +103,7 @@ retrieve locations d basek p _dest miv c = withOtherTmp $ \tmpdir -> do
        let go = \k sink -> do
                liftIO $ void $ withStoredFiles (fromOsPath d) (legacyLocations locations) k $ \fs -> do
                        forM_ fs $
-                               F.appendFile' tmp <=< S.readFile
+                               F.appendFile' tmp <=< F.readFile' . toOsPath
                        return True
                b <- liftIO $ F.readFile tmp
                liftIO $ removeWhenExistsWith removeFile tmp
index cc1fdf20a35139b4c1745e9ba557bf133cc46372..c74cb1dde1e29155e12931f8b5b298af1e8cb000 100644 (file)
@@ -96,7 +96,7 @@ mkRetrievalVerifiableKeysSecure gc
 fileStorer :: (Key -> OsPath -> MeterUpdate -> Annex ()) -> Storer
 fileStorer a k (FileContent f) m = a k f m
 fileStorer a k (ByteContent b) m = withTmp k $ \f -> do
-       liftIO $ L.writeFile (fromOsPath f) b
+       liftIO $ F.writeFile f b
        a k f m
 
 -- A Storer that expects to be provided with a L.ByteString of
index f10cb20ffcb56f44849ac1c64105862b833e66ac..712877f0cb9e848e6e88fe52c3971702b6196eac 100644 (file)
@@ -1,4 +1,7 @@
-{- File IO on OsPaths.
+{- This is a subset of the functions provided by file-io.
+ -
+ - When not building with file-io, this provides equvilant
+ - RawFilePath versions.
  -
  - Since Prelude exports many of these as well, this needs to be imported
  - qualified.
@@ -41,7 +44,6 @@ import System.IO (IO, Handle, IOMode)
 import Prelude (return)
 import qualified System.File.OsPath as O
 import qualified Data.ByteString as B
-import qualified Data.ByteString.Lazy as L
 import Control.Applicative
 
 withFile :: OsPath -> IOMode -> (Handle -> IO r) -> IO r