Skip to content

Commit

Permalink
Merge pull request #6078 from fendor/cabal-unpack-empty-dir
Browse files Browse the repository at this point in the history
Unpack in existing directory if empty
  • Loading branch information
23Skidoo authored Jun 25, 2019
2 parents c63e378 + c6ff32e commit 49b323b
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions cabal-install/Distribution/Client/Get.hs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ module Distribution.Client.Get (

import Prelude ()
import Distribution.Client.Compat.Prelude hiding (get)

import Distribution.Compat.Directory
( listDirectory )
import Distribution.Package
( PackageId, packageId, packageName )
import Distribution.Simple.Setup
Expand Down Expand Up @@ -162,12 +163,16 @@ unpackPackage :: Verbosity -> FilePath -> PackageId
-> PackageDescriptionOverride
-> FilePath -> IO ()
unpackPackage verbosity prefix pkgid descOverride pkgPath = do
let pkgdirname = display pkgid
pkgdir = prefix </> pkgdirname
pkgdir' = addTrailingPathSeparator pkgdir
let pkgdirname = display pkgid
pkgdir = prefix </> pkgdirname
pkgdir' = addTrailingPathSeparator pkgdir
emptyDirectory directory = null <$> listDirectory directory
existsDir <- doesDirectoryExist pkgdir
when existsDir $ die' verbosity $
"The directory \"" ++ pkgdir' ++ "\" already exists, not unpacking."
when existsDir $ do
isEmpty <- emptyDirectory pkgdir
unless isEmpty $
die' verbosity $
"The directory \"" ++ pkgdir' ++ "\" already exists and is not empty, not unpacking."
existsFile <- doesFileExist pkgdir
when existsFile $ die' verbosity $
"A file \"" ++ pkgdir ++ "\" is in the way, not unpacking."
Expand Down

0 comments on commit 49b323b

Please sign in to comment.