1 {-# LANGUAGE DeriveFunctor #-}
2 {-# OPTIONS_GHC -fno-warn-orphans #-}
4 -----------------------------------------------------------------------------
6 -----------------------------------------------------------------------------
9 -- Module : Distribution.Client.Tar
10 -- Copyright : (c) 2007 Bjorn Bringert,
11 -- 2008 Andrea Vezzosi,
12 -- 2008-2009 Duncan Coutts
15 -- Maintainer : duncan@community.haskell.org
16 -- Portability : portable
18 -- Reading, writing and manipulating \"@.tar@\" archive files.
19 module Distribution
.Client
.Tar
20 ( -- * @tar.gz@ operations
22 , TarComp
.extractTarGzFile
24 -- * Other local utils
25 , buildTreeRefTypeCode
26 , buildTreeSnapshotTypeCode
27 , isBuildTreeRefTypeCode
33 import Distribution
.Client
.Compat
.Prelude
36 import qualified Codec
.Archive
.Tar
as Tar
37 import qualified Codec
.Archive
.Tar
.Entry
as Tar
38 import qualified Codec
.Compression
.GZip
as GZip
39 import qualified Data
.ByteString
.Lazy
as BS
40 import qualified Distribution
.Client
.Compat
.Tar
as TarComp
43 import Control
.Exception
(throw
)
47 -- * High level operations
53 -- ^ Full Tarball path
57 -- ^ Directory to archive, relative to base dir
59 createTarGzFile tar base dir
=
60 BS
.writeFile tar
. GZip
.compress
. Tar
.write
=<< Tar
.pack base
[dir
]
62 -- | Type code for the local build tree reference entry type. We don't use the
63 -- symbolic link entry type because it allows only 100 ASCII characters for the
65 buildTreeRefTypeCode
:: Tar
.TypeCode
66 buildTreeRefTypeCode
= 'C
'
68 -- | Type code for the local build tree snapshot entry type.
69 buildTreeSnapshotTypeCode
:: Tar
.TypeCode
70 buildTreeSnapshotTypeCode
= 'S
'
72 -- | Is this a type code for a build tree reference?
73 isBuildTreeRefTypeCode
:: Tar
.TypeCode
-> Bool
74 isBuildTreeRefTypeCode typeCode
75 |
( typeCode
== buildTreeRefTypeCode
76 || typeCode
== buildTreeSnapshotTypeCode
81 filterEntries
:: (Tar
.Entry
-> Bool) -> Tar
.Entries e
-> Tar
.Entries e
84 (\e es
-> if p e
then Tar
.Next e es
else es
)
90 => (Tar
.Entry
-> m
Bool)
99 then return (Tar
.Next entry xs
)
105 entriesToList
:: Exception e
=> Tar
.Entries e
-> [Tar
.Entry
]
106 entriesToList
= Tar
.foldEntries
(:) [] throw