Skip to content

Commit c7e66bb

Browse files
committed
hide StorePath constructor, add unsafeMakeStorePath
1 parent a610701 commit c7e66bb

File tree

4 files changed

+23
-8
lines changed

4 files changed

+23
-8
lines changed

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import Data.ByteString (ByteString)
1414
import Data.HashSet (HashSet)
1515
import System.Nix.Hash (BaseEncoding(Base16), NamedAlgo(algoName))
1616
import System.Nix.Store.Types (FileIngestionMethod(..), PathFilter, RepairMode)
17-
import System.Nix.StorePath (StoreDir, StorePath(StorePath), StorePathName)
17+
import System.Nix.StorePath (StoreDir, StorePath, StorePathName)
1818

1919
import qualified Crypto.Hash
2020
import qualified Data.ByteString.Char8
@@ -35,7 +35,8 @@ makeStorePath
3535
-> Digest hashAlgo
3636
-> StorePathName
3737
-> StorePath
38-
makeStorePath storeDir ty h nm = StorePath storeHash nm
38+
makeStorePath storeDir ty h nm =
39+
System.Nix.StorePath.unsafeMakeStorePath storeHash nm
3940
where
4041
storeHash = System.Nix.StorePath.mkStorePathHashPart @hashAlgo s
4142
s =

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

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,9 @@ module System.Nix.StorePath
1010
StoreDir(..)
1111
, HasStoreDir(..)
1212
, getStoreDir
13-
, StorePath(..)
13+
, StorePath
14+
, storePathHash
15+
, storePathName
1416
, StorePathName
1517
, unStorePathName
1618
, StorePathHashPart
@@ -31,6 +33,8 @@ module System.Nix.StorePath
3133
parsePath
3234
, parsePathFromText
3335
, pathParser
36+
-- * Utilities for tests
37+
, unsafeMakeStorePath
3438
) where
3539

3640
import Control.Monad.Reader.Class (MonadReader, asks)
@@ -299,3 +303,13 @@ pathParser expectedRoot = do
299303
(fail . show)
300304
pure
301305
(StorePath <$> hashPart <*> name)
306+
307+
-- * Utilities for tests
308+
309+
-- | Paths rarely need to be constructed directly.
310+
-- Prefer @parsePath@ or @parsePathFromText@
311+
unsafeMakeStorePath
312+
:: StorePathHashPart
313+
-> StorePathName
314+
-> StorePath
315+
unsafeMakeStorePath = StorePath

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ dummy = do
174174
invalidPath :: StorePath
175175
invalidPath =
176176
let name = Data.Either.fromRight (error "impossible") $ makeStorePathName "invalid"
177-
in StorePath (mkStorePathHashPart @SHA256 "invalid") name
177+
in unsafeMakeStorePath (mkStorePathHashPart @SHA256 "invalid") name
178178

179179
withBuilder :: (StorePath -> MonadStore a) -> MonadStore a
180180
withBuilder action = do

hnix-store-tests/src/System/Nix/Arbitrary/StorePath.hs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@ import Crypto.Hash (SHA256)
1111
import qualified Data.ByteString.Char8
1212
import qualified Data.Text
1313
import System.Nix.StorePath (StoreDir(..)
14-
, StorePath(..)
15-
, StorePathName(..)
16-
, StorePathHashPart(..)
14+
, StorePath
15+
, StorePathName
16+
, StorePathHashPart
1717
)
1818
import qualified System.Nix.StorePath
1919

@@ -27,7 +27,7 @@ instance Arbitrary StoreDir where
2727

2828
instance Arbitrary StorePath where
2929
arbitrary =
30-
liftA2 StorePath
30+
liftA2 System.Nix.StorePath.unsafeMakeStorePath
3131
arbitrary
3232
arbitrary
3333

0 commit comments

Comments
 (0)