Skip to content

Commit 774d7ba

Browse files
authored
Merge pull request #1449 from spencerjanssen/tar-0.7
Support tar 0.7
2 parents 350fd8a + 13c5b51 commit 774d7ba

File tree

6 files changed

+30
-27
lines changed

6 files changed

+30
-27
lines changed

exes/BuildClient.hs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -866,13 +866,14 @@ pruneHaddockFiles dir = do
866866

867867
tarGzDirectory :: FilePath -> IO BS.ByteString
868868
tarGzDirectory dir = do
869-
res <- liftM (GZip.compress . Tar.write) $
870-
Tar.pack containing_dir [nested_dir]
871-
-- This seq is extremely important! Tar.pack is lazy, scanning
872-
-- directories as entries are demanded.
869+
entries <- Tar.pack' containing_dir [nested_dir]
870+
tarcontents <- Tar.write' entries
871+
let gzipped = GZip.compress tarcontents
872+
-- This seq is extremely important! Tar.write' is lazy, reading
873+
-- files as entries are demanded.
873874
-- This interacts very badly with the renameDirectory stuff with
874875
-- which tarGzDirectory gets wrapped.
875-
BS.length res `seq` return res
876+
BS.length gzipped `seq` return gzipped
876877
where (containing_dir, nested_dir) = splitFileName dir
877878

878879
uploadResults :: Verbosity -> BuildConfig -> DocInfo -> Maybe FilePath

flake.nix

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@
6060
packages = {
6161
# https://community.flake.parts/haskell-flake/dependency#path
6262
# tls.source = "1.9.0";
63+
tar.source = "0.7.0.0";
6364
};
6465
devShell = {
6566
tools = hp: {

hackage-server.cabal

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ common defaults
172172
, network-bsd ^>= 2.8
173173
, network-uri ^>= 2.6
174174
, parsec ^>= 3.1.13
175-
, tar ^>= 0.6
175+
, tar ^>= 0.7
176176
, unordered-containers ^>= 0.2.10
177177
, vector ^>= 0.12 || ^>= 0.13.0.0
178178
, zlib ^>= 0.6.2 || ^>= 0.7.0.0

src/Distribution/Server/Packages/Unpack.hs

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -341,14 +341,14 @@ warn msg = tell [msg]
341341
runUploadMonad :: UploadMonad a -> Either String (a, [String])
342342
runUploadMonad (UploadMonad m) = runIdentity . runExceptT . runWriterT $ m
343343

344-
selectEntries :: forall tarPath linkTarget err a.
344+
selectEntries :: forall content tarPath linkTarget err a.
345345
(err -> String)
346-
-> (Tar.GenEntry tarPath linkTarget -> Maybe a)
347-
-> Tar.GenEntries tarPath linkTarget err
346+
-> (Tar.GenEntry content tarPath linkTarget -> Maybe a)
347+
-> Tar.GenEntries content tarPath linkTarget err
348348
-> UploadMonad [a]
349349
selectEntries formatErr select = extract []
350350
where
351-
extract :: [a] -> Tar.GenEntries tarPath linkTarget err -> UploadMonad [a]
351+
extract :: [a] -> Tar.GenEntries content tarPath linkTarget err -> UploadMonad [a]
352352
extract _ (Tar.Fail err) = throwError (formatErr err)
353353
extract selected Tar.Done = return selected
354354
extract selected (Tar.Next entry entries) =
@@ -366,7 +366,7 @@ data CombinedTarErrs =
366366

367367
tarballChecks :: Bool -> UTCTime -> FilePath
368368
-> Tar.Entries Tar.FormatError
369-
-> Tar.GenEntries FilePath FilePath CombinedTarErrs
369+
-> Tar.GenEntries ByteString FilePath FilePath CombinedTarErrs
370370
tarballChecks lax now expectedDir =
371371
(if not lax then checkFutureTimes now else id)
372372
. checkTarbomb expectedDir
@@ -385,15 +385,15 @@ tarballChecks lax now expectedDir =
385385
fmapTarError f = Tar.foldEntries Tar.Next Tar.Done (Tar.Fail . f)
386386

387387
checkFutureTimes :: UTCTime
388-
-> Tar.GenEntries FilePath linkTarget CombinedTarErrs
389-
-> Tar.GenEntries FilePath linkTarget CombinedTarErrs
388+
-> Tar.GenEntries content FilePath linkTarget CombinedTarErrs
389+
-> Tar.GenEntries content FilePath linkTarget CombinedTarErrs
390390
checkFutureTimes now =
391391
checkEntries checkEntry
392392
where
393393
-- Allow 30s for client clock skew
394394
now' = addUTCTime 30 now
395395

396-
checkEntry :: Tar.GenEntry FilePath linkTarget -> Maybe CombinedTarErrs
396+
checkEntry :: Tar.GenEntry content FilePath linkTarget -> Maybe CombinedTarErrs
397397
checkEntry entry
398398
| entryUTCTime > now'
399399
= Just (FutureTimeError posixPath entryUTCTime now')
@@ -405,8 +405,8 @@ checkFutureTimes now =
405405

406406
checkTarbomb
407407
:: FilePath
408-
-> Tar.GenEntries FilePath linkTarget CombinedTarErrs
409-
-> Tar.GenEntries FilePath linkTarget CombinedTarErrs
408+
-> Tar.GenEntries content FilePath linkTarget CombinedTarErrs
409+
-> Tar.GenEntries content FilePath linkTarget CombinedTarErrs
410410
checkTarbomb expectedTopDir =
411411
checkEntries checkEntry
412412
where
@@ -416,8 +416,8 @@ checkTarbomb expectedTopDir =
416416
_ -> Just $ TarBombError (Tar.entryTarPath entry) expectedTopDir
417417

418418
checkUselessPermissions
419-
:: Tar.GenEntries FilePath linkTarget CombinedTarErrs
420-
-> Tar.GenEntries FilePath linkTarget CombinedTarErrs
419+
:: Tar.GenEntries content FilePath linkTarget CombinedTarErrs
420+
-> Tar.GenEntries content FilePath linkTarget CombinedTarErrs
421421
checkUselessPermissions =
422422
checkEntries checkEntry
423423
where
@@ -434,9 +434,9 @@ checkUselessPermissions =
434434

435435

436436
checkEntries
437-
:: (Tar.GenEntry tarPath linkTarget -> Maybe e)
438-
-> Tar.GenEntries tarPath linkTarget e
439-
-> Tar.GenEntries tarPath linkTarget e
437+
:: (Tar.GenEntry content tarPath linkTarget -> Maybe e)
438+
-> Tar.GenEntries content tarPath linkTarget e
439+
-> Tar.GenEntries content tarPath linkTarget e
440440
checkEntries checkEntry =
441441
Tar.foldEntries (\entry rest -> maybe (Tar.Next entry rest) Tar.Fail
442442
(checkEntry entry))

tests/Distribution/Server/Packages/UnpackTest.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ deriving instance Eq CombinedTarErrs
1919

2020
-- | Test that check permissions does the right thing
2121
testPermissions :: FilePath -- ^ .tar.gz file to test
22-
-> (Tar.GenEntry FilePath FilePath -> Maybe CombinedTarErrs) -- ^ Converter to create errors if necessary
22+
-> (Tar.GenEntry BL.ByteString FilePath FilePath -> Maybe CombinedTarErrs) -- ^ Converter to create errors if necessary
2323
-> Assertion
2424
testPermissions tarPath mangler = do
2525
entries <- Tar.read . GZip.decompress <$> BL.readFile tarPath

tests/PackageTestMain.hs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,16 +43,16 @@ tarPermissions =
4343
(testPermissions "tests/permissions-tarballs/bad-dir-perms.tar.gz" badDirMangler)
4444
]
4545

46-
goodMangler :: (Tar.GenEntry tarPath linkTarget -> Maybe CombinedTarErrs)
46+
goodMangler :: (Tar.GenEntry content tarPath linkTarget -> Maybe CombinedTarErrs)
4747
goodMangler = const Nothing
4848

49-
badFileMangler :: (Tar.GenEntry FilePath linkTarget -> Maybe CombinedTarErrs)
49+
badFileMangler :: (Tar.GenEntry content FilePath linkTarget -> Maybe CombinedTarErrs)
5050
badFileMangler entry =
5151
case Tar.entryContent entry of
5252
(Tar.NormalFile _ _) -> Just $ PermissionsError (Tar.entryTarPath entry) 0o600
5353
_ -> Nothing
5454

55-
badDirMangler :: (Tar.GenEntry FilePath linkTarget -> Maybe CombinedTarErrs)
55+
badDirMangler :: (Tar.GenEntry content FilePath linkTarget -> Maybe CombinedTarErrs)
5656
badDirMangler entry =
5757
case Tar.entryContent entry of
5858
Tar.Directory -> Just $ PermissionsError (Tar.entryTarPath entry) 0o700
@@ -153,8 +153,9 @@ successTestTGZ pkg tar = do
153153

154154
tarGzFile :: String -> IO ByteString
155155
tarGzFile name = do
156-
entries <- Tar.pack "tests/unpack-checks" [name]
157-
return (GZip.compress (Tar.write entries))
156+
entries <- Tar.pack' "tests/unpack-checks" [name]
157+
tarcontents <- Tar.write' entries
158+
return (GZip.compress tarcontents)
158159

159160
-- | Remove all Tar.Entries that are not files.
160161
keepOnlyFiles :: ByteString -> ByteString

0 commit comments

Comments
 (0)