module Hackage.Security.Client.Repository.Local (
LocalRepo
, withRepository
) where
import Hackage.Security.Client.Repository
import Hackage.Security.Client.Repository.Cache
import Hackage.Security.Client.Formats
import Hackage.Security.TUF
import Hackage.Security.Util.Path
import Hackage.Security.Util.Pretty
import Hackage.Security.Util.Some
type LocalRepo = Path (Rooted Absolute)
withRepository
:: LocalRepo
-> Cache
-> RepoLayout
-> (LogMessage -> IO ())
-> (Repository -> IO a)
-> IO a
withRepository repo cache repLayout logger callback = callback Repository {
repWithRemote = withRemote repLayout repo cache
, repGetCached = getCached cache
, repGetCachedRoot = getCachedRoot cache
, repClearCache = clearCache cache
, repGetFromIndex = getFromIndex cache (repoIndexLayout repLayout)
, repWithMirror = mirrorsUnsupported
, repLog = logger
, repLayout = repLayout
, repDescription = "Local repository at " ++ pretty repo
}
withRemote :: RepoLayout -> LocalRepo -> Cache
-> IsRetry
-> RemoteFile fs
-> (forall f. HasFormat fs f -> TempPath -> IO a)
-> IO a
withRemote repoLayout repo cache _isRetry remoteFile callback = do
case remoteFileDefaultFormat remoteFile of
Some format -> do
let remotePath' = remoteRepoPath' repoLayout remoteFile format
remotePath = anchorRepoPathLocally repo remotePath'
result <- callback format remotePath
cacheRemoteFile cache
remotePath
(hasFormatGet format)
(mustCache remoteFile)
return result