Skip to content

Commit ec79cfe

Browse files
committed
remote: NixSerializer, move maybePath from where clause, expose
1 parent 936fdf8 commit ec79cfe

File tree

1 file changed

+22
-21
lines changed

1 file changed

+22
-21
lines changed

hnix-store-remote/src/System/Nix/Store/Remote/Serializer.hs

Lines changed: 22 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ module System.Nix.Store.Remote.Serializer
3333
, protoVersion
3434
-- * StorePath
3535
, storePath
36+
, maybePath
3637
, storePathHashPart
3738
, storePathName
3839
-- * Metadata
@@ -409,6 +410,27 @@ storePath = Serializer
409410
$ System.Nix.StorePath.storePathToRawFilePath sd p
410411
}
411412

413+
maybePath
414+
:: HasStoreDir r
415+
=> NixSerializer r SError (Maybe StorePath)
416+
maybePath = Serializer
417+
{ getS = do
418+
getS maybeText >>= \case
419+
Nothing -> pure Nothing
420+
Just t -> do
421+
sd <- Control.Monad.Reader.asks hasStoreDir
422+
either
423+
(throwError . SError_Path)
424+
(pure . pure)
425+
$ System.Nix.StorePath.parsePathFromText sd t
426+
427+
, putS = \case
428+
Nothing -> putS maybeText Nothing
429+
Just p -> do
430+
sd <- Control.Monad.Reader.asks hasStoreDir
431+
putS text $ System.Nix.StorePath.storePathToText sd p
432+
}
433+
412434
storePathHashPart :: NixSerializer r SError StorePathHashPart
413435
storePathHashPart =
414436
mapIsoSerializer
@@ -485,27 +507,6 @@ pathMetadata = Serializer
485507
(fmap System.Nix.ContentAddress.buildContentAddress)
486508
maybeText
487509

488-
maybePath
489-
:: HasStoreDir r
490-
=> NixSerializer r SError (Maybe StorePath)
491-
maybePath = Serializer
492-
{ getS = do
493-
getS maybeText >>= \case
494-
Nothing -> pure Nothing
495-
Just t -> do
496-
sd <- Control.Monad.Reader.asks hasStoreDir
497-
either
498-
(throwError . SError_Path)
499-
(pure . pure)
500-
$ System.Nix.StorePath.parsePathFromText sd t
501-
502-
, putS = \case
503-
Nothing -> putS maybeText Nothing
504-
Just p -> do
505-
sd <- Control.Monad.Reader.asks hasStoreDir
506-
putS text $ System.Nix.StorePath.storePathToText sd p
507-
}
508-
509510
storePathTrust
510511
:: NixSerializer r SError StorePathTrust
511512
storePathTrust =

0 commit comments

Comments
 (0)