Skip to content

Commit

Permalink
remote: align record field naming
Browse files Browse the repository at this point in the history
  • Loading branch information
sorki committed Dec 9, 2023
1 parent e9a0225 commit e5e4c6c
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 37 deletions.
62 changes: 31 additions & 31 deletions hnix-store-remote/src/System/Nix/Store/Remote/MonadStore.hs
Original file line number Diff line number Diff line change
Expand Up @@ -36,25 +36,25 @@ import System.Nix.Store.Remote.Types.StoreConfig (ProtoStoreConfig(..))
import qualified Data.DList

data RemoteStoreState = RemoteStoreState {
remoteStoreState_config :: ProtoStoreConfig
, remoteStoreState_logs :: DList Logger
, remoteStoreState_mDataSource :: Maybe (Word64 -> IO (Maybe ByteString))
remoteStoreStateConfig :: ProtoStoreConfig
, remoteStoreStateLogs :: DList Logger
, remoteStoreStateMDataSource :: Maybe (Word64 -> IO (Maybe ByteString))
-- ^ Source for @Logger_Read@, this will be called repeatedly
-- as the daemon requests chunks of size @Word64@.
-- If the function returns Nothing and daemon tries to read more
-- data an error is thrown.
-- Used by @AddToStoreNar@ and @ImportPaths@ operations.
, remoteStoreState_mDataSink :: Maybe (ByteString -> IO ())
, remoteStoreStateMDataSink :: Maybe (ByteString -> IO ())
-- ^ Sink for @Logger_Write@, called repeatedly by the daemon
-- to dump us some data. Used by @ExportPath@ operation.
, remoteStoreState_mNarSource :: Maybe (NarSource IO)
, remoteStoreStateMNarSource :: Maybe (NarSource IO)
}

instance HasStoreDir RemoteStoreState where
hasStoreDir = hasStoreDir . remoteStoreState_config
hasStoreDir = hasStoreDir . remoteStoreStateConfig

instance HasProtoVersion RemoteStoreState where
hasProtoVersion = hasProtoVersion . remoteStoreState_config
hasProtoVersion = hasProtoVersion . remoteStoreStateConfig

data RemoteStoreError
= RemoteStoreError_Fixme String
Expand All @@ -75,9 +75,9 @@ data RemoteStoreError
| RemoteStoreError_LoggerError (Either BasicError ErrorInfo)
| RemoteStoreError_LoggerLeftovers String ByteString -- when there are bytes left over after incremental logger parser is done, (Done x leftover), first param is show x
| RemoteStoreError_LoggerParserFail String ByteString -- when incremental parser returns ((Fail msg leftover) :: Result)
| RemoteStoreError_NoDataSourceProvided -- remoteStoreState_mDataSource is required but it is Nothing
| RemoteStoreError_DataSourceExhausted -- remoteStoreState_mDataSource returned Nothing but more data was requested
| RemoteStoreError_NoDataSinkProvided -- remoteStoreState_mDataSink is required but it is Nothing
| RemoteStoreError_NoDataSourceProvided -- remoteStoreStateMDataSource is required but it is Nothing
| RemoteStoreError_DataSourceExhausted -- remoteStoreStateMDataSource returned Nothing but more data was requested
| RemoteStoreError_NoDataSinkProvided -- remoteStoreStateMDataSink is required but it is Nothing
| RemoteStoreError_NoNarSourceProvided
| RemoteStoreError_OperationFailed
| RemoteStoreError_ProtocolMismatch
Expand Down Expand Up @@ -135,18 +135,18 @@ runRemoteStoreT
-> RemoteStoreT m a
-> m (Either RemoteStoreError a, DList Logger)
runRemoteStoreT sock =
fmap (\(res, RemoteStoreState{..}) -> (res, remoteStoreState_logs))
fmap (\(res, RemoteStoreState{..}) -> (res, remoteStoreStateLogs))
. (`runReaderT` sock)
. (`runStateT` emptyState)
. runExceptT
. _unRemoteStoreT
where
emptyState = RemoteStoreState
{ remoteStoreState_config = def
, remoteStoreState_logs = mempty
, remoteStoreState_mDataSource = Nothing
, remoteStoreState_mDataSink = Nothing
, remoteStoreState_mNarSource = Nothing
{ remoteStoreStateConfig = def
, remoteStoreStateLogs = mempty
, remoteStoreStateMDataSource = Nothing
, remoteStoreStateMDataSink = Nothing
, remoteStoreStateMNarSource = Nothing
}

class ( MonadIO m
Expand Down Expand Up @@ -302,37 +302,37 @@ instance MonadRemoteStore m => MonadRemoteStore (ExceptT RemoteStoreError m)

instance MonadIO m => MonadRemoteStore (RemoteStoreT m) where

getConfig = RemoteStoreT $ gets remoteStoreState_config
getConfig = RemoteStoreT $ gets remoteStoreStateConfig
getProtoVersion = RemoteStoreT $ gets hasProtoVersion
setProtoVersion pv =
RemoteStoreT $ modify $ \s ->
s { remoteStoreState_config =
(remoteStoreState_config s) { protoStoreConfig_protoVersion = pv }
s { remoteStoreStateConfig =
(remoteStoreStateConfig s) { protoStoreConfigProtoVersion = pv }
}
getStoreDir = RemoteStoreT $ gets hasStoreDir
setStoreDir sd =
RemoteStoreT $ modify $ \s ->
s { remoteStoreState_config =
(remoteStoreState_config s) { protoStoreConfig_dir = sd }
s { remoteStoreStateConfig =
(remoteStoreStateConfig s) { protoStoreConfigDir = sd }
}

getStoreSocket = RemoteStoreT ask

appendLog x =
RemoteStoreT
$ modify
$ \s -> s { remoteStoreState_logs = remoteStoreState_logs s `Data.DList.snoc` x }
$ \s -> s { remoteStoreStateLogs = remoteStoreStateLogs s `Data.DList.snoc` x }

setDataSource x = RemoteStoreT $ modify $ \s -> s { remoteStoreState_mDataSource = pure x }
getDataSource = RemoteStoreT (gets remoteStoreState_mDataSource)
clearDataSource = RemoteStoreT $ modify $ \s -> s { remoteStoreState_mDataSource = Nothing }
setDataSource x = RemoteStoreT $ modify $ \s -> s { remoteStoreStateMDataSource = pure x }
getDataSource = RemoteStoreT (gets remoteStoreStateMDataSource)
clearDataSource = RemoteStoreT $ modify $ \s -> s { remoteStoreStateMDataSource = Nothing }

setDataSink x = RemoteStoreT $ modify $ \s -> s { remoteStoreState_mDataSink = pure x }
getDataSink = RemoteStoreT (gets remoteStoreState_mDataSink)
clearDataSink = RemoteStoreT $ modify $ \s -> s { remoteStoreState_mDataSink = Nothing }
setDataSink x = RemoteStoreT $ modify $ \s -> s { remoteStoreStateMDataSink = pure x }
getDataSink = RemoteStoreT (gets remoteStoreStateMDataSink)
clearDataSink = RemoteStoreT $ modify $ \s -> s { remoteStoreStateMDataSink = Nothing }

setNarSource x = RemoteStoreT $ modify $ \s -> s { remoteStoreState_mNarSource = pure x }
setNarSource x = RemoteStoreT $ modify $ \s -> s { remoteStoreStateMNarSource = pure x }
takeNarSource = RemoteStoreT $ do
x <- remoteStoreState_mNarSource <$> get
modify $ \s -> s { remoteStoreState_mNarSource = Nothing }
x <- remoteStoreStateMNarSource <$> get
modify $ \s -> s { remoteStoreStateMNarSource = Nothing }
pure x
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ instance HasStoreSocket Socket where
hasStoreSocket = id

data ProtoStoreConfig = ProtoStoreConfig
{ protoStoreConfig_dir :: StoreDir
, protoStoreConfig_protoVersion :: ProtoVersion
{ protoStoreConfigDir :: StoreDir
, protoStoreConfigProtoVersion :: ProtoVersion
} deriving (Eq, Generic, Ord, Show)

instance Default ProtoStoreConfig where
Expand All @@ -29,12 +29,12 @@ instance HasStoreDir StoreDir where
hasStoreDir = id

instance HasStoreDir ProtoStoreConfig where
hasStoreDir = protoStoreConfig_dir
hasStoreDir = protoStoreConfigDir

instance HasProtoVersion ProtoStoreConfig where
hasProtoVersion = protoStoreConfig_protoVersion
hasProtoVersion = protoStoreConfigProtoVersion

data StoreConfig = StoreConfig
{ storeConfig_dir :: Maybe StoreDir
, storeConfig_socketPath :: FilePath
{ storeConfigDir :: Maybe StoreDir
, storeConfigSocketPath :: FilePath
} deriving (Eq, Generic, Ord, Show)

0 comments on commit e5e4c6c

Please sign in to comment.