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