Modulehackage-security-0.6.3.2Haskell2010
Hackage.Security.Client.Repository
Abstract definition of a Repository
Most clients should only need to import this module if they wish to define their own Repository implementations.
- 11 types
- 1 class
- 6 values
- Packagehackage-security-0.6.3.2
- Exports18
- LanguageHaskell2010
- LicenceBSD-3-Clause
- SourceRepository.hs
Files
7 declarationsAbstract definition of files we might have to download
RemoteFile is parametrized by the type of the formats that we can accept from the remote repository, as well as with information on whether this file is metadata actual binary content.
NOTE: Haddock lacks GADT support so constructors have only regular comments.
Constructors
RemoteTimestamp :: RemoteFile (FormatUn :- ()) MetadataRemoteRoot :: Maybe (Trusted FileInfo) -> RemoteFile (FormatUn :- ()) MetadataRemoteSnapshot :: Trusted FileInfo -> RemoteFile (FormatUn :- ()) MetadataRemoteMirrors :: Trusted FileInfo -> RemoteFile (FormatUn :- ()) MetadataRemoteIndex :: HasFormat a FormatGz -> Formats a (Trusted FileInfo) -> RemoteFile a BinaryRemotePkgTarGz :: PackageIdentifier -> Trusted FileInfo -> RemoteFile (FormatGz :- ()) Binary
Instances2Show, Pretty
Show (RemoteFile fs typ)Defined in hackage-security-0.6.3.2 · Hackage.Security.Client.RepositoryPretty (RemoteFile fs typ)Defined in hackage-security-0.6.3.2 · Hackage.Security.Client.Repository
Files that we might request from the local cache
Constructors
CachedTimestampTimestamp metadata (
timestamp.json)CachedRootRoot metadata (
root.json)CachedSnapshotSnapshot metadata (
snapshot.json)CachedMirrorsMirrors list (
mirrors.json)
Instances4Eq, Ord, Show, Pretty
Eq CachedFileDefined in hackage-security-0.6.3.2 · Hackage.Security.Client.RepositoryOrd CachedFileDefined in hackage-security-0.6.3.2 · Hackage.Security.Client.RepositoryShow CachedFileDefined in hackage-security-0.6.3.2 · Hackage.Security.Client.RepositoryPretty CachedFileDefined in hackage-security-0.6.3.2 · Hackage.Security.Client.Repository
Files that we might request from the index
The type index tells us the type of the decoded file, if any. For files for
which the library does not support decoding this will be ().
NOTE: Clients should NOT rely on this type index being (), or they might
break if we add support for parsing additional file formats in the future.
TODO: If we wanted to support legacy Hackage, we should also have a case for the global preferred-versions file. But supporting legacy Hackage will probably require more work anyway..
Constructors
IndexPkgMetadata :: PackageIdentifier -> IndexFile (Signed Targets)IndexPkgCabal :: PackageIdentifier -> IndexFile ()IndexPkgPrefs :: PackageName -> IndexFile ()
Instances4SomePretty, SomeShow, Show, Pretty
SomePretty IndexFileDefined in hackage-security-0.6.3.2 · Hackage.Security.TUF.Layout.IndexSomeShow IndexFileDefined in hackage-security-0.6.3.2 · Hackage.Security.TUF.Layout.IndexShow (IndexFile dec)Defined in hackage-security-0.6.3.2 · Hackage.Security.TUF.Layout.IndexPretty (IndexFile dec)Defined in hackage-security-0.6.3.2 · Hackage.Security.TUF.Layout.Index
Default format for each file type
For most file types we don't have a choice; for the index the repository is only required to offer the GZip-compressed format so that is the default.
Default file info (see also remoteFileDefaultFormat)
Repository proper
5 declarationsRepository
This is an abstract representation of a repository. It simply provides a way to download metafiles and target files, without specifying how this is done. For instance, for a local repository this could just be doing a file read, whereas for remote repositories this could be using any kind of HTTP client.
Constructors
DownloadedFile down => RepositoryrepGetRemote :: forall fs typ. Throws SomeRemoteError => AttemptNr -> RemoteFile fs typ -> Verify (Some (HasFormat fs), down typ)Get a file from the server
Responsibilies of repGetRemote:
Download the file from the repository and make it available at a temporary location
Use the provided file length to protect against endless data attacks. (Repositories such as local repositories that are not susceptible to endless data attacks can safely ignore this argument.)
Move the file from its temporary location to its permanent location if verification succeeds.
NOTE: Calls to repGetRemote should _always_ be in the scope of repWithMirror.
repGetCached :: CachedFile -> IO (Maybe (Path Absolute))Get a cached file (if available)
repGetCachedRoot :: IO (Path Absolute)Get the cached root
This is a separate method only because clients must ALWAYS have root information available.
repClearCache :: IO ()Clear all cached data
In particular, this should remove the snapshot and the timestamp. It would also be okay, but not required, to delete the index.
repWithIndex :: forall a. (Handle -> IO a) -> IO aOpen the tarball for reading
This function has this shape so that:
We can read multiple files from the tarball without having to open and close the handle each time
We can close the handle immediately when done.
repGetIndexIdx :: IO TarIndexRead the index index
repLockCache :: IO () -> IO ()Lock the cache (during updates)
repWithMirror :: forall a. Maybe [Mirror] -> IO a -> IO aMirror selection
The purpose of repWithMirror is to scope mirror selection. The idea is that if we have
repWithMirror mirrorList $ someCallbackthen the repository may pick a mirror before calling
someCallback, catch exceptions thrown bysomeCallback, and potentially try the callback again with a different mirror.The list of mirrors may be
Nothingif we haven't yet downloaded the list of mirrors from the repository, or when our cached list of mirrors is invalid. Of course, if we did download it, then the list of mirrors may still be empty. In this case the repository must fall back to its primary download mechanism.Mirrors as currently defined (in terms of a "base URL") are inherently a HTTP (or related) concept, so in repository implementations such as the local-repo
repWithMirrorsis probably just an identity operation (seeignoreMirrors). Conversely, HTTP implementations of repositories may have other, out-of-band information (for example, coming from a cabal config file) that they may use to influence mirror selection.repLog :: LogMessage -> IO ()Logging
repLayout :: RepoLayoutLayout of this repository
repIndexLayout :: IndexLayoutLayout of the index
Since the repository hosts the index, the layout of the index is not independent of the layout of the repository.
repDescription :: StringDescription of the repository (used in the show instance)
Instances1Show
Show (Repository down)Defined in hackage-security-0.6.3.2 · Hackage.Security.Client.Repository
Are we requesting this information because of a previous validation error?
Clients can take advantage of this to tell caches to revalidate files.
Log messages
We use a RemoteFile rather than a RepoPath here because we might not have a RepoPath for the file that we were trying to download (that is, for example if the server does not provide an uncompressed tarball, it doesn't make much sense to list the path to that non-existing uncompressed tarball).
Constructors
LogRootUpdatedRoot information was updated
This message is issued when the root information is updated as part of the normal check for updates procedure. If the root information is updated because of a verification error WarningVerificationError is issued instead.
LogVerificationError VerificationErrorA verification error
Verification errors can be temporary, and may be resolved later; hence these are just warnings. (Verification errors that cannot be resolved are thrown as exceptions.)
forall fs typ. LogDownloading (RemoteFile fs typ)Download a file from a repository
forall fs. LogUpdating (RemoteFile fs Binary)Incrementally updating a file from a repository
LogSelectedMirror MirrorDescriptionSelected a particular mirror
forall fs. LogCannotUpdate (RemoteFile fs Binary) UpdateFailureUpdating a file failed (we will instead download it whole)
LogMirrorFailed MirrorDescription SomeExceptionWe got an exception with a particular mirror (we will try with a different mirror if any are available)
LogLockWait (Path Absolute)This log event is triggered before invoking a filesystem lock operation that may block for a significant amount of time; once the possibly blocking call completes successfully, LogLockWaitDone will be emitted.
LogLockWaitDone (Path Absolute)Denotes completion of the operation that advertised a LogLockWait event
LogUnlock (Path Absolute)Denotes the filesystem lock previously acquired (signaled by LogLockWait) has been released.
Instances1Pretty
Pretty LogMessageDefined in hackage-security-0.6.3.2 · Hackage.Security.Client.Repository
Records why we are downloading a file rather than updating it.
Constructors
UpdateImpossibleUnsupportedServer does not support incremental downloads
UpdateImpossibleNoLocalCopyWe don't have a local copy of the file to update
UpdateFailedTwiceUpdate failed twice
If we attempt an incremental update the first time, and it fails, we let it go round the loop, update local security information, and try again. But if an incremental update then fails _again_, we instead attempt a regular download.
UpdateFailed SomeExceptionUpdate failed (for example: perhaps the local file got corrupted)
Instances1Pretty
Pretty UpdateFailureDefined in hackage-security-0.6.3.2 · Hackage.Security.Client.Repository
Repository-specific exceptions
For instance, for repositories using HTTP this might correspond to a 404; for local repositories this might correspond to file-not-found, etc.
Constructors
SomeRemoteError :: Exception e => e -> SomeRemoteError
Instances3Show, Exception, Pretty
Show SomeRemoteErrorDefined in hackage-security-0.6.3.2 · Hackage.Security.Client.RepositoryException SomeRemoteErrorDefined in hackage-security-0.6.3.2 · Hackage.Security.Client.RepositoryPretty SomeRemoteErrorDefined in hackage-security-0.6.3.2 · Hackage.Security.Client.Repository
Downloaded files
Methods
downloadedVerify :: down a -> Trusted FileInfo -> IO BoolVerify a download file
downloadedRead :: down Metadata -> IO ByteStringRead the file we just downloaded into memory
We never read binary data, only metadata.
downloadedCopyTo :: down a -> Path Absolute -> IO ()Copy a downloaded file to its destination
Instances2DownloadedFile
DownloadedFile LocalFileDefined in hackage-security-0.6.3.2 · Hackage.Security.Client.Repository.LocalDownloadedFile RemoteTempDefined in hackage-security-0.6.3.2 · Hackage.Security.Client.Repository.Remote
Helpers
Helper function to implement repWithMirrors.
Paths
2 declarationsUtility
2 declarationsIs a particular remote file cached?
Constructors
Which remote files should we cache locally?