@@ -175,25 +175,10 @@ type Source = () -- abstract binary source
175175addToStoreNar :: ValidPathInfo -> Source -> RepairFlag -> CheckSigsFlag -> MonadStore ()
176176addToStoreNar = undefined -- XXX
177177
178- -- class BaseHashAlgorithm (a :: HashAlgorithm) where
179- -- baseHashAlgorithm :: Bool
180-
181- -- instance BaseHashAlgorithm MD5 where
182- -- baseHashAlgorithm = MD5
183-
184- -- instance BaseHashAlgorithm SHA1 where
185- -- baseHashAlgorithm = SHA1
186-
187- -- instance BaseHashAlgorithm SHA256 where
188- -- baseHashAlgorithm = SHA256
189-
190- -- instance forall n a.BaseHashAlgorithm a => BaseHashAlgorithm (Truncated n a) where
191- -- baseHashAlgorithm = baseHashAlgorithm @a
192-
193178printHashType :: HashAlgorithm' Integer -> T. Text
194- printHashType MD5 = " MD5"
195- printHashType SHA1 = " SHA1"
196- printHashType SHA256 = " SHA256"
179+ printHashType MD5 = " MD5"
180+ printHashType SHA1 = " SHA1"
181+ printHashType SHA256 = " SHA256"
197182printHashType (Truncated _ a) = printHashType a
198183
199184type PathFilter = Path -> Bool
@@ -208,54 +193,26 @@ addToStore
208193 -> RepairFlag
209194 -> MonadStore Path
210195addToStore name pth recursive algoProxy pfilter repair = do
211- -- Get length first
212- -- len <- liftIO $ LBS.length . B.runPut . putNar <$> localPackNar narEffectsIO pth
213- -- Fetch full NAR bytestring separately. We are trying to
214- -- avoid forcing the full string in memory
196+
197+ -- TODO: Is this lazy enough? We need `B.putLazyByteString bs` to stream `bs`
215198 bs :: LBS. ByteString <- liftIO $ B. runPut . putNar <$> localPackNar narEffectsIO pth
216- liftIO $ print (LBS. length bs)
217- bs' <- liftIO $ putNar <$> localPackNar narEffectsIO pth
218- let bs'' = putByteStringLen " nix-archive-1"
219- let bs = sampleRegularBaseline
220- let len = LBS. length bs
199+
221200 runOpArgs AddToStore $ do
222201 putByteStringLen name
223- -- TODO: really send the string 0 or 1? Or is this Word8's 0 and 1?
224- putByteStringLen $ if algoVal @ a `elem` [SHA256 , Truncated 20 SHA256 ]
225- && recursive
226- then (LBS. pack [0 ])
227- else (LBS. pack [1 ])
228- -- then "0"
229- -- else "1"
230- -- TODO: really send the string 0 or 1? Or is this Word8's 0 and 1?
231- putByteStringLen $ if recursive
232- then (LBS. pack [1 ])
233- else (LBS. pack [0 ])
234- -- then "1"
235- -- else "0"
236-
237- -- putByteStringLen (T.encodeUtf8 . T.toLower . printHashType $ algoVal @a)
238-
239- -- putByteStringLen bs
240- -- putInt len
202+ if algoVal @ a `elem` [SHA256 , Truncated 20 SHA256 ] && recursive
203+ then putInt 0
204+ else putInt 1
205+ if recursive
206+ then putInt 1
207+ else putInt 0
208+
209+ putByteStringLen (T. encodeUtf8 . T. toLower . printHashType $ algoVal @ a )
210+
241211 B. putLazyByteString bs
242- -- bs''
243- -- when (len `mod` 8 /= 0) $
244- -- let pad x = forM_ (take x $ cycle [0]) B.putWord8
245- -- in pad $ fromIntegral $ 8 - (len `mod` 8)
246212
247213 fmap (fromMaybe $ error " TODO: Error" ) sockGetPath
248214
249215
250- -- "hi" file turned to a NAR with `nix-store --dump`, Base64 encoded
251- sampleRegularBaseline :: LBS. ByteString
252- sampleRegularBaseline = B64. decodeLenient $ LBS. concat
253- [" DQAAAAAAAABuaXgtYXJjaGl2ZS0xAAAAAQAAAAAAAAAoAAAAAAA"
254- ," AAAQAAAAAAAAAdHlwZQAAAAAHAAAAAAAAAHJlZ3VsYXIACAAAAA"
255- ," AAAABjb250ZW50cwMAAAAAAAAAaGkKAAAAAAABAAAAAAAAACkAA"
256- ," AAAAAAA"
257- ]
258-
259216addTextToStore :: LBS. ByteString -> LBS. ByteString -> PathSet -> RepairFlag -> MonadStore (Maybe Path )
260217addTextToStore name text references' repair = do
261218 runOpArgs AddTextToStore $ do
0 commit comments