module Hackage.Security.TUF.Layout.Repo (
RepoLayout(..)
, hackageRepoLayout
, cabalLocalRepoLayout
) where
import Distribution.Package
import Distribution.Text
import Hackage.Security.TUF.Paths
import Hackage.Security.Util.Path
data RepoLayout = RepoLayout {
repoLayoutRoot :: RepoPath
, repoLayoutTimestamp :: RepoPath
, repoLayoutSnapshot :: RepoPath
, repoLayoutMirrors :: RepoPath
, repoLayoutIndexTarGz :: RepoPath
, repoLayoutIndexTar :: RepoPath
, repoLayoutPkgTarGz :: PackageIdentifier -> RepoPath
}
hackageRepoLayout :: RepoLayout
hackageRepoLayout = RepoLayout {
repoLayoutRoot = rp $ fragment "root.json"
, repoLayoutTimestamp = rp $ fragment "timestamp.json"
, repoLayoutSnapshot = rp $ fragment "snapshot.json"
, repoLayoutMirrors = rp $ fragment "mirrors.json"
, repoLayoutIndexTarGz = rp $ fragment "01-index.tar.gz"
, repoLayoutIndexTar = rp $ fragment "01-index.tar"
, repoLayoutPkgTarGz = \pkgId -> rp $ fragment "package" </> pkgFile pkgId
}
where
pkgFile :: PackageIdentifier -> Path Unrooted
pkgFile pkgId = fragment (display pkgId) <.> "tar.gz"
rp :: Path Unrooted -> RepoPath
rp = rootPath
cabalLocalRepoLayout :: RepoLayout
cabalLocalRepoLayout = hackageRepoLayout {
repoLayoutPkgTarGz = \pkgId -> rp $ pkgLoc pkgId </> pkgFile pkgId
}
where
pkgLoc :: PackageIdentifier -> Path Unrooted
pkgLoc pkgId = joinFragments [
display (packageName pkgId)
, display (packageVersion pkgId)
]
pkgFile :: PackageIdentifier -> Path Unrooted
pkgFile pkgId = fragment (display pkgId) <.> "tar.gz"
rp :: Path Unrooted -> RepoPath
rp = rootPath