module Hackage.Security.TUF.Paths (
RepoRoot
, RepoPath
, anchorRepoPathLocally
, anchorRepoPathRemotely
, IndexRoot
, IndexPath
, CacheRoot
, CachePath
, anchorCachePath
) where
import Prelude
import Hackage.Security.Util.Path
import Hackage.Security.Util.Pretty
data RepoRoot
type RepoPath = Path RepoRoot
instance Pretty (Path RepoRoot) where
pretty :: Path RepoRoot -> String
pretty (Path String
fp) = String
"<repo>/" String -> String -> String
forall a. [a] -> [a] -> [a]
++ String
fp
anchorRepoPathLocally :: Path root -> RepoPath -> Path root
anchorRepoPathLocally :: forall root. Path root -> Path RepoRoot -> Path root
anchorRepoPathLocally Path root
localRoot Path RepoRoot
repoPath = Path root
localRoot Path root -> Path Unrooted -> Path root
forall a. Path a -> Path Unrooted -> Path a
</> Path RepoRoot -> Path Unrooted
forall root. Path root -> Path Unrooted
unrootPath Path RepoRoot
repoPath
anchorRepoPathRemotely :: Path Web -> RepoPath -> Path Web
anchorRepoPathRemotely :: Path Web -> Path RepoRoot -> Path Web
anchorRepoPathRemotely Path Web
remoteRoot Path RepoRoot
repoPath = Path Web
remoteRoot Path Web -> Path Unrooted -> Path Web
forall a. Path a -> Path Unrooted -> Path a
</> Path RepoRoot -> Path Unrooted
forall root. Path root -> Path Unrooted
unrootPath Path RepoRoot
repoPath
data IndexRoot
type IndexPath = Path IndexRoot
instance Pretty (Path IndexRoot) where
pretty :: Path IndexRoot -> String
pretty (Path String
fp) = String
"<index>/" String -> String -> String
forall a. [a] -> [a] -> [a]
++ String
fp
data CacheRoot
type CachePath = Path CacheRoot
instance Pretty (Path CacheRoot) where
pretty :: Path CacheRoot -> String
pretty (Path String
fp) = String
"<cache>/" String -> String -> String
forall a. [a] -> [a] -> [a]
++ String
fp
anchorCachePath :: Path root -> CachePath -> Path root
anchorCachePath :: forall root. Path root -> Path CacheRoot -> Path root
anchorCachePath Path root
cacheRoot Path CacheRoot
cachePath = Path root
cacheRoot Path root -> Path Unrooted -> Path root
forall a. Path a -> Path Unrooted -> Path a
</> Path CacheRoot -> Path Unrooted
forall root. Path root -> Path Unrooted
unrootPath Path CacheRoot
cachePath