@@ -138,10 +138,10 @@ tarPackageChecks lax now tarGzFile contents = do
138
138
expectedDir = display pkgid
139
139
140
140
selectEntry entry = case Tar. entryContent entry of
141
- Tar. NormalFile bs _ -> Just (normalise (Tar. entryPath entry), NormalFile bs)
142
- Tar. Directory -> Just (normalise (Tar. entryPath entry), Directory )
143
- Tar. SymbolicLink linkTarget -> Just (normalise (Tar. entryPath entry), Link ( Tar. fromLinkTarget linkTarget) )
144
- Tar. HardLink linkTarget -> Just (normalise (Tar. entryPath entry), Link ( Tar. fromLinkTarget linkTarget) )
141
+ Tar. NormalFile bs _ -> Just (normalise (Tar. entryTarPath entry), NormalFile bs)
142
+ Tar. Directory -> Just (normalise (Tar. entryTarPath entry), Directory )
143
+ Tar. SymbolicLink linkTarget -> Just (normalise (Tar. entryTarPath entry), Link linkTarget)
144
+ Tar. HardLink linkTarget -> Just (normalise (Tar. entryTarPath entry), Link linkTarget)
145
145
_ -> Nothing
146
146
files <- selectEntries explainTarError selectEntry entries
147
147
return (pkgid, files)
@@ -331,14 +331,14 @@ warn msg = tell [msg]
331
331
runUploadMonad :: UploadMonad a -> Either String (a , [String ])
332
332
runUploadMonad (UploadMonad m) = runIdentity . runExceptT . runWriterT $ m
333
333
334
- selectEntries :: forall err a .
334
+ selectEntries :: forall tarPath linkTarget err a .
335
335
(err -> String )
336
- -> (Tar. Entry -> Maybe a )
337
- -> Tar. Entries err
336
+ -> (Tar. GenEntry tarPath linkTarget -> Maybe a )
337
+ -> Tar. GenEntries tarPath linkTarget err
338
338
-> UploadMonad [a ]
339
339
selectEntries formatErr select = extract []
340
340
where
341
- extract :: [a ] -> Tar. Entries err -> UploadMonad [a ]
341
+ extract :: [a ] -> Tar. GenEntries tarPath linkTarget err -> UploadMonad [a ]
342
342
extract _ (Tar. Fail err) = throwError (formatErr err)
343
343
extract selected Tar. Done = return selected
344
344
extract selected (Tar. Next entry entries) =
@@ -352,18 +352,20 @@ data CombinedTarErrs =
352
352
| TarBombError FilePath FilePath
353
353
| FutureTimeError FilePath UTCTime UTCTime
354
354
| PermissionsError FilePath Tar. Permissions
355
+ | LongNamesError Tar. DecodeLongNamesError
355
356
356
357
tarballChecks :: Bool -> UTCTime -> FilePath
357
358
-> Tar. Entries Tar. FormatError
358
- -> Tar. Entries CombinedTarErrs
359
+ -> Tar. GenEntries FilePath FilePath CombinedTarErrs
359
360
tarballChecks lax now expectedDir =
360
361
(if not lax then checkFutureTimes now else id )
361
362
. checkTarbomb expectedDir
362
363
. (if not lax then checkUselessPermissions else id )
363
364
. (if lax then ignoreShortTrailer
364
365
else fmapTarError (either id PortabilityError )
365
- . Tar. checkPortability)
366
- . fmapTarError FormatError
366
+ . Tar. mapEntries (\ entry -> maybe (Right entry) Left (Tar. checkEntryPortability entry)))
367
+ . fmapTarError (either FormatError LongNamesError )
368
+ . Tar. decodeLongNames
367
369
where
368
370
ignoreShortTrailer =
369
371
Tar. foldEntries Tar. Next Tar. Done
@@ -373,32 +375,39 @@ tarballChecks lax now expectedDir =
373
375
fmapTarError f = Tar. foldEntries Tar. Next Tar. Done (Tar. Fail . f)
374
376
375
377
checkFutureTimes :: UTCTime
376
- -> Tar. Entries CombinedTarErrs
377
- -> Tar. Entries CombinedTarErrs
378
+ -> Tar. GenEntries FilePath linkTarget CombinedTarErrs
379
+ -> Tar. GenEntries FilePath linkTarget CombinedTarErrs
378
380
checkFutureTimes now =
379
381
checkEntries checkEntry
380
382
where
381
383
-- Allow 30s for client clock skew
382
384
now' = addUTCTime 30 now
385
+
386
+ checkEntry :: Tar. GenEntry FilePath linkTarget -> Maybe CombinedTarErrs
383
387
checkEntry entry
384
388
| entryUTCTime > now'
385
389
= Just (FutureTimeError posixPath entryUTCTime now')
386
390
where
387
391
entryUTCTime = posixSecondsToUTCTime (realToFrac (Tar. entryTime entry))
388
- posixPath = Tar. fromTarPathToPosixPath ( Tar. entryTarPath entry)
392
+ posixPath = Tar. entryTarPath entry
389
393
390
394
checkEntry _ = Nothing
391
395
392
- checkTarbomb :: FilePath -> Tar. Entries CombinedTarErrs -> Tar. Entries CombinedTarErrs
396
+ checkTarbomb
397
+ :: FilePath
398
+ -> Tar. GenEntries FilePath linkTarget CombinedTarErrs
399
+ -> Tar. GenEntries FilePath linkTarget CombinedTarErrs
393
400
checkTarbomb expectedTopDir =
394
401
checkEntries checkEntry
395
402
where
396
403
checkEntry entry =
397
- case splitDirectories (Tar. entryPath entry) of
404
+ case splitDirectories (Tar. entryTarPath entry) of
398
405
(topDir: _) | topDir == expectedTopDir -> Nothing
399
- _ -> Just $ TarBombError (Tar. entryPath entry) expectedTopDir
406
+ _ -> Just $ TarBombError (Tar. entryTarPath entry) expectedTopDir
400
407
401
- checkUselessPermissions :: Tar. Entries CombinedTarErrs -> Tar. Entries CombinedTarErrs
408
+ checkUselessPermissions
409
+ :: Tar. GenEntries FilePath linkTarget CombinedTarErrs
410
+ -> Tar. GenEntries FilePath linkTarget CombinedTarErrs
402
411
checkUselessPermissions =
403
412
checkEntries checkEntry
404
413
where
@@ -410,11 +419,14 @@ checkUselessPermissions =
410
419
where
411
420
checkPermissions expected actual =
412
421
if expected .&. actual /= expected
413
- then Just $ PermissionsError (Tar. entryPath entry) actual
422
+ then Just $ PermissionsError (Tar. entryTarPath entry) actual
414
423
else Nothing
415
424
416
425
417
- checkEntries :: (Tar. Entry -> Maybe e ) -> Tar. Entries e -> Tar. Entries e
426
+ checkEntries
427
+ :: (Tar. GenEntry tarPath linkTarget -> Maybe e )
428
+ -> Tar. GenEntries tarPath linkTarget e
429
+ -> Tar. GenEntries tarPath linkTarget e
418
430
checkEntries checkEntry =
419
431
Tar. foldEntries (\ entry rest -> maybe (Tar. Next entry rest) Tar. Fail
420
432
(checkEntry entry))
@@ -468,6 +480,10 @@ explainTarError (PermissionsError entryname mode) =
468
480
where
469
481
showMode :: Tar. Permissions -> String
470
482
showMode m = printf " %.3o" (fromIntegral m :: Int )
483
+ explainTarError (LongNamesError err) =
484
+ " There is an error in the format of entries with long names in the tar file: " ++ show err
485
+ ++ " . Check that it is a valid tar file (e.g. 'tar -xtf thefile.tar'). "
486
+ ++ " You may need to re-create the package tarball and try again."
471
487
472
488
quote :: String -> String
473
489
quote s = " '" ++ s ++ " '"
0 commit comments