Distribution.Client.FetchUtils

cabal-install-3.12.1.0: The command-line interface for Cabal and Hackage.

Copyright | (c) David Himmelstrup 2005 Duncan Coutts 2011
License | BSD-like
Maintainer | cabal-devel@gmail.com
Stability | provisional
Portability | portable
Safe Haskell | None
Language | Haskell2010

Distribution.Client.FetchUtils

Contents

- fetching packages
  - specifically for repo packages
  - fetching packages asynchronously
- fetching other things

Description

Functions for fetching packages

Synopsis

- fetchPackage :: Verbosity -> RepoContext -> UnresolvedPkgLoc -> IO ResolvedPkgLoc
- isFetched :: UnresolvedPkgLoc -> IO Bool
- checkFetched :: UnresolvedPkgLoc -> IO (Maybe ResolvedPkgLoc)
- checkRepoTarballFetched :: Repo -> PackageId -> IO (Maybe FilePath)
- fetchRepoTarball :: Verbosity -> RepoContext -> Repo -> PackageId -> IO FilePath
- verifyFetchedTarballs :: Verbosity -> RepoContext -> Repo -> [PackageId] -> IO [Either (Repo, PackageId) (Repo, PackageId)]
- asyncFetchPackages :: Verbosity -> RepoContext -> [UnresolvedPkgLoc] -> (AsyncFetchMap -> IO a) -> IO a
- waitAsyncFetchPackage :: Verbosity -> AsyncFetchMap -> UnresolvedPkgLoc -> IO ResolvedPkgLoc
- type AsyncFetchMap = Map UnresolvedPkgLoc (MVar (Either SomeException ResolvedPkgLoc))
- downloadIndex :: HttpTransport -> Verbosity -> RemoteRepo -> FilePath -> IO DownloadResult

# fetching packages

fetchPackage :: Verbosity -> RepoContext -> UnresolvedPkgLoc -> IO ResolvedPkgLoc #

Fetch a package if we don't have it already.

isFetched :: UnresolvedPkgLoc -> IO Bool #

Returns `True` if the package has already been fetched or does not need fetching.

checkFetched :: UnresolvedPkgLoc -> IO (Maybe ResolvedPkgLoc) #

Checks if the package has already been fetched (or does not need fetching) and if so returns evidence in the form of a `PackageLocation` with a resolved local file location.

## specifically for repo packages

checkRepoTarballFetched :: Repo -> PackageId -> IO (Maybe FilePath) #

Like `checkFetched` but for the specific case of a `RepoTarballPackage`.

fetchRepoTarball :: Verbosity -> RepoContext -> Repo -> PackageId -> IO FilePath #

Fetch a repo package if we don't have it already.

verifyFetchedTarballs :: Verbosity -> RepoContext -> Repo -> [PackageId] -> IO [Either (Repo, PackageId) (Repo, PackageId)] #

## fetching packages asynchronously

asyncFetchPackages :: Verbosity -> RepoContext -> [UnresolvedPkgLoc] -> (AsyncFetchMap -> IO a) -> IO a #

Fork off an async action to download the given packages (by location).

The downloads are initiated in order, so you can arrange for packages that will likely be needed sooner to be earlier in the list.

The body action is passed a map from those packages (identified by their location) to a completion var for that package. So the body action should lookup the location and use `waitAsyncFetchPackage` to get the result.

Synchronous exceptions raised by the download actions are delivered via `waitAsyncFetchPackage`.

waitAsyncFetchPackage :: Verbosity -> AsyncFetchMap -> UnresolvedPkgLoc -> IO ResolvedPkgLoc #

Expect to find a download in progress in the given `AsyncFetchMap` and wait on it to finish.

If the download failed with an exception then this will be thrown.

Note: This function is supposed to be idempotent, as our install plans can now use the same tarball for many builds, e.g. different components and/or qualified goals, and these all go through the download phase so we end up using `waitAsyncFetchPackage` twice on the same package. C.f. #4461.

type AsyncFetchMap = Map UnresolvedPkgLoc (MVar (Either SomeException ResolvedPkgLoc)) #

# fetching other things

downloadIndex :: HttpTransport -> Verbosity -> RemoteRepo -> FilePath -> IO DownloadResult #

Downloads an index file to [config-dirpackagesserv-id] without hackage-security. You probably don't want to call this directly; use `updateRepo` instead.