Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prevent "Unsupported tarball" exception upon download of Git dependency containing problematic symlinks #64

Closed
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 9 additions & 5 deletions src/Pantry/Archive.hs
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,7 @@ foldTar loc accum0 f = do
_ -> throwIO exc
pure $
(\met -> MetaEntry
{ mePath = Tar.getFileInfoPath fi
{ mePath = removeInitialDotSlash . Tar.getFileInfoPath $ fi
, meType = met
})
<$> mmet
Expand All @@ -356,6 +356,10 @@ data SimpleEntry = SimpleEntry
}
deriving Show

removeInitialDotSlash :: FilePath -> FilePath
removeInitialDotSlash filename =
maybe filename T.unpack (T.stripPrefix "./" $ T.pack filename)
mpilgrem marked this conversation as resolved.
Show resolved Hide resolved

-- | Attempt to parse the contents of the given archive in the given subdir into
-- a 'Tree'. This will not consult any caches. It will ensure that:
--
Expand All @@ -380,7 +384,7 @@ parseArchive rpli archive fp = do
logDebug $ "parseArchive of " <> display at <> ": " <> displayShow e
getFiles ats
Right files -> pure (at, Map.fromList $ map (mePath &&& id) $ files [])
(at :: ArchiveType, files :: Map FilePath MetaEntry) <- getFiles [minBound..maxBound]
(at :: ArchiveType, files :: Map FilePath MetaEntry) <- second (Map.mapKeys removeInitialDotSlash) <$> getFiles [minBound..maxBound]
let toSimple :: FilePath -> MetaEntry -> Either String (Map FilePath SimpleEntry)
toSimple key me =
case meType me of
Expand Down Expand Up @@ -475,10 +479,10 @@ parseArchive rpli archive fp = do
pure $ Map.insert (mePath me) (blobKey, blobId) m
else pure m
tree :: CachedTree <- fmap (CachedTreeMap . Map.fromList) $ for safeFiles $ \(sfp, se) ->
case Map.lookup (seSource se) blobs of
Nothing ->
case Map.lookup (removeInitialDotSlash . seSource $ se) blobs of
Nothing ->
error $ "Impossible: blob not found for: " ++ seSource se
Just (blobKey, blobId) ->
Just (blobKey, blobId) ->
pure (sfp, (TreeEntry blobKey (seType se), blobId))
-- parse the cabal file and ensure it has the right name
buildFile <- findCabalOrHpackFile rpli $ unCachedTree tree
Expand Down