Skip to content

Commit

Permalink
Merge pull request haskell#5558 from typedrat/fix-sdist-fd-leak
Browse files Browse the repository at this point in the history
  • Loading branch information
typedrat committed Sep 1, 2018
1 parent 793cdc6 commit b00d215
Show file tree
Hide file tree
Showing 7 changed files with 50 additions and 1 deletion.
3 changes: 2 additions & 1 deletion cabal-install/Distribution/Client/CmdSdist.hs
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ import Control.Monad.Writer.Lazy
( WriterT, tell, execWriterT )
import Data.Bits
( shiftL )
import qualified Data.ByteString.Char8 as BS
import qualified Data.ByteString.Lazy.Char8 as BSL
import Data.Either
( partitionEithers )
Expand Down Expand Up @@ -259,7 +260,7 @@ packageToSdist verbosity projectRootDir format outputFile pkg = do
Left err -> liftIO $ die' verbosity ("Error packing sdist: " ++ err)
Right path -> tell [Tar.directoryEntry path]

contents <- liftIO $ BSL.readFile file
contents <- liftIO . fmap BSL.fromStrict . BS.readFile $ file
case Tar.toTarPath False (prefix </> file) of
Left err -> liftIO $ die' verbosity ("Error packing sdist: " ++ err)
Right path -> tell [(Tar.fileEntry path contents) { Tar.entryPermissions = perm' }]
Expand Down
4 changes: 4 additions & 0 deletions cabal-testsuite/PackageTests/NewSdist/ManyDataFiles/Main.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module Main (main) where

main :: IO ()
main = putStrLn "Hello, World!"
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
packages: .
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
cabal-version: 2.2
name: many-data-files
version: 0

data-files: data/*.txt

executable dummy
default-language: Haskell2010
main-is: Main.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# cabal new-sdist
Wrote tarball sdist to <ROOT>/many-data-files.dist/source/dist-newstyle/sdist/many-data-files-0.tar.gz
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import Test.Cabal.Prelude

import Control.Applicative ((<$>))
import System.Directory ( createDirectoryIfMissing )
import qualified Data.ByteString.Char8 as BS

main = cabalTest . withSourceCopy $ do
limit <- getOpenFilesLimit
cwd <- testCurrentDir <$> getTestEnv

case limit of
Just n -> do
liftIO $ createDirectoryIfMissing False (cwd </> "data")
forM_ [1 .. n + 100] $ \i ->
liftIO $ BS.writeFile (cwd </> "data" </> ("data-file-" ++ show i) <.> "txt") (BS.pack "a data file\n")
cabal "new-sdist" ["many-data-files"]
Nothing -> skip
15 changes: 15 additions & 0 deletions cabal-testsuite/Test/Cabal/Prelude.hs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE NamedFieldPuns #-}
{-# LANGUAGE NondecreasingIndentation #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE CPP #-}
Expand Down Expand Up @@ -61,6 +62,7 @@ import System.Directory
#ifndef mingw32_HOST_OS
import Control.Monad.Catch ( bracket_ )
import System.Posix.Files ( createSymbolicLink )
import System.Posix.Resource
#endif

------------------------------------------------------------------------
Expand Down Expand Up @@ -804,6 +806,19 @@ isOSX = return (buildOS == OSX)
isLinux :: TestM Bool
isLinux = return (buildOS == Linux)

getOpenFilesLimit :: TestM (Maybe Integer)
#ifdef mingw32_HOST_OS
-- No MS-specified limit, was determined experimentally on Windows 10 Pro x64,
-- matches other online reports from other versions of Windows.
getOpenFilesLimit = return (Just 2048)
#else
getOpenFilesLimit = liftIO $ do
ResourceLimits { softLimit } <- getResourceLimit ResourceOpenFiles
case softLimit of
ResourceLimit n -> return (Just n)
_ -> return Nothing
#endif

hasCabalForGhc :: TestM Bool
hasCabalForGhc = do
env <- getTestEnv
Expand Down

0 comments on commit b00d215

Please sign in to comment.