Skip to content

Commit 6f21bb3

Browse files
committed
remote: add Recursive newtype for addToStore
1 parent 3b3752d commit 6f21bb3

File tree

3 files changed

+19
-5
lines changed

3 files changed

+19
-5
lines changed

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ addToStore
7878
. (NamedAlgo a)
7979
=> StorePathName -- ^ Name part of the newly created `StorePath`
8080
-> NarSource MonadStore -- ^ provide nar stream
81-
-> Bool -- ^ Add target directory recursively
81+
-> Recursive -- ^ Add target directory recursively
8282
-> RepairFlag -- ^ Only used by local store backend
8383
-> MonadStore StorePath
8484
addToStore name source recursive repair = do
@@ -88,8 +88,8 @@ addToStore name source recursive repair = do
8888
runOpArgsIO AddToStore $ \yield -> do
8989
yield $ toStrict $ Data.Binary.Put.runPut $ do
9090
putText $ System.Nix.StorePath.unStorePathName name
91-
putBool $ not $ System.Nix.Hash.algoName @a == "sha256" && recursive
92-
putBool recursive
91+
putBool $ not $ System.Nix.Hash.algoName @a == "sha256" && (unRecursive recursive)
92+
putBool (unRecursive recursive)
9393
putText $ System.Nix.Hash.algoName @a
9494
source yield
9595
sockGetPath

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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@ module System.Nix.Store.Remote.Types
1616
, doSubstitute
1717
, dontSubstitute
1818
, unSubstituteFlag
19+
, Recursive
20+
, addRecursive
21+
, addNonRecursive
22+
, unRecursive
1923
, Logger(..)
2024
, Field(..)
2125
, mapStoreDir
@@ -66,6 +70,16 @@ doSubstitute, dontSubstitute :: SubstituteFlag
6670
doSubstitute = SubstituteFlag True
6771
dontSubstitute = SubstituteFlag False
6872

73+
-- | Recursive, used by @addToStore@
74+
newtype Recursive = Recursive { unRecursive :: Bool }
75+
deriving (Eq, Ord, Show)
76+
77+
addRecursive, addNonRecursive :: Recursive
78+
-- | Add target directory recursively
79+
addRecursive = Recursive True
80+
-- | Add target directory non-recursively
81+
addNonRecursive = Recursive False
82+
6983
type MonadStore a
7084
= ExceptT
7185
String

hnix-store-remote/tests/NixDaemon.hs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ withPath action = do
161161
dummy :: MonadStore StorePath
162162
dummy = do
163163
let name = Data.Either.fromRight (error "impossible") $ makeStorePathName "dummy"
164-
addToStore @SHA256 name (dumpPath "dummy") False dontRepair
164+
addToStore @SHA256 name (dumpPath "dummy") addNonRecursive dontRepair
165165

166166
invalidPath :: StorePath
167167
invalidPath =
@@ -252,7 +252,7 @@ spec_protocol = Hspec.around withNixDaemon $
252252
itRights "adds file to store" $ do
253253
fp <- liftIO $ writeSystemTempFile "addition" "lal"
254254
let name = Data.Either.fromRight (error "impossible") $ makeStorePathName "tmp-addition"
255-
res <- addToStore @SHA256 name (dumpPath fp) False dontRepair
255+
res <- addToStore @SHA256 name (dumpPath fp) addNonRecursive dontRepair
256256
liftIO $ print res
257257

258258
context "with dummy" $ do

0 commit comments

Comments
 (0)