@@ -59,6 +59,9 @@ import System.Nix.Store.Remote.Types
5959import System.Nix.Store.Remote.Protocol
6060import System.Nix.Store.Remote.Util
6161
62+ -- tmp
63+ import qualified Data.ByteString.Base64.Lazy as B64
64+
6265type RepairFlag = Bool
6366type CheckFlag = Bool
6467type CheckSigsFlag = Bool
@@ -194,7 +197,50 @@ printHashType SHA1 = "SHA1"
194197printHashType SHA256 = " SHA256"
195198printHashType (Truncated _ a) = printHashType a
196199
200+
201+ -- **********************************************************
202+ -- ** This is the c++ code we are porting for `addToStore` **
203+ -- **********************************************************
204+ --
205+ -- Path RemoteStore::addToStore(const string & name, const Path & _srcPath,
206+ -- bool recursive, HashType hashAlgo, PathFilter & filter, RepairFlag repair)
207+ -- {
208+ -- if (repair) throw Error("repairing is not supported when building through the Nix daemon");
209+
210+ -- auto conn(getConnection());
211+
212+ -- Path srcPath(absPath(_srcPath));
213+
214+ -- conn->to << wopAddToStore << name
215+ -- << ((hashAlgo == htSHA256 && recursive) ? 0 : 1) /* backwards compatibility hack */
216+ -- << (recursive ? 1 : 0)
217+ -- << printHashType(hashAlgo);
218+
219+ -- try {
220+ -- conn->to.written = 0;
221+ -- conn->to.warn = true;
222+ -- connections->incCapacity();
223+ -- {
224+ -- Finally cleanup([&]() { connections->decCapacity(); });
225+ -- dumpPath(srcPath, conn->to, filter);
226+ -- }
227+ -- conn->to.warn = false;
228+ -- conn.processStderr();
229+ -- } catch (SysError & e) {
230+ -- /* Daemon closed while we were sending the path. Probably OOM
231+ -- or I/O error. */
232+ -- if (e.errNo == EPIPE)
233+ -- try {
234+ -- conn.processStderr();
235+ -- } catch (EndOfFile & e) { }
236+ -- throw;
237+ -- }
238+
239+ -- return readStorePath(*this, conn->from);
240+ -- }
241+
197242type PathFilter = Path -> Bool
243+
198244addToStore
199245 :: forall a . (HasDigest a , AlgoVal a )
200246 => LBS. ByteString
@@ -206,26 +252,53 @@ addToStore
206252 -> MonadStore Path
207253addToStore name pth recursive algoProxy pfilter repair = do
208254 -- Get length first
209- len <- liftIO $ LBS. length . B. runPut . putNar <$> localPackNar narEffectsIO pth
255+ -- len <- liftIO $ LBS.length . B.runPut . putNar <$> localPackNar narEffectsIO pth
210256 -- Fetch full NAR bytestring separately. We are trying to
211257 -- avoid forcing the full string in memory
212258 bs :: LBS. ByteString <- liftIO $ B. runPut . putNar <$> localPackNar narEffectsIO pth
259+ liftIO $ print (LBS. length bs)
260+ bs' <- liftIO $ putNar <$> localPackNar narEffectsIO pth
261+ let bs'' = putByteStringLen " nix-archive-1"
262+ let bs = sampleRegularBaseline
263+ let len = LBS. length bs
213264 runOpArgs AddToStore $ do
214265 putByteStringLen name
215266 -- TODO: really send the string 0 or 1? Or is this Word8's 0 and 1?
216267 putByteStringLen $ if algoVal @ a `elem` [SHA256 , Truncated 20 SHA256 ]
217268 && recursive
218- then " 0"
219- else " 1"
269+ then (LBS. pack [0 ])
270+ else (LBS. pack [1 ])
271+ -- then "0"
272+ -- else "1"
220273 -- TODO: really send the string 0 or 1? Or is this Word8's 0 and 1?
221- putByteStringLen $ if recursive then " 0" else " 1"
222- putByteStringLen (T. encodeUtf8 . printHashType $ algoVal @ a )
274+ putByteStringLen $ if recursive
275+ then (LBS. pack [1 ])
276+ else (LBS. pack [0 ])
277+ -- then "1"
278+ -- else "0"
223279
224- putInt len
280+ -- putByteStringLen (T.encodeUtf8 . T.toLower . printHashType $ algoVal @a)
281+
282+ -- putByteStringLen bs
283+ -- putInt len
225284 B. putLazyByteString bs
285+ -- bs''
286+ -- when (len `mod` 8 /= 0) $
287+ -- let pad x = forM_ (take x $ cycle [0]) B.putWord8
288+ -- in pad $ fromIntegral $ 8 - (len `mod` 8)
289+
226290 fmap (fromMaybe $ error " TODO: Error" ) sockGetPath
227291
228292
293+ -- "hi" file turned to a NAR with `nix-store --dump`, Base64 encoded
294+ sampleRegularBaseline :: LBS. ByteString
295+ sampleRegularBaseline = B64. decodeLenient $ LBS. concat
296+ [" DQAAAAAAAABuaXgtYXJjaGl2ZS0xAAAAAQAAAAAAAAAoAAAAAAA"
297+ ," AAAQAAAAAAAAAdHlwZQAAAAAHAAAAAAAAAHJlZ3VsYXIACAAAAA"
298+ ," AAAABjb250ZW50cwMAAAAAAAAAaGkKAAAAAAABAAAAAAAAACkAA"
299+ ," AAAAAAA"
300+ ]
301+
229302addTextToStore :: LBS. ByteString -> LBS. ByteString -> PathSet -> RepairFlag -> MonadStore (Maybe Path )
230303addTextToStore name text references' repair = do
231304 runOpArgs AddTextToStore $ do
0 commit comments