Skip to content

Commit d3408a6

Browse files
committed
remote: add SuccessCodeReply
Add SuccessCodeReply to replace instances of the () reply type. The serialization behavior is more clear with the more explicit type.
1 parent 21040fb commit d3408a6

File tree

7 files changed

+31
-18
lines changed

7 files changed

+31
-18
lines changed

hnix-store-remote/hnix-store-remote.cabal

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ library
9393
, System.Nix.Store.Remote.Types.StoreReply
9494
, System.Nix.Store.Remote.Types.StoreText
9595
, System.Nix.Store.Remote.Types.SubstituteMode
96+
, System.Nix.Store.Remote.Types.SuccessCodeReply
9697
, System.Nix.Store.Remote.Types.TrustedFlag
9798
, System.Nix.Store.Remote.Types.Verbosity
9899
, System.Nix.Store.Remote.Types.WorkerMagic

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

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ module System.Nix.Store.Remote.Client
2626
, module System.Nix.Store.Remote.Client.Core
2727
) where
2828

29-
import Control.Monad (when)
29+
import Control.Monad (void, when)
3030
import Control.Monad.Except (throwError)
3131
import Data.HashSet (HashSet)
3232
import Data.Map (Map)
@@ -96,7 +96,7 @@ addSignatures
9696
=> StorePath
9797
-> Set Signature
9898
-> m ()
99-
addSignatures p signatures = doReq (AddSignatures p signatures)
99+
addSignatures p signatures = (void . doReq) (AddSignatures p signatures)
100100

101101
-- | Add temporary garbage collector root.
102102
--
@@ -105,14 +105,14 @@ addTempRoot
105105
:: MonadRemoteStore m
106106
=> StorePath
107107
-> m ()
108-
addTempRoot = doReq . AddTempRoot
108+
addTempRoot = void . doReq . AddTempRoot
109109

110110
-- | Add indirect garbage collector root.
111111
addIndirectRoot
112112
:: MonadRemoteStore m
113113
=> StorePath
114114
-> m ()
115-
addIndirectRoot = doReq . AddIndirectRoot
115+
addIndirectRoot = void . doReq . AddIndirectRoot
116116

117117
-- | Build a derivation available at @StorePath@
118118
buildDerivation
@@ -139,7 +139,7 @@ buildPaths
139139
=> Set DerivedPath
140140
-> BuildMode
141141
-> m ()
142-
buildPaths a b = doReq (BuildPaths a b)
142+
buildPaths a b = (void . doReq) (BuildPaths a b)
143143

144144
collectGarbage
145145
:: MonadRemoteStore m
@@ -151,7 +151,7 @@ ensurePath
151151
:: MonadRemoteStore m
152152
=> StorePath
153153
-> m ()
154-
ensurePath = doReq . EnsurePath
154+
ensurePath = void . doReq . EnsurePath
155155

156156
-- | Find garbage collector roots.
157157
findRoots
@@ -235,12 +235,12 @@ queryMissing = doReq . QueryMissing
235235
optimiseStore
236236
:: MonadRemoteStore m
237237
=> m ()
238-
optimiseStore = doReq OptimiseStore
238+
optimiseStore = (void . doReq) OptimiseStore
239239

240240
syncWithGC
241241
:: MonadRemoteStore m
242242
=> m ()
243-
syncWithGC = doReq SyncWithGC
243+
syncWithGC = (void . doReq) SyncWithGC
244244

245245
verifyStore
246246
:: MonadRemoteStore m

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1368,14 +1368,14 @@ mapPutER = mapErrorST ReplySError_PrimPut
13681368
-- | Parse a bool returned at the end of simple operations.
13691369
-- This is always 1 (@True@) so we assert that it really is so.
13701370
-- Errors for these operations are indicated via @Logger_Error@.
1371-
opSuccess :: NixSerializer r ReplySError ()
1371+
opSuccess :: NixSerializer r ReplySError SuccessCodeReply
13721372
opSuccess = Serializer
13731373
{ getS = do
13741374
retCode <- mapGetER $ getS bool
13751375
Control.Monad.unless
13761376
(retCode == True)
13771377
$ throwError ReplySError_UnexpectedFalseOpSuccess
1378-
pure ()
1378+
pure SuccessCodeReply
13791379
, putS = \_ -> mapPutER $ putS bool True
13801380
}
13811381

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ module System.Nix.Store.Remote.Types
99
, module System.Nix.Store.Remote.Types.StoreRequest
1010
, module System.Nix.Store.Remote.Types.StoreText
1111
, module System.Nix.Store.Remote.Types.SubstituteMode
12+
, module System.Nix.Store.Remote.Types.SuccessCodeReply
1213
, module System.Nix.Store.Remote.Types.TrustedFlag
1314
, module System.Nix.Store.Remote.Types.Verbosity
1415
, module System.Nix.Store.Remote.Types.WorkerMagic
@@ -25,6 +26,7 @@ import System.Nix.Store.Remote.Types.StoreConfig
2526
import System.Nix.Store.Remote.Types.StoreRequest
2627
import System.Nix.Store.Remote.Types.StoreText
2728
import System.Nix.Store.Remote.Types.SubstituteMode
29+
import System.Nix.Store.Remote.Types.SuccessCodeReply
2830
import System.Nix.Store.Remote.Types.TrustedFlag
2931
import System.Nix.Store.Remote.Types.Verbosity
3032
import System.Nix.Store.Remote.Types.WorkerMagic

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import System.Nix.Build (BuildResult)
88
import System.Nix.StorePath (StorePath, StorePathName)
99
import System.Nix.StorePath.Metadata (Metadata)
1010
import System.Nix.Store.Remote.Serializer
11+
import System.Nix.Store.Remote.Types.SuccessCodeReply (SuccessCodeReply)
1112
import System.Nix.Store.Remote.Types.GC (GCResult, GCRoot)
1213
import System.Nix.Store.Remote.Types.Query.Missing (Missing)
1314
import System.Nix.Store.Remote.Types.StoreConfig (ProtoStoreConfig)
@@ -20,7 +21,7 @@ import System.Nix.Store.Remote.Types.StoreConfig (ProtoStoreConfig)
2021
class StoreReply a where
2122
getReplyS :: NixSerializer ProtoStoreConfig ReplySError a
2223

23-
instance StoreReply () where
24+
instance StoreReply SuccessCodeReply where
2425
getReplyS = opSuccess
2526

2627
instance StoreReply Bool where

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

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import System.Nix.Store.Remote.Types.CheckMode (CheckMode)
2828
import System.Nix.Store.Remote.Types.Query.Missing (Missing)
2929
import System.Nix.Store.Remote.Types.StoreText (StoreText)
3030
import System.Nix.Store.Remote.Types.SubstituteMode (SubstituteMode)
31+
import System.Nix.Store.Remote.Types.SuccessCodeReply (SuccessCodeReply)
3132

3233
data StoreRequest :: Type -> Type where
3334
-- | Add @NarSource@ to the store.
@@ -51,26 +52,26 @@ data StoreRequest :: Type -> Type where
5152
AddSignatures
5253
:: StorePath
5354
-> Set Signature
54-
-> StoreRequest ()
55+
-> StoreRequest SuccessCodeReply
5556

5657
AddIndirectRoot
5758
:: StorePath
58-
-> StoreRequest ()
59+
-> StoreRequest SuccessCodeReply
5960

6061
-- | Add temporary garbage collector root.
6162
--
6263
-- This root is removed as soon as the client exits.
6364
AddTempRoot
6465
:: StorePath
65-
-> StoreRequest ()
66+
-> StoreRequest SuccessCodeReply
6667

6768
-- | Build paths if they are an actual derivations.
6869
--
6970
-- If derivation output paths are already valid, do nothing.
7071
BuildPaths
7172
:: Set DerivedPath
7273
-> BuildMode
73-
-> StoreRequest ()
74+
-> StoreRequest SuccessCodeReply
7475

7576
BuildDerivation
7677
:: StorePath
@@ -84,7 +85,7 @@ data StoreRequest :: Type -> Type where
8485

8586
EnsurePath
8687
:: StorePath
87-
-> StoreRequest ()
88+
-> StoreRequest SuccessCodeReply
8889

8990
-- | Find garbage collector roots.
9091
FindRoots
@@ -138,10 +139,10 @@ data StoreRequest :: Type -> Type where
138139
-> StoreRequest Missing
139140

140141
OptimiseStore
141-
:: StoreRequest ()
142+
:: StoreRequest SuccessCodeReply
142143

143144
SyncWithGC
144-
:: StoreRequest ()
145+
:: StoreRequest SuccessCodeReply
145146

146147
-- returns True on errors
147148
VerifyStore
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
module System.Nix.Store.Remote.Types.SuccessCodeReply
2+
( SuccessCodeReply(..)
3+
) where
4+
5+
-- | Reply that checks an int success return value
6+
data SuccessCodeReply = SuccessCodeReply
7+
deriving (Show)
8+

0 commit comments

Comments
 (0)