remote: add Types.Query.Missing for QueryMissing result

This commit is contained in:
sorki 2023-12-02 14:45:05 +01:00
parent a05377a983
commit 8b1db174bc
7 changed files with 46 additions and 21 deletions

View File

@ -89,6 +89,8 @@ library
, System.Nix.Store.Remote.Types.Handshake
, System.Nix.Store.Remote.Types.Logger
, System.Nix.Store.Remote.Types.ProtoVersion
, System.Nix.Store.Remote.Types.Query
, System.Nix.Store.Remote.Types.Query.Missing
, System.Nix.Store.Remote.Types.StoreConfig
, System.Nix.Store.Remote.Types.StoreRequest
, System.Nix.Store.Remote.Types.StoreText

View File

@ -401,23 +401,18 @@ queryPathFromHashPart storePathHash = do
queryMissing
:: (HashSet StorePath)
-> MonadStore
( HashSet StorePath -- Paths that will be built
, HashSet StorePath -- Paths that have substitutes
, HashSet StorePath -- Unknown paths
, Integer -- Download size
, Integer -- Nar size?
)
-> MonadStore Missing
queryMissing ps = do
storeDir <- getStoreDir
runOpArgs WorkerOp_QueryMissing $ putPaths storeDir ps
willBuild <- sockGetPaths
willSubstitute <- sockGetPaths
unknown <- sockGetPaths
downloadSize' <- sockGetInt
narSize' <- sockGetInt
pure (willBuild, willSubstitute, unknown, downloadSize', narSize')
missingWillBuild <- sockGetPaths
missingWillSubstitute <- sockGetPaths
missingUnknownPaths <- sockGetPaths
missingDownloadSize <- sockGetInt
missingNarSize <- sockGetInt
pure Missing{..}
optimiseStore :: MonadStore ()
optimiseStore = Control.Monad.void $ simpleOp WorkerOp_OptimiseStore

View File

@ -4,6 +4,7 @@ module System.Nix.Store.Remote.Types
, module System.Nix.Store.Remote.Types.CheckMode
, module System.Nix.Store.Remote.Types.Logger
, module System.Nix.Store.Remote.Types.ProtoVersion
, module System.Nix.Store.Remote.Types.Query
, module System.Nix.Store.Remote.Types.StoreConfig
, module System.Nix.Store.Remote.Types.StoreRequest
, module System.Nix.Store.Remote.Types.StoreText
@ -19,6 +20,7 @@ import System.Nix.Store.Remote.Types.GC
import System.Nix.Store.Remote.Types.CheckMode
import System.Nix.Store.Remote.Types.Logger
import System.Nix.Store.Remote.Types.ProtoVersion
import System.Nix.Store.Remote.Types.Query
import System.Nix.Store.Remote.Types.StoreConfig
import System.Nix.Store.Remote.Types.StoreRequest
import System.Nix.Store.Remote.Types.StoreText

View File

@ -0,0 +1,5 @@
module System.Nix.Store.Remote.Types.Query
( module System.Nix.Store.Remote.Types.Query.Missing
) where
import System.Nix.Store.Remote.Types.Query.Missing

View File

@ -0,0 +1,18 @@
module System.Nix.Store.Remote.Types.Query.Missing
( Missing(..)
) where
import Data.HashSet (HashSet)
import Data.Word (Word64)
import GHC.Generics (Generic)
import System.Nix.StorePath (StorePath)
-- | Result of @QueryMissing@ @StoreRequest@
data Missing = Missing
{ missingWillBuild :: HashSet StorePath -- ^ Paths that will be built
, missingWillSubstitute :: HashSet StorePath -- ^ Paths that can be substituted from cache
, missingUnknownPaths :: HashSet StorePath -- ^ Path w/o any information
, missingDownloadSize :: Word64 -- ^ Total size of packed NARs to download
, missingNarSize :: Word64 -- ^ Total size of NARs after unpacking
}
deriving (Eq, Generic, Ord, Show)

View File

@ -24,6 +24,7 @@ import System.Nix.Store.Types (FileIngestionMethod, RepairMode)
import System.Nix.StorePath (StorePath, StorePathName, StorePathHashPart)
import System.Nix.StorePath.Metadata (Metadata)
import System.Nix.Store.Remote.Types.CheckMode (CheckMode)
import System.Nix.Store.Remote.Types.Query.Missing (Missing)
import System.Nix.Store.Remote.Types.StoreText (StoreText)
import System.Nix.Store.Remote.Types.SubstituteMode (SubstituteMode)
@ -138,13 +139,7 @@ data StoreRequest :: Type -> Type where
QueryMissing
:: Set DerivedPath
-> StoreRequest
( HashSet StorePath -- Paths that will be built
, HashSet StorePath -- Paths that have substitutes
, HashSet StorePath -- Unknown paths
, Integer -- Download size
, Integer -- Nar size?
)
-> StoreRequest Missing
OptimiseStore
:: StoreRequest ()

View File

@ -262,7 +262,15 @@ spec_protocol = Hspec.around withNixDaemon $
context "queryMissing" $
itRights "queries" $ withPath $ \path -> do
let pathSet = HS.fromList [path]
queryMissing pathSet `shouldReturn` (HS.empty, HS.empty, HS.empty, 0, 0)
queryMissing pathSet
`shouldReturn`
Missing
{ missingWillBuild = mempty
, missingWillSubstitute = mempty
, missingUnknownPaths = mempty
, missingDownloadSize = 0
, missingNarSize = 0
}
context "addToStore" $
itRights "adds file to store" $ do