Skip to content

Commit 48706b3

Browse files
committed
Revert "Pack: do not leak file handles"
This reverts commit ae872fc. The fix in ae872fc was not the best idea, because it forced reading entire input file in memory, which could be infeasible.
1 parent 0d26f10 commit 48706b3

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

Codec/Archive/Tar/Pack.hs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ import Data.Time.Clock
4444
import Data.Time.Clock.POSIX
4545
( utcTimeToPOSIXSeconds )
4646
import System.IO
47-
( IOMode(ReadMode), withBinaryFile, hFileSize )
47+
( IOMode(ReadMode), openBinaryFile, hFileSize )
4848
import System.IO.Unsafe (unsafeInterleaveIO)
4949
import Control.Exception (throwIO, SomeException)
5050
import Codec.Archive.Tar.Check.Internal (checkSecurity)
@@ -132,8 +132,9 @@ packFileEntry :: FilePath -- ^ Full path to find the file on the local disk
132132
packFileEntry filepath tarpath = do
133133
mtime <- getModTime filepath
134134
perms <- getPermissions filepath
135-
content <- BS.readFile filepath
136-
let size = BS.length content
135+
file <- openBinaryFile filepath ReadMode
136+
size <- hFileSize file
137+
content <- BS.hGetContents file
137138
return (simpleEntry tarpath (NormalFile content (fromIntegral size))) {
138139
entryPermissions = if executable perms then executableFilePermissions
139140
else ordinaryFilePermissions,

0 commit comments

Comments
 (0)