Copyright | (c) Julian Ospald 2020 |
---|---|
License | LGPL-3.0 |
Maintainer | hasufell@hasufell.de |
Stability | experimental |
Portability | portable |
Safe Haskell | None |
Language | Haskell2010 |
Module for handling all download related functions.
Generally we support downloading via:
- curl (default)
- wget
- internal downloader (only when compiled)
Synopsis
- getDownloadsF :: (FromJSONKey Tool, FromJSONKey Version, FromJSON VersionInfo, MonadReader env m, HasSettings env, HasDirs env, MonadIO m, MonadCatch m, HasLog env, MonadThrow m, MonadFail m, MonadMask m) => Excepts '[DigestError, GPGError, JSONError, DownloadFailed, FileDoesNotExistError] m GHCupInfo
- yamlFromCache :: (MonadReader env m, HasDirs env) => URI -> m FilePath
- etagsFile :: FilePath -> FilePath
- getBase :: (MonadReader env m, HasDirs env, HasSettings env, MonadFail m, MonadIO m, MonadCatch m, HasLog env, MonadMask m) => URI -> Excepts '[GPGError, DigestError, JSONError, FileDoesNotExistError] m GHCupInfo
- getDownloadInfo :: (MonadReader env m, HasPlatformReq env, HasGHCupInfo env) => Tool -> Version -> Excepts '[NoDownload] m DownloadInfo
- download :: (MonadReader env m, HasSettings env, HasDirs env, MonadMask m, MonadThrow m, HasLog env, MonadIO m) => URI -> Maybe URI -> Maybe Text -> FilePath -> Maybe FilePath -> Bool -> Excepts '[DigestError, DownloadFailed, GPGError] m FilePath
- downloadCached :: (MonadReader env m, HasDirs env, HasSettings env, MonadMask m, MonadResource m, MonadThrow m, HasLog env, MonadIO m, MonadUnliftIO m) => DownloadInfo -> Maybe FilePath -> Excepts '[DigestError, DownloadFailed, GPGError] m FilePath
- downloadCached' :: (MonadReader env m, HasDirs env, HasSettings env, MonadMask m, MonadThrow m, HasLog env, MonadIO m, MonadUnliftIO m) => DownloadInfo -> Maybe FilePath -> Maybe FilePath -> Excepts '[DigestError, DownloadFailed, GPGError] m FilePath
- checkDigest :: (MonadReader env m, HasDirs env, HasSettings env, MonadIO m, MonadThrow m, HasLog env) => Text -> FilePath -> Excepts '[DigestError] m ()
- getCurlOpts :: IO [String]
- getWgetOpts :: IO [String]
- getGpgOpts :: IO [String]
- urlBaseName :: ByteString -> ByteString
- getLastHeader :: Text -> Text
- tmpFile :: FilePath -> FilePath
Documentation
getDownloadsF :: (FromJSONKey Tool, FromJSONKey Version, FromJSON VersionInfo, MonadReader env m, HasSettings env, HasDirs env, MonadIO m, MonadCatch m, HasLog env, MonadThrow m, MonadFail m, MonadMask m) => Excepts '[DigestError, GPGError, JSONError, DownloadFailed, FileDoesNotExistError] m GHCupInfo Source #
Downloads the download information! But only if we need to ;P
yamlFromCache :: (MonadReader env m, HasDirs env) => URI -> m FilePath Source #
getBase :: (MonadReader env m, HasDirs env, HasSettings env, MonadFail m, MonadIO m, MonadCatch m, HasLog env, MonadMask m) => URI -> Excepts '[GPGError, DigestError, JSONError, FileDoesNotExistError] m GHCupInfo Source #
:: (MonadReader env m, HasPlatformReq env, HasGHCupInfo env) | |
=> Tool | |
-> Version | tool version |
-> Excepts '[NoDownload] m DownloadInfo |
:: (MonadReader env m, HasSettings env, HasDirs env, MonadMask m, MonadThrow m, HasLog env, MonadIO m) | |
=> URI | |
-> Maybe URI | URI for gpg sig |
-> Maybe Text | expected hash |
-> FilePath | destination dir (ignored for file:// scheme) |
-> Maybe FilePath | optional filename |
-> Bool | whether to read an write etags |
-> Excepts '[DigestError, DownloadFailed, GPGError] m FilePath |
Tries to download from the given http or https url and saves the result in continuous memory into a file. If the filename is not provided, then we: 1. try to guess the filename from the url path 2. otherwise create a random file
The file must not exist.
:: (MonadReader env m, HasDirs env, HasSettings env, MonadMask m, MonadResource m, MonadThrow m, HasLog env, MonadIO m, MonadUnliftIO m) | |
=> DownloadInfo | |
-> Maybe FilePath | optional filename |
-> Excepts '[DigestError, DownloadFailed, GPGError] m FilePath |
Download into tmpdir or use cached version, if it exists. If filename is omitted, infers the filename from the url.
:: (MonadReader env m, HasDirs env, HasSettings env, MonadMask m, MonadThrow m, HasLog env, MonadIO m, MonadUnliftIO m) | |
=> DownloadInfo | |
-> Maybe FilePath | optional filename |
-> Maybe FilePath | optional destination dir (default: cacheDir) |
-> Excepts '[DigestError, DownloadFailed, GPGError] m FilePath |
:: (MonadReader env m, HasDirs env, HasSettings env, MonadIO m, MonadThrow m, HasLog env) | |
=> Text | the hash |
-> FilePath | |
-> Excepts '[DigestError] m () |
getCurlOpts :: IO [String] Source #
Get additional curl args from env. This is an undocumented option.
getWgetOpts :: IO [String] Source #
Get additional wget args from env. This is an undocumented option.
getGpgOpts :: IO [String] Source #
Get additional gpg args from env. This is an undocumented option.
:: ByteString | the url path (without scheme and host) |
-> ByteString |
Get the url base name.
>>>
urlBaseName "/foo/bar/baz"
"baz"
getLastHeader :: Text -> Text Source #
Curl saves all intermediate connect headers as well, not just the last one, so we make an effort to take the last HTTP block only. Passing '--suppress-connect-headers' would be better, but it isn't supported by all versions, also see: https://gitlab.haskell.org/haskell/ghcup-hs/-/issues/213
>>>
getLastHeader "\n\nHTTP/1.0 200 Connection established\n\nHTTP/1.1 304 Not Modified\n"
"HTTP/1.1 304 Not Modified\n">>>
getLastHeader "HTTP/1.1 304 Not Modified\n"
"HTTP/1.1 304 Not Modified\n"