Skip to content

Commit 488fe78

Browse files
committed
Fix hash computation in makeFixedOutputPath
1 parent 0099f6d commit 488fe78

File tree

1 file changed

+17
-8
lines changed

1 file changed

+17
-8
lines changed

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

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,12 @@ import Data.Text.Encoding
1212
import System.Nix.Hash
1313
import System.Nix.StorePath
1414

15-
makeStorePath :: forall hashAlgo . (NamedAlgo hashAlgo) => FilePath -> ByteString -> Digest hashAlgo -> StorePathName -> StorePath
15+
makeStorePath :: forall hashAlgo . (NamedAlgo hashAlgo)
16+
=> FilePath
17+
-> ByteString
18+
-> Digest hashAlgo
19+
-> StorePathName
20+
-> StorePath
1621
makeStorePath fp ty h nm = StorePath storeHash nm fp
1722
where
1823
s = BS.intercalate ":"
@@ -29,14 +34,18 @@ makeTextPath fp nm h refs = makeStorePath fp ty h nm
2934
where
3035
ty = BS.intercalate ":" ("text" : map storePathToRawFilePath (HS.toList refs))
3136

32-
makeFixedOutputPath :: forall hashAlgo. (ValidAlgo hashAlgo, NamedAlgo hashAlgo) => FilePath -> Bool -> Digest hashAlgo -> StorePathName -> StorePath
37+
makeFixedOutputPath :: forall hashAlgo . (ValidAlgo hashAlgo, NamedAlgo hashAlgo)
38+
=> FilePath
39+
-> Bool
40+
-> Digest hashAlgo
41+
-> StorePathName
42+
-> StorePath
3343
makeFixedOutputPath fp recursive h nm =
34-
makeStorePath fp ty h' nm
35-
where
36-
(ty, h') =
37-
if recursive && algoName @hashAlgo == algoName @'SHA256
38-
then ("source", h)
39-
else ("output:out", hash ("fixed:out:" <> encodeUtf8 (encodeBase16 h) <> ":"))
44+
if recursive && (algoName @hashAlgo) == "sha256"
45+
then makeStorePath fp "source" h nm
46+
else makeStorePath fp "output:out" h' nm
47+
where
48+
h' = hash @'SHA256 $ "fixed:out:" <> encodeUtf8 (algoName @hashAlgo) <> (if recursive then ":r:" else ":") <> encodeUtf8 (encodeBase16 h) <> ":"
4049

4150
computeStorePathForText :: FilePath -> StorePathName -> ByteString -> StorePathSet -> StorePath
4251
computeStorePathForText fp nm s refs = makeTextPath fp nm (hash s) refs

0 commit comments

Comments
 (0)