From: Joey Hess Date: Fri, 5 Sep 2025 19:44:43 +0000 (-0400) Subject: convert withFile and withBinaryFile to close-on-exec safe versions X-Git-Tag: archive/raspbian/10.20251029-1+rpi1~1^2~3^2~132 X-Git-Url: https://dgit.raspbian.org/?a=commitdiff_plain;h=66814d921c1505173d6351e74e5435e9d3dd9284;p=git-annex.git convert withFile and withBinaryFile to close-on-exec safe versions At this point, every call in git-annex to withFile, openBinaryFile, withBinaryFile, appendFile, and openTempFile, readFile, and writeFile have been converted. Sponsored-by: the NIH-funded NICEMAN (ReproNim TR&D3) project --- diff --git a/Assistant/Install/Menu.hs b/Assistant/Install/Menu.hs index 04261838ef..d5056fa89f 100644 --- a/Assistant/Install/Menu.hs +++ b/Assistant/Install/Menu.hs @@ -13,6 +13,7 @@ module Assistant.Install.Menu where import Common import Utility.FreeDesktop +import qualified Utility.FileIO as F installMenu :: String -> OsPath -> OsPath -> OsPath -> IO () #ifdef darwin_HOST_OS @@ -40,8 +41,8 @@ fdoDesktopMenu command = genDesktopEntry installIcon :: OsPath -> OsPath -> IO () installIcon src dest = do createDirectoryIfMissing True (parentDir dest) - withBinaryFile (fromOsPath src) ReadMode $ \hin -> - withBinaryFile (fromOsPath dest) WriteMode $ \hout -> + F.withBinaryFile src ReadMode $ \hin -> + F.withBinaryFile dest WriteMode $ \hout -> hGetContents hin >>= hPutStr hout iconBaseName :: String diff --git a/Remote/Directory/LegacyChunked.hs b/Remote/Directory/LegacyChunked.hs index e32b263b98..56b3071359 100644 --- a/Remote/Directory/LegacyChunked.hs +++ b/Remote/Directory/LegacyChunked.hs @@ -59,7 +59,7 @@ storeLegacyChunked' :: MeterUpdate -> ChunkSize -> [FilePath] -> [S.ByteString] storeLegacyChunked' _ _ [] _ _ = error "ran out of dests" storeLegacyChunked' _ _ _ [] c = return $ reverse c storeLegacyChunked' meterupdate chunksize (d:dests) bs c = do - bs' <- withFile d WriteMode $ + bs' <- F.withFile (toOsPath d) WriteMode $ feed zeroBytesProcessed chunksize bs storeLegacyChunked' meterupdate chunksize dests bs' (d:c) where diff --git a/Remote/Helper/Chunked/Legacy.hs b/Remote/Helper/Chunked/Legacy.hs index 9f4c3fea36..c4a300e1f6 100644 --- a/Remote/Helper/Chunked/Legacy.hs +++ b/Remote/Helper/Chunked/Legacy.hs @@ -10,6 +10,7 @@ module Remote.Helper.Chunked.Legacy where import Annex.Common import Remote.Helper.Chunked import Utility.Metered +import qualified Utility.FileIO as F import qualified Data.ByteString as S import qualified Data.ByteString.Lazy as L @@ -116,6 +117,6 @@ storeChunked annexrunner chunksize dests storer content = -} meteredWriteFileChunks :: MeterUpdate -> FilePath -> [v] -> (v -> IO L.ByteString) -> IO () meteredWriteFileChunks meterupdate dest chunks feeder = - withBinaryFile dest WriteMode $ \h -> + F.withBinaryFile (toOsPath dest) WriteMode $ \h -> forM_ chunks $ meteredWrite meterupdate (S.hPut h) <=< feeder