@@ -43,6 +43,7 @@ import qualified Data.Binary.Put as B
4343import Data.ByteString (ByteString )
4444import qualified Data.ByteString.Lazy as BSL
4545import qualified Data.Map.Strict as M
46+ import qualified Data.Set
4647import Data.Proxy (Proxy )
4748import Data.Text (Text )
4849
@@ -52,14 +53,14 @@ import System.Nix.Hash (Digest, ValidAlgo)
5253import System.Nix.StorePath
5354import System.Nix.Hash
5455import System.Nix.Nar (localPackNar , putNar , narEffectsIO , Nar )
55- import System.Nix.ValidPath
56+ import System.Nix.StorePathMetadata
5657
5758import System.Nix.Store.Remote.Binary
5859import System.Nix.Store.Remote.Types
5960import System.Nix.Store.Remote.Protocol
6061import System.Nix.Store.Remote.Util
6162
62- import Data.Text.Encoding (encodeUtf8 )
63+ import qualified Data.Text.Encoding -- (encodeUtf8)
6364
6465type RepairFlag = Bool
6566type CheckFlag = Bool
@@ -71,11 +72,10 @@ addToStore
7172 => StorePathName
7273 -> FilePath
7374 -> Bool
74- -> Proxy a
7575 -> (StorePath -> Bool )
7676 -> RepairFlag
7777 -> MonadStore StorePath
78- addToStore name pth recursive _algoProxy pfilter repair = do
78+ addToStore name pth recursive _pathFilter _repair = do
7979
8080 -- TODO: Is this lazy enough? We need `B.putLazyByteString bs` to stream `bs`
8181 bs :: BSL. ByteString <- liftIO $ B. runPut . putNar <$> localPackNar narEffectsIO pth
@@ -92,23 +92,32 @@ addToStore name pth recursive _algoProxy pfilter repair = do
9292
9393 sockGetPath
9494
95- addToStoreNar :: ValidPath -> Nar -> RepairFlag -> CheckSigsFlag -> MonadStore ()
96- addToStoreNar ValidPath {.. } nar repair checkSigs = do
95+ addToStoreNar :: StorePathMetadata -> Nar -> RepairFlag -> CheckSigsFlag -> MonadStore ()
96+ addToStoreNar StorePathMetadata {.. } nar repair checkSigs = do
9797 -- after the command, protocol asks for data via Read message
9898 -- so we provide it here
9999 let n = B. runPut $ putNar nar
100100 setData n
101101
102102 void $ runOpArgs AddToStoreNar $ do
103103 putPath path
104- maybe (putText " " ) (putPath) deriver
105- putText narHash
104+ maybe (putText " " ) (putPath) deriverPath
105+ let putNarHash :: SomeNamedDigest -> B. PutM ()
106+ putNarHash (SomeDigest n) = putByteStringLen
107+ $ BSL. fromStrict
108+ $ Data.Text.Encoding. encodeUtf8
109+ $ encodeBase32 n
110+
111+ putNarHash narHash
106112 putPaths references
107113 putTime registrationTime
108- putInt narSize
109- putBool ultimate
110- putTexts sigs
111- putText ca
114+ -- XXX
115+ maybe (error " NO NAR BYTES" ) putInt narBytes
116+ putBool (trust == BuiltLocally )
117+ -- XXX
118+ putTexts [" " ]
119+ -- XXX
120+ putText " "
112121
113122 putBool repair
114123 putBool (not checkSigs)
@@ -190,23 +199,38 @@ querySubstitutablePaths ps = do
190199 putPaths ps
191200 sockGetPaths
192201
193- queryPathInfoUncached :: StorePath -> MonadStore ValidPath
202+ queryPathInfoUncached :: forall a . NamedAlgo a => StorePath -> MonadStore StorePathMetadata
194203queryPathInfoUncached path = do
195204 runOpArgs QueryPathInfo $ do
196205 putPath path
197206
198207 valid <- sockGetBool
199208 unless valid $ error " Path is not valid"
200209
201- deriver <- sockGetPathMay
202- narHash <- bsToText <$> sockGetStr
210+ deriverPath <- sockGetPathMay
211+
212+ narHashText <- Data.Text.Encoding. decodeUtf8 <$> sockGetStr
213+ let narHash = case decodeBase32 narHashText of
214+ Left e -> error e
215+ Right x -> SomeDigest @ a x
216+
203217 references <- sockGetPaths
204218 registrationTime <- sockGet getTime
205- narSize <- sockGetInt
219+ narBytes <- Just <$> sockGetInt
206220 ultimate <- sockGetBool
207- sigs <- map bsToText <$> sockGetStrings
221+
222+ -- XXX
223+ sigStrings <- map bsToText <$> sockGetStrings
224+
225+ let sigs = Data.Set. empty
226+ contentAddressableAddress = Nothing
227+
208228 ca <- bsToText <$> sockGetStr
209- return $ ValidPath {.. }
229+
230+ let trust = if ultimate then BuiltLocally
231+ else BuiltElsewhere
232+
233+ return $ StorePathMetadata {.. }
210234
211235queryReferrers :: StorePath -> MonadStore StorePathSet
212236queryReferrers p = do
@@ -235,7 +259,7 @@ queryDerivationOutputNames p = do
235259queryPathFromHashPart :: Digest StorePathHashAlgo -> MonadStore StorePath
236260queryPathFromHashPart storePathHash = do
237261 runOpArgs QueryPathFromHashPart $
238- putByteStringLen $ BSL. fromStrict $ encodeUtf8 $ encodeBase32 storePathHash
262+ putByteStringLen $ BSL. fromStrict $ Data.Text.Encoding. encodeUtf8 $ encodeBase32 storePathHash
239263 sockGetPath
240264
241265queryMissing :: StorePathSet -> MonadStore (StorePathSet , StorePathSet , StorePathSet , Integer , Integer )
@@ -253,7 +277,7 @@ queryMissing ps = do
253277optimiseStore :: MonadStore ()
254278optimiseStore = void $ simpleOp OptimiseStore
255279
256- syncWithGC :: MonadStore ()
280+ syncWithGC :: MonadStore ()
257281syncWithGC = void $ simpleOp SyncWithGC
258282
259283-- returns True on errors
0 commit comments