Skip to content

Commit 70a848e

Browse files
committed
Generalize Entry and EntryContent to GenEntry and GenEntryContent
1 parent 8588955 commit 70a848e

File tree

4 files changed

+35
-27
lines changed

4 files changed

+35
-27
lines changed

Codec/Archive/Tar.hs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,8 @@ module Codec.Archive.Tar (
118118
Entry,
119119
entryPath,
120120
entryContent,
121-
EntryContent(..),
121+
GenEntryContent(..),
122+
EntryContent,
122123

123124
-- ** Sequences of tar entries
124125
Entries(..),

Codec/Archive/Tar/Entry.hs

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,11 @@
2525
module Codec.Archive.Tar.Entry (
2626

2727
-- * Tar entry and associated types
28-
Entry(..),
29-
--TODO: should be the following with the Entry constructor not exported,
30-
-- but haddock cannot document that properly
31-
-- see http://trac.haskell.org/haddock/ticket/3
32-
--Entry(filePath, fileMode, ownerId, groupId, fileSize, modTime,
33-
-- fileType, linkTarget, headerExt, fileContent),
28+
GenEntry(..),
29+
Entry,
3430
entryPath,
35-
EntryContent(..),
31+
GenEntryContent(..),
32+
EntryContent,
3633
Ownership(..),
3734

3835
FileSize,

Codec/Archive/Tar/Types.hs

Lines changed: 28 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,11 @@
1616
-----------------------------------------------------------------------------
1717
module Codec.Archive.Tar.Types (
1818

19-
Entry(..),
19+
GenEntry(..),
20+
Entry,
2021
entryPath,
21-
EntryContent(..),
22+
GenEntryContent(..),
23+
EntryContent,
2224
FileSize,
2325
Permissions,
2426
Ownership(..),
@@ -99,15 +101,16 @@ type Permissions = FileMode
99101

100102
-- | Tar archive entry.
101103
--
102-
data Entry = Entry {
104+
-- @since 0.6.0.0
105+
data GenEntry tarPath linkTarget = Entry {
103106

104107
-- | The path of the file or directory within the archive. This is in a
105108
-- tar-specific form. Use 'entryPath' to get a native 'FilePath'.
106-
entryTarPath :: {-# UNPACK #-} !TarPath,
109+
entryTarPath :: !tarPath,
107110

108111
-- | The real content of the entry. For 'NormalFile' this includes the
109112
-- file data. An entry usually contains a 'NormalFile' or a 'Directory'.
110-
entryContent :: !EntryContent,
113+
entryContent :: !(GenEntryContent linkTarget),
111114

112115
-- | File permissions (Unix style file mode).
113116
entryPermissions :: {-# UNPACK #-} !Permissions,
@@ -123,6 +126,8 @@ data Entry = Entry {
123126
}
124127
deriving (Eq, Show)
125128

129+
type Entry = GenEntry TarPath LinkTarget
130+
126131
-- | Native 'FilePath' of the file or directory within the archive.
127132
--
128133
entryPath :: Entry -> FilePath
@@ -132,18 +137,22 @@ entryPath = fromTarPath . entryTarPath
132137
--
133138
-- Portable archives should contain only 'NormalFile' and 'Directory'.
134139
--
135-
data EntryContent = NormalFile LBS.ByteString {-# UNPACK #-} !FileSize
136-
| Directory
137-
| SymbolicLink !LinkTarget
138-
| HardLink !LinkTarget
139-
| CharacterDevice {-# UNPACK #-} !DevMajor
140-
{-# UNPACK #-} !DevMinor
141-
| BlockDevice {-# UNPACK #-} !DevMajor
142-
{-# UNPACK #-} !DevMinor
143-
| NamedPipe
144-
| OtherEntryType {-# UNPACK #-} !TypeCode LBS.ByteString
145-
{-# UNPACK #-} !FileSize
146-
deriving (Eq, Ord, Show)
140+
-- @since 0.6.0.0
141+
data GenEntryContent linkTarget
142+
= NormalFile LBS.ByteString {-# UNPACK #-} !FileSize
143+
| Directory
144+
| SymbolicLink !linkTarget
145+
| HardLink !linkTarget
146+
| CharacterDevice {-# UNPACK #-} !DevMajor
147+
{-# UNPACK #-} !DevMinor
148+
| BlockDevice {-# UNPACK #-} !DevMajor
149+
{-# UNPACK #-} !DevMinor
150+
| NamedPipe
151+
| OtherEntryType {-# UNPACK #-} !TypeCode LBS.ByteString
152+
{-# UNPACK #-} !FileSize
153+
deriving (Eq, Ord, Show)
154+
155+
type EntryContent = GenEntryContent LinkTarget
147156

148157
data Ownership = Ownership {
149158
-- | The owner user name. Should be set to @\"\"@ if unknown.
@@ -183,10 +192,10 @@ data Format =
183192
| GnuFormat
184193
deriving (Eq, Ord, Show)
185194

186-
instance NFData Entry where
195+
instance NFData (GenEntry a b) where
187196
rnf (Entry _ c _ _ _ _) = rnf c
188197

189-
instance NFData EntryContent where
198+
instance NFData (GenEntryContent linkTarget) where
190199
rnf x = case x of
191200
NormalFile c _ -> rnf c
192201
OtherEntryType _ c _ -> rnf c

changelog.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ See also http://pvp.haskell.org/faq
1919
* Drop deprecated `emptyIndex` and `finaliseIndex`
2020
* Extend `FileNameError` with `UnsafeLinkTarget` constructor
2121
* Add `CheckSecurityCallback`, `packWith`, `unpackWith`
22+
* Generalize `Entry` and `EntryContent` to `GenEntry` and `GenEntryContent`
2223

2324
0.5.1.1 Herbert Valerio Riedel <[email protected]> August 2019
2425

0 commit comments

Comments
 (0)