-
Notifications
You must be signed in to change notification settings - Fork 704
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add a `Compat` module to accomodate two different `tar` interfaces.
- Loading branch information
Showing
5 changed files
with
68 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
{-# LANGUAGE CPP #-} | ||
|
||
{- FOURMOLU_DISABLE -} | ||
module Distribution.Client.Compat.Tar | ||
( extractTarGzFile | ||
#if MIN_VERSION_tar(0,6,0) | ||
, Tar.Entry | ||
, Tar.Entries | ||
, Tar.GenEntries (..) | ||
, Tar.GenEntryContent (..) | ||
, Tar.entryContent | ||
#else | ||
, Tar.Entries (..) | ||
, Tar.Entry (..) | ||
, Tar.EntryContent (..) | ||
#endif | ||
) where | ||
{- FOURMOLU_ENABLE -} | ||
|
||
import Distribution.Client.Compat.Prelude | ||
import Prelude () | ||
|
||
import qualified Codec.Archive.Tar as Tar | ||
import qualified Codec.Archive.Tar.Check as Tar | ||
#if MIN_VERSION_tar(0,6,0) | ||
#else | ||
import qualified Codec.Archive.Tar.Entry as Tar | ||
#endif | ||
import qualified Data.ByteString.Lazy as BS | ||
import qualified Distribution.Client.GZipUtils as GZipUtils | ||
|
||
-- Instances. | ||
import Control.Exception () | ||
This comment has been minimized.
Sorry, something went wrong. |
||
|
||
{- FOURMOLU_DISABLE -} | ||
extractTarGzFile | ||
:: FilePath | ||
-- ^ Destination directory | ||
-> FilePath | ||
-- ^ Expected subdir (to check for tarbombs) | ||
-> FilePath | ||
-- ^ Tarball | ||
-> IO () | ||
extractTarGzFile dir expected tar = | ||
#if MIN_VERSION_tar(0,6,0) | ||
Tar.unpackAndCheck | ||
( \x -> | ||
SomeException <$> Tar.checkEntryTarbomb expected x | ||
<|> SomeException <$> Tar.checkEntrySecurity x | ||
) | ||
dir | ||
#else | ||
Tar.unpack dir | ||
. Tar.checkTarbomb expected | ||
#endif | ||
. Tar.read | ||
. GZipUtils.maybeDecompress | ||
=<< BS.readFile tar | ||
{- FOURMOLU_ENABLE -} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
There is no
instance Exception (Either e1 e2)
at the moment (see haskell/core-libraries-committee#233). Something stupid likeeither throwIO throwIO
should do.