Skip to content

Commit

Permalink
Pack: do not leak file handles
Browse files Browse the repository at this point in the history
  • Loading branch information
Bodigrim committed Nov 18, 2023
1 parent ae0aa0e commit ae872fc
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions Codec/Archive/Tar/Pack.hs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ import Data.Time.Clock
import Data.Time.Clock.POSIX
( utcTimeToPOSIXSeconds )
import System.IO
( IOMode(ReadMode), openBinaryFile, hFileSize )
( IOMode(ReadMode), withBinaryFile, hFileSize )
import System.IO.Unsafe (unsafeInterleaveIO)

-- | Creates a tar archive from a list of directory or files. Any directories
Expand Down Expand Up @@ -103,9 +103,8 @@ packFileEntry :: FilePath -- ^ Full path to find the file on the local disk
packFileEntry filepath tarpath = do
mtime <- getModTime filepath
perms <- getPermissions filepath
file <- openBinaryFile filepath ReadMode
size <- hFileSize file
content <- BS.hGetContents file
content <- BS.readFile filepath
let size = BS.length content
return (simpleEntry tarpath (NormalFile content (fromIntegral size))) {
entryPermissions = if executable perms then executableFilePermissions
else ordinaryFilePermissions,
Expand Down

2 comments on commit ae872fc

@Gabriella439
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Bodigrim: It looks like the withBinaryFile imported as part of this commit wasn't used. It's a benign unused import, but I just wanted to point that out.

@Bodigrim
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! Surprisingly this library does not enable -Wall %)

Please sign in to comment.