Skip to content

Commit

Permalink
Better types for repositories WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
andreabedini committed Apr 26, 2024
1 parent f27cd58 commit 40366fc
Show file tree
Hide file tree
Showing 2 changed files with 77 additions and 1 deletion.
4 changes: 3 additions & 1 deletion cabal-install/src/Distribution/Client/IndexUtils.hs
Original file line number Diff line number Diff line change
Expand Up @@ -421,6 +421,7 @@ data RepoData = RepoData
-- All the 'SourcePackage's are marked as having come from the given 'Repo'.
--
-- This is a higher level wrapper used internally in cabal-install.
-- TODO:
readRepoIndex
:: Verbosity
-> RepoContext
Expand Down Expand Up @@ -759,10 +760,11 @@ indexFile (RepoIndex _ctxt repo) = indexBaseName repo <.> "tar"
cacheFile :: Index -> FilePath
cacheFile (RepoIndex _ctxt repo) = indexBaseName repo <.> "cache"

timestampFile :: Index -> FilePath
timestampFile :: Repo -> FilePath
timestampFile (RepoIndex _ctxt repo) = indexBaseName repo <.> "timestamp"

-- | Return 'True' if 'Index' uses 01-index format (aka secure repo)
-- is01Repo ??
is01Index :: Index -> Bool
is01Index (RepoIndex _ repo) = case repo of
RepoSecure{} -> True
Expand Down
74 changes: 74 additions & 0 deletions cabal-install/src/Distribution/Client/Types/Repo.hs
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE FlexibleInstances #-}

module Distribution.Client.Types.Repo
( -- * Remote repository
Expand Down Expand Up @@ -31,6 +35,11 @@ import qualified Distribution.Compat.CharParsing as P
import qualified Text.PrettyPrint as Disp

import Distribution.Client.Types.RepoName
import Distribution.Make (Dependency)
import qualified Data.ByteString as BSS
import Distribution.Types.GenericPackageDescription
import Distribution.Client.IndexUtils.Timestamp
import Distribution.Client.IndexUtils.IndexState (RepoIndexState)

-------------------------------------------------------------------------------
-- Remote repository
Expand Down Expand Up @@ -175,6 +184,71 @@ data Repo
instance Binary Repo
instance Structured Repo

-- Repo -> Index (~ tarball) -> ?IndexState -> Cache'
-- LocalNoIndex -> () -> () -> Cache' (RepoIndexState r)
-- RemoteRepo -> Tarball -> () -> CacheWithNoTimestamp
-- SecureRepo -> HackageSecurity -> IndexStateInfo -> CacheWithTimestamp

data PackageId
data BlockNo
data BuildTreeRefType
data IndexStateInfo

data NoTimestamp
data NoIndexState

newtype SecureRepo = SecureRepo RemoteRepo

data HasIndexState
data HasNoIndexState

class IsCache c where

class (IsCache (Cache r)) => IsRepo r where
type RepoHasIndexState r
type Cache r

instance IsCache NoIndexCache
instance IsCache (IndexCache Timestamp)
instance IsCache (IndexCache NoTimestamp)

instance IsRepo LocalRepo where
type RepoHasIndexState LocalRepo = NoIndexState
type Cache LocalRepo = NoIndexCache

instance IsRepo RemoteRepo where
type RepoHasIndexState RemoteRepo = NoIndexState
type Cache RemoteRepo = IndexCache NoTimestamp

instance IsRepo SecureRepo where
type RepoHasIndexState SecureRepo = IndexStateInfo
type Cache SecureRepo = IndexCache Timestamp

data IndexCache ts = IndexCache
{ cacheHeadTs :: ts
, cacheEntries :: [IndexCacheEntry ts]
}

data IndexCacheEntry ts
= CachePackageId PackageId !BlockNo !ts
| CachePreference Dependency !BlockNo !ts
| CacheBuildTreeRef !BuildTreeRefType !BlockNo

newtype NoIndexCache = NoIndexCache
{ noIndexCacheEntries :: [NoIndexCacheEntry]
}

data NoIndexCacheEntry
= CacheGPD GenericPackageDescription !BSS.ByteString
| NoIndexCachePreference [Dependency]

data SomeRepo r where
SomeLocalRepo :: FilePath -> LocalRepo -> SomeRepo LocalRepo
SomeRemoteRepo :: FilePath -> RemoteRepo -> SomeRepo RemoteRepo
SomeSecureRepo :: FilePath -> RemoteRepo -> SomeRepo SecureRepo


--
-- | Check if this is a remote repo
isRepoRemote :: Repo -> Bool
isRepoRemote RepoLocalNoIndex{} = False
Expand Down

0 comments on commit 40366fc

Please sign in to comment.