{-# LANGUAGE ScopedTypeVariables #-}
module SketeUpdate where

import qualified Control.Monad.Catch as E
import Data.Conduit (($=), ($$))
import qualified Data.Conduit.List as CL
import Control.Monad.Reader
import Control.Monad.Log
import qualified Codec.Archive.Tar as Tar

import qualified Distribution.Skete.Storage.Interface as Storage
import Distribution.Skete.Haskell.Package

fullUpdate :: forall t m env c d r
           . ( MonadTrans t, MonadIO (t m), E.MonadCatch (t m)
             , MonadLog env (t m), HasUpdateConfig c, MonadReader c (t m)
             , Storage.SketeStorage d m r)
           => t m ()
fullUpdate =
    getIndexRemaining go
  where
    go :: Tar.Entries Tar.FormatError -> t m ()
    go idxEnts = streamIndex idxEnts $= elideSeen $$ CL.mapM_ applyPackageEvent
