Skip to content

Commit 152ce6f

Browse files
committed
add RepairMode to System.Nix.Store.Types
1 parent 8ac46de commit 152ce6f

File tree

7 files changed

+29
-30
lines changed

7 files changed

+29
-30
lines changed

hnix-store-core/src/System/Nix/ReadonlyStore.hs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import Crypto.Hash (Context, Digest, SHA256)
1313
import Data.ByteString (ByteString)
1414
import Data.HashSet (HashSet)
1515
import System.Nix.Hash (BaseEncoding(Base16), NamedAlgo(algoName))
16-
import System.Nix.Store.Types (FileIngestionMethod(..))
16+
import System.Nix.Store.Types (FileIngestionMethod(..), RepairMode)
1717
import System.Nix.StorePath (StoreDir, StorePath(StorePath), StorePathName)
1818

1919
import qualified Crypto.Hash
@@ -100,7 +100,7 @@ computeStorePathForPath
100100
-> FilePath -- ^ Local `FilePath` to add
101101
-> FileIngestionMethod -- ^ Add target directory recursively
102102
-> (FilePath -> Bool) -- ^ Path filter function
103-
-> Bool -- ^ Only used by local store backend
103+
-> RepairMode -- ^ Only used by local store backend
104104
-> IO StorePath
105105
computeStorePathForPath storeDir name pth recursive _pathFilter _repair = do
106106
selectedHash <-

hnix-store-core/src/System/Nix/Store/Types.hs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
module System.Nix.Store.Types
22
( FileIngestionMethod(..)
3+
, RepairMode(..)
34
) where
45

56
import GHC.Generics (Generic)
@@ -9,3 +10,9 @@ data FileIngestionMethod
910
= FileIngestionMethod_Flat
1011
| FileIngestionMethod_FileRecursive
1112
deriving (Bounded, Eq, Generic, Enum, Ord, Show)
13+
14+
-- | Repair mode
15+
data RepairMode
16+
= RepairMode_DoRepair
17+
| RepairMode_DontRepair
18+
deriving (Bounded, Eq, Generic, Enum, Ord, Show)

hnix-store-remote/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,6 @@ main = do
2525
roots <- findRoots
2626
liftIO $ print roots
2727

28-
res <- addTextToStore "hnix-store" "test" mempty dontRepair
28+
res <- addTextToStore "hnix-store" "test" mempty RepairMode_DontRepair
2929
liftIO $ print res
3030
```

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

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ module System.Nix.Store.Remote
2727
, runStore
2828
, syncWithGC
2929
, verifyStore
30+
, module System.Nix.Store.Types
3031
, module System.Nix.Store.Remote.Types
3132
) where
3233

@@ -43,7 +44,7 @@ import qualified System.Nix.Hash
4344
import qualified Data.ByteString.Lazy as BSL
4445

4546
import System.Nix.Derivation (Derivation)
46-
import System.Nix.Store.Types (FileIngestionMethod(..))
47+
import System.Nix.Store.Types (FileIngestionMethod(..), RepairMode(..))
4748
import System.Nix.Build ( BuildMode
4849
, BuildResult
4950
)
@@ -82,10 +83,10 @@ addToStore
8283
=> StorePathName -- ^ Name part of the newly created `StorePath`
8384
-> NarSource MonadStore -- ^ provide nar stream
8485
-> FileIngestionMethod -- ^ Add target directory recursively
85-
-> RepairFlag -- ^ Only used by local store backend
86+
-> RepairMode -- ^ Only used by local store backend
8687
-> MonadStore StorePath
8788
addToStore name source recursive repair = do
88-
Control.Monad.when (unRepairFlag repair)
89+
Control.Monad.when (repair == RepairMode_DoRepair)
8990
$ error "repairing is not supported when building through the Nix daemon"
9091

9192
runOpArgsIO AddToStore $ \yield -> do
@@ -108,10 +109,11 @@ addTextToStore
108109
:: Text -- ^ Name of the text
109110
-> Text -- ^ Actual text to add
110111
-> HashSet StorePath -- ^ Set of `StorePath`s that the added text references
111-
-> RepairFlag -- ^ Repair flag, must be `False` in case of remote backend
112+
-> RepairMode -- ^ Repair mode, must be `RepairMode_DontRepair` for remote backend
113+
-- (only valid for local store)
112114
-> MonadStore StorePath
113115
addTextToStore name text references' repair = do
114-
Control.Monad.when (unRepairFlag repair)
116+
Control.Monad.when (repair == RepairMode_DoRepair)
115117
$ error "repairing is not supported when building through the Nix daemon"
116118

117119
storeDir <- getStoreDir
@@ -329,7 +331,7 @@ syncWithGC :: MonadStore ()
329331
syncWithGC = Control.Monad.void $ simpleOp SyncWithGC
330332

331333
-- returns True on errors
332-
verifyStore :: CheckFlag -> RepairFlag -> MonadStore Bool
334+
verifyStore :: CheckFlag -> RepairMode -> MonadStore Bool
333335
verifyStore check repair = simpleOpArgs VerifyStore $ do
334336
putBool $ unCheckFlag check
335-
putBool $ unRepairFlag repair
337+
putBool $ repair == RepairMode_DoRepair

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

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,6 @@ module System.Nix.Store.Remote.Types
55
, doCheck
66
, dontCheck
77
, unCheckFlag
8-
, RepairFlag
9-
, doRepair
10-
, dontRepair
11-
, unRepairFlag
128
, SubstituteFlag
139
, doSubstitute
1410
, dontSubstitute
@@ -53,15 +49,6 @@ doCheck, dontCheck :: CheckFlag
5349
doCheck = CheckFlag True
5450
dontCheck = CheckFlag False
5551

56-
-- | Repair flag, used by @addToStore@, @addTextToStore@
57-
-- and @verifyStore@
58-
newtype RepairFlag = RepairFlag { unRepairFlag :: Bool }
59-
deriving (Eq, Ord, Show)
60-
61-
doRepair, dontRepair :: RepairFlag
62-
doRepair = RepairFlag True
63-
dontRepair = RepairFlag False
64-
6552
-- | Substitute flag, used by @queryValidPaths@
6653
newtype SubstituteFlag = SubstituteFlag { unSubstituteFlag :: Bool }
6754
deriving (Eq, Ord, Show)

hnix-store-remote/tests-io/NixDaemon.hs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -162,14 +162,14 @@ itLefts name action = it name action isLeft
162162

163163
withPath :: (StorePath -> MonadStore a) -> MonadStore a
164164
withPath action = do
165-
path <- addTextToStore "hnix-store" "test" mempty dontRepair
165+
path <- addTextToStore "hnix-store" "test" mempty RepairMode_DontRepair
166166
action path
167167

168168
-- | dummy path, adds <tmp>/dummpy with "Hello World" contents
169169
dummy :: MonadStore StorePath
170170
dummy = do
171171
let name = Data.Either.fromRight (error "impossible") $ makeStorePathName "dummy"
172-
addToStore @SHA256 name (dumpPath "dummy") addNonRecursive dontRepair
172+
addToStore @SHA256 name (dumpPath "dummy") FileIngestionMethod_Flat RepairMode_DontRepair
173173

174174
invalidPath :: StorePath
175175
invalidPath =
@@ -178,7 +178,7 @@ invalidPath =
178178

179179
withBuilder :: (StorePath -> MonadStore a) -> MonadStore a
180180
withBuilder action = do
181-
path <- addTextToStore "builder" builderSh mempty dontRepair
181+
path <- addTextToStore "builder" builderSh mempty RepairMode_DontRepair
182182
action path
183183

184184
builderSh :: Text
@@ -194,14 +194,14 @@ spec_protocol = Hspec.around withNixDaemon $
194194

195195
context "verifyStore" $ do
196196
itRights "check=False repair=False" $
197-
verifyStore dontCheck dontRepair `shouldReturn` False
197+
verifyStore dontCheck RepairMode_DontRepair `shouldReturn` False
198198

199199
itRights "check=True repair=False" $
200-
verifyStore doCheck dontRepair `shouldReturn` False
200+
verifyStore doCheck RepairMode_DontRepair `shouldReturn` False
201201

202202
--privileged
203203
itRights "check=True repair=True" $
204-
verifyStore doCheck doRepair `shouldReturn` False
204+
verifyStore doCheck RepairMode_DoRepair `shouldReturn` False
205205

206206
context "addTextToStore" $
207207
itRights "adds text to store" $ withPath pure
@@ -262,7 +262,7 @@ spec_protocol = Hspec.around withNixDaemon $
262262
itRights "adds file to store" $ do
263263
fp <- liftIO $ writeSystemTempFile "addition" "lal"
264264
let name = Data.Either.fromRight (error "impossible") $ makeStorePathName "tmp-addition"
265-
res <- addToStore @SHA256 name (dumpPath fp) FileIngestionMethod_Flat dontRepair
265+
res <- addToStore @SHA256 name (dumpPath fp) FileIngestionMethod_Flat RepairMode_DontRepair
266266
liftIO $ print res
267267

268268
context "with dummy" $ do

hnix-store-tests/src/System/Nix/Arbitrary/Store/Types.hs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,6 @@ import Test.QuickCheck.Arbitrary.Generic (GenericArbitrary(..))
1010

1111
deriving via GenericArbitrary FileIngestionMethod
1212
instance Arbitrary FileIngestionMethod
13+
14+
deriving via GenericArbitrary RepairMode
15+
instance Arbitrary RepairMode

0 commit comments

Comments
 (0)