diff options
author | Joey Hess <joey@kitenet.net> | 2014-02-03 10:16:05 -0400 |
---|---|---|
committer | Joey Hess <joey@kitenet.net> | 2014-02-03 10:19:06 -0400 |
commit | 19fee049f6dfba4d4294e16d6d530bc7d0e78c54 (patch) | |
tree | c7888ba624904092b280223a34a044f0c2bdbd9a /Logs | |
parent | 6295ec998fb65607fb8c1d88035b41fa0cb3b0d6 (diff) |
avoid using openFile when withFile can be used
Potentially fixes some FD leak if an action on an opened file handle fails
for some reason. There have been some hard to reproduce reports of
git-annex leaking FDs, and this may solve them.
Diffstat (limited to 'Logs')
-rw-r--r-- | Logs/Transfer.hs | 13 |
1 files changed, 4 insertions, 9 deletions
diff --git a/Logs/Transfer.hs b/Logs/Transfer.hs index fbfd0a427..e998a56b1 100644 --- a/Logs/Transfer.hs +++ b/Logs/Transfer.hs @@ -340,11 +340,8 @@ parseTransferFile file bits = splitDirectories file writeTransferInfoFile :: TransferInfo -> FilePath -> IO () -writeTransferInfoFile info tfile = do - h <- openFile tfile WriteMode - fileEncoding h - hPutStr h $ writeTransferInfo info - hClose h +writeTransferInfoFile info tfile = writeFileAnyEncoding tfile $ + writeTransferInfo info {- File format is a header line containing the startedTime and any - bytesComplete value. Followed by a newline and the associatedFile. @@ -365,10 +362,8 @@ writeTransferInfo info = unlines ] readTransferInfoFile :: Maybe PID -> FilePath -> IO (Maybe TransferInfo) -readTransferInfoFile mpid tfile = catchDefaultIO Nothing $ do - h <- openFile tfile ReadMode - fileEncoding h - hClose h `after` (readTransferInfo mpid <$> hGetContentsStrict h) +readTransferInfoFile mpid tfile = catchDefaultIO Nothing $ + readTransferInfo mpid <$> readFileStrictAnyEncoding tfile readTransferInfo :: Maybe PID -> String -> Maybe TransferInfo readTransferInfo mpid s = TransferInfo |