-
Notifications
You must be signed in to change notification settings - Fork 697
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. * Tweak `-Wunused-packages` conditional (thanks Phil de Joux)
- Loading branch information
Showing
5 changed files
with
95 additions
and
42 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,68 @@ | ||
{-# LANGUAGE CPP #-} | ||
{-# OPTIONS_GHC -fno-warn-orphans #-} | ||
|
||
{- 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 | ||
|
||
instance (Exception a, Exception b) => Exception (Either a b) where | ||
toException (Left e) = toException e | ||
toException (Right e) = toException e | ||
|
||
fromException e = | ||
case fromException e of | ||
Just e' -> Just (Left e') | ||
Nothing -> case fromException e of | ||
Just e' -> Just (Right e') | ||
Nothing -> Nothing | ||
|
||
{- 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