Skip to content

Commit

Permalink
Rework ResolvedSourcePackage (take three)
Browse files Browse the repository at this point in the history
Very well
  • Loading branch information
andreabedini committed Apr 26, 2024
1 parent eada91e commit 7c76f75
Show file tree
Hide file tree
Showing 15 changed files with 1,081 additions and 869 deletions.
8 changes: 4 additions & 4 deletions cabal-install/cabal-install.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -162,9 +162,10 @@ library
Distribution.Client.Reconfigure
Distribution.Client.ReplFlags
Distribution.Client.Repository
Distribution.Client.Repository.Class
Distribution.Client.Repository.Secure
Distribution.Client.Repository.Cache
Distribution.Client.Repository.IndexCache
Distribution.Client.Repository.Legacy
Distribution.Client.Repository.PreferredVersions
Distribution.Client.Run
Distribution.Client.Sandbox
Distribution.Client.Sandbox.PackageEnvironment
Expand Down Expand Up @@ -238,8 +239,7 @@ library
regex-base >= 0.94.0.0 && <0.95,
regex-posix >= 0.96.0.0 && <0.97,
safe-exceptions >= 0.1.7.0 && < 0.2,
semaphore-compat >= 1.0.0 && < 1.1,
some
semaphore-compat >= 1.0.0 && < 1.1

if flag(native-dns)
if os(windows)
Expand Down
12 changes: 6 additions & 6 deletions cabal-install/src/Distribution/Client/BuildReports/Storage.hs
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ import System.FilePath
, (</>)
)

storeAnonymous :: [(BuildReport, Maybe (Some Repo))] -> IO ()
storeAnonymous :: [(BuildReport, Maybe Repo)] -> IO ()
storeAnonymous reports =
sequence_
[ appendFile file (concatMap format reports')
Expand All @@ -95,16 +95,16 @@ storeAnonymous reports =
separate =
map (\rs@((_, repo, _) : _) -> (repo, [r | (r, _, _) <- rs]))
. map (concatMap toList)
. L.groupBy (equating (repoName' . head))
. sortBy (comparing (repoName' . head))
. groupBy (equating repoName')
. L.groupBy (equating (repositoryName' . head))
. sortBy (comparing (repositoryName' . head))
. groupBy (equating repositoryName')
. onlyRemote

repoName' (_, _, rrepo) = remoteRepoName rrepo
repositoryName' (_, _, rrepo) = repositoryName rrepo

onlyRemote
:: [(BuildReport, Maybe Repo)]
-> [(BuildReport, Repo, RemoteRepo)]
-> [(BuildReport, Repo, Repo'Remote)]
onlyRemote rs =
[ (report, repo, remoteRepo)
| (report, Just repo) <- rs
Expand Down
20 changes: 10 additions & 10 deletions cabal-install/src/Distribution/Client/FetchUtils.hs
Original file line number Diff line number Diff line change
Expand Up @@ -137,15 +137,15 @@ checkFetched loc = case loc of
(checkRepoTarballFetched repo pkgid)

-- | Like 'checkFetched' but for the specific case of a 'RepoTarballPackage'.
checkRepoTarballFetched :: Some Repo -> PackageId -> IO (Maybe FilePath)
checkRepoTarballFetched :: Repo -> PackageId -> IO (Maybe FilePath)
checkRepoTarballFetched repo pkgid = do
let file = packageFile repo pkgid
exists <- doesFileExist file
if exists
then return (Just file)
else return Nothing

verifyFetchedTarball :: Verbosity -> RepoContext -> Some Repo -> PackageId -> IO Bool
verifyFetchedTarball :: Verbosity -> RepoContext -> Repo -> PackageId -> IO Bool
verifyFetchedTarball verbosity repoCtxt repo pkgid =
let file = packageFile repo pkgid
handleError :: IO Bool -> IO Bool
Expand All @@ -160,7 +160,7 @@ verifyFetchedTarball verbosity repoCtxt repo pkgid =
then return True -- if the file does not exist, it vacuously passes validation, since it will be downloaded as necessary with what we will then check is a valid hash.
else case repo of
-- a secure repo has hashes we can compare against to confirm this is the correct file.
Some (RepoSecure repo') ->
RepoSecure repo' ->
repoContextWithSecureRepo repoCtxt repo' $ \repoSecure ->
Sec.withIndex repoSecure $ \callbacks ->
let warnAndFail s = warn verbosity ("Fetched tarball " ++ file ++ " does not match server, will redownload: " ++ s) >> return False
Expand Down Expand Up @@ -218,7 +218,7 @@ fetchPackage verbosity repoCtxt loc = case loc of
return path

-- | Fetch a repo package if we don't have it already.
fetchRepoTarball :: Verbosity -> RepoContext -> Some Repo -> PackageId -> IO FilePath
fetchRepoTarball :: Verbosity -> RepoContext -> Repo -> PackageId -> IO FilePath
fetchRepoTarball verbosity' repoCtxt repo pkgid = do
fetched <- doesFileExist (packageFile repo pkgid)
if fetched
Expand All @@ -236,9 +236,9 @@ fetchRepoTarball verbosity' repoCtxt repo pkgid = do

downloadRepoPackage :: IO FilePath
downloadRepoPackage = case repo of
Some RepoLocalNoIndex{} ->
RepoLocalNoIndex{} ->
return (packageFile repo pkgid)
Some (RepoLegacy (Located _ legacyRepo)) -> do
RepoLegacy (Located _ legacyRepo) -> do
transport <- repoContextGetTransport repoCtxt
remoteRepoCheckHttps verbosity transport legacyRepo
let uri = packageURI legacyRepo pkgid
Expand All @@ -247,7 +247,7 @@ fetchRepoTarball verbosity' repoCtxt repo pkgid = do
createDirectoryIfMissing True dir
_ <- downloadURI transport verbosity uri path
return path
Some (RepoSecure repo') ->
RepoSecure repo' ->
repoContextWithSecureRepo repoCtxt repo' $ \rep -> do
let dir = packageDir repo pkgid
path = packageFile repo pkgid
Expand Down Expand Up @@ -360,16 +360,16 @@ waitAsyncFetchPackage verbosity downloadMap srcloc =

-- | Generate the full path to the locally cached copy of
-- the tarball for a given @PackageIdentifier@.
packageFile :: Some Repo -> PackageId -> FilePath
packageFile :: Repo -> PackageId -> FilePath
packageFile repo pkgid =
packageDir repo pkgid
</> prettyShow pkgid
<.> "tar.gz"

-- | Generate the full path to the directory where the local cached copy of
-- the tarball for a given @PackageIdentifier@ is stored.
packageDir :: Some Repo -> PackageId -> FilePath
packageDir (Some (RepoLocalNoIndex (Located _ (LocalRepo _ dir _)))) _pkgid = dir
packageDir :: Repo -> PackageId -> FilePath
packageDir (RepoLocalNoIndex (Located _ (LocalRepo _ dir _))) _pkgid = dir
packageDir repo pkgid =
repoLocalDir repo
</> prettyShow (packageName pkgid)
Expand Down
Loading

0 comments on commit 7c76f75

Please sign in to comment.