@@ -100,13 +100,14 @@ type DevMinor = Int
100
100
type TypeCode = Char
101
101
type Permissions = FileMode
102
102
103
- -- | Tar archive entry.
103
+ -- | Polymorphic tar archive entry. High-level interfaces
104
+ -- commonly work with 'GenEntry' 'FilePath' 'FilePath',
105
+ -- while low level uses 'GenEntry' 'TarPath' 'LinkTarget'.
104
106
--
105
107
-- @since 0.6.0.0
106
108
data GenEntry tarPath linkTarget = Entry {
107
109
108
- -- | The path of the file or directory within the archive. This is in a
109
- -- tar-specific form. Use 'entryPath' to get a native 'FilePath'.
110
+ -- | The path of the file or directory within the archive.
110
111
entryTarPath :: ! tarPath ,
111
112
112
113
-- | The real content of the entry. For 'NormalFile' this includes the
@@ -127,14 +128,18 @@ data GenEntry tarPath linkTarget = Entry {
127
128
}
128
129
deriving (Eq , Show )
129
130
131
+ -- | Monomorphic tar archive entry, ready for serialization / deserialization.
132
+ --
130
133
type Entry = GenEntry TarPath LinkTarget
131
134
132
135
-- | Native 'FilePath' of the file or directory within the archive.
133
136
--
134
- entryPath :: Entry -> FilePath
137
+ entryPath :: GenEntry TarPath linkTarget -> FilePath
135
138
entryPath = fromTarPath . entryTarPath
136
139
137
- -- | The content of a tar archive entry, which depends on the type of entry.
140
+ -- | Polymorphic content of a tar archive entry. High-level interfaces
141
+ -- commonly work with 'GenEntryContent' 'FilePath',
142
+ -- while low level uses 'GenEntryContent' 'LinkTarget'.
138
143
--
139
144
-- Portable archives should contain only 'NormalFile' and 'Directory'.
140
145
--
@@ -153,6 +158,8 @@ data GenEntryContent linkTarget
153
158
{- # UNPACK #-} !FileSize
154
159
deriving (Eq , Ord , Show )
155
160
161
+ -- | Monomorphic content of a tar archive entry,
162
+ -- ready for serialization / deserialization.
156
163
type EntryContent = GenEntryContent LinkTarget
157
164
158
165
data Ownership = Ownership {
@@ -183,17 +190,15 @@ data Format =
183
190
-- | The \"USTAR\" format is an extension of the classic V7 format. It was
184
191
-- later standardised by POSIX. It has some restrictions but is the most
185
192
-- portable format.
186
- --
187
193
| UstarFormat
188
194
189
195
-- | The GNU tar implementation also extends the classic V7 format, though
190
- -- in a slightly different way from the USTAR format. In general for new
191
- -- archives the standard USTAR/POSIX should be used.
192
- --
196
+ -- in a slightly different way from the USTAR format. This is the only format
197
+ -- supporting long file names.
193
198
| GnuFormat
194
199
deriving (Eq , Ord , Show )
195
200
196
- instance NFData (GenEntry a b ) where
201
+ instance NFData (GenEntry tarPath linkTarget ) where
197
202
rnf (Entry _ c _ _ _ _) = rnf c
198
203
199
204
instance NFData (GenEntryContent linkTarget ) where
@@ -224,7 +229,7 @@ directoryPermissions :: Permissions
224
229
directoryPermissions = 0o0755
225
230
226
231
-- | An 'Entry' with all default values except for the file name and type. It
227
- -- uses the portable USTAR/POSIX format (see 'UstarHeader ').
232
+ -- uses the portable USTAR/POSIX format (see 'UstarFormat ').
228
233
--
229
234
-- You can use this as a basis and override specific fields, eg:
230
235
--
@@ -352,7 +357,8 @@ instance Show TarPath where
352
357
--
353
358
-- * The tar path may be an absolute path or may contain @\"..\"@ components.
354
359
-- For security reasons this should not usually be allowed, but it is your
355
- -- responsibility to check for these conditions (eg using 'checkEntrySecurity').
360
+ -- responsibility to check for these conditions
361
+ -- (e.g., using 'Codec.Archive.Tar.Check.checkEntrySecurity').
356
362
--
357
363
fromTarPath :: TarPath -> FilePath
358
364
fromTarPath = BS.Char8. unpack . fromTarPathInternal FilePath.Native. pathSeparator
@@ -543,15 +549,15 @@ fromFilePathToWindowsPath path = adjustDirectory $
543
549
-- * Entries type
544
550
--
545
551
546
- -- | A tar archive is a sequence of entries.
552
+ -- | Polymorphic sequence of archive entries.
553
+ -- High-level interfaces
554
+ -- commonly work with 'GenEntries' 'FilePath' 'FilePath',
555
+ -- while low level uses 'GenEntries' 'TarPath' 'LinkTarget'.
547
556
--
548
557
-- The point of this type as opposed to just using a list is that it makes the
549
558
-- failure case explicit. We need this because the sequence of entries we get
550
559
-- from reading a tarball can include errors.
551
560
--
552
- -- It is a concrete data type so you can manipulate it directly but it is often
553
- -- clearer to use the provided functions for mapping, folding and unfolding.
554
- --
555
561
-- Converting from a list can be done with just @foldr Next Done@. Converting
556
562
-- back into a list can be done with 'foldEntries' however in that case you
557
563
-- must be prepared to handle the 'Fail' case inherent in the 'Entries' type.
@@ -574,16 +580,21 @@ data GenEntries tarPath linkTarget e
574
580
575
581
infixr 5 `Next `
576
582
583
+ -- | Monomorphic sequence of archive entries,
584
+ -- ready for serialization / deserialization.
577
585
type Entries e = GenEntries TarPath LinkTarget e
578
586
579
- -- | This is like the standard 'unfoldr' function on lists, but for 'Entries'.
587
+ -- | This is like the standard 'Data.List. unfoldr' function on lists, but for 'Entries'.
580
588
-- It includes failure as an extra possibility that the stepper function may
581
589
-- return.
582
590
--
583
591
-- It can be used to generate 'Entries' from some other type. For example it is
584
592
-- used internally to lazily unfold entries from a 'LBS.ByteString'.
585
593
--
586
- unfoldEntries :: (a -> Either e (Maybe (Entry , a ))) -> a -> Entries e
594
+ unfoldEntries
595
+ :: (a -> Either e (Maybe (GenEntry tarPath linkTarget , a )))
596
+ -> a
597
+ -> GenEntries tarPath linkTarget e
587
598
unfoldEntries f = unfold
588
599
where
589
600
unfold x = case f x of
@@ -598,7 +609,11 @@ unfoldEntries f = unfold
598
609
-- This is used to consume a sequence of entries. For example it could be used
599
610
-- to scan a tarball for problems or to collect an index of the contents.
600
611
--
601
- foldEntries :: (GenEntry tarPath linkTarget -> a -> a ) -> a -> (e -> a ) -> GenEntries tarPath linkTarget e -> a
612
+ foldEntries
613
+ :: (GenEntry tarPath linkTarget -> a -> a )
614
+ -> a
615
+ -> (e -> a )
616
+ -> GenEntries tarPath linkTarget e -> a
602
617
foldEntries next done fail' = fold
603
618
where
604
619
fold (Next e es) = next e (fold es)
@@ -609,7 +624,11 @@ foldEntries next done fail' = fold
609
624
-- accumulator result, or the failure along with the intermediate accumulator
610
625
-- value.
611
626
--
612
- foldlEntries :: (a -> Entry -> a ) -> a -> Entries e -> Either (e , a ) a
627
+ foldlEntries
628
+ :: (a -> GenEntry tarPath linkTarget -> a )
629
+ -> a
630
+ -> GenEntries tarPath linkTarget e
631
+ -> Either (e , a ) a
613
632
foldlEntries f = go
614
633
where
615
634
go ! acc (Next e es) = go (f acc e) es
@@ -623,14 +642,19 @@ foldlEntries f = go
623
642
-- 'mapEntriesNoFail'
624
643
mapEntries
625
644
:: (GenEntry tarPath linkTarget -> Either e' (GenEntry tarPath linkTarget ))
645
+ -- ^ Function to apply to each entry
626
646
-> GenEntries tarPath linkTarget e
647
+ -- ^ Input sequence
627
648
-> GenEntries tarPath linkTarget (Either e e' )
628
649
mapEntries f =
629
650
foldEntries (\ entry rest -> either (Fail . Right ) (`Next ` rest) (f entry)) Done (Fail . Left )
630
651
631
652
-- | Like 'mapEntries' but the mapping function itself cannot fail.
632
653
--
633
- mapEntriesNoFail :: (Entry -> Entry ) -> Entries e -> Entries e
654
+ mapEntriesNoFail
655
+ :: (GenEntry tarPath linkTarget -> GenEntry tarPath linkTarget )
656
+ -> GenEntries tarPath linkTarget e
657
+ -> GenEntries tarPath linkTarget e
634
658
mapEntriesNoFail f =
635
659
foldEntries (Next . f) Done Fail
636
660
0 commit comments