Skip to content

Commit ce1d7da

Browse files
committed
Further deduplication within makeFixedOutputPath
1 parent 457683d commit ce1d7da

File tree

1 file changed

+14
-14
lines changed

1 file changed

+14
-14
lines changed

hnix-store-readonly/src/System/Nix/Store/ReadOnly.hs

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -89,27 +89,27 @@ makeFixedOutputPath
8989
-> StorePathName
9090
-> StorePath
9191
makeFixedOutputPath storeDir method digest@(hashAlgo :=> h) refs =
92-
case method of
92+
makeStorePath storeDir ty digest'
93+
where
94+
(ty, digest') = case method of
9395
ContentAddressMethod_Text ->
9496
case hashAlgo of
9597
HashAlgo_SHA256
96-
| references_self refs == False -> makeStorePath storeDir ty digest
97-
where
98-
ty = makeType storeDir "text" refs
98+
| references_self refs == False -> (makeType storeDir "text" refs, digest)
9999
_ -> error "unsupported" -- TODO do better; maybe we'll just remove this restriction too?
100100
_ ->
101101
if method == ContentAddressMethod_NixArchive
102102
&& Some hashAlgo == Some HashAlgo_SHA256
103-
then makeStorePath storeDir (makeType storeDir "source" refs) digest
104-
else makeStorePath storeDir "output:out" (HashAlgo_SHA256 :=> h')
105-
where
106-
h' =
107-
Crypto.Hash.hash @ByteString @SHA256
108-
$ "fixed:out:"
109-
<> Data.Text.Encoding.encodeUtf8 (System.Nix.Hash.algoToText hashAlgo)
110-
<> (if method == ContentAddressMethod_NixArchive then ":r:" else ":")
111-
<> Data.Text.Encoding.encodeUtf8 (System.Nix.Hash.encodeDigestWith Base16 h)
112-
<> ":"
103+
then (makeType storeDir "source" refs, digest)
104+
else let
105+
h' =
106+
Crypto.Hash.hash @ByteString @SHA256
107+
$ "fixed:out:"
108+
<> Data.Text.Encoding.encodeUtf8 (System.Nix.Hash.algoToText hashAlgo)
109+
<> (if method == ContentAddressMethod_NixArchive then ":r:" else ":")
110+
<> Data.Text.Encoding.encodeUtf8 (System.Nix.Hash.encodeDigestWith Base16 h)
111+
<> ":"
112+
in ("output:out", HashAlgo_SHA256 :=> h')
113113

114114
digestPath
115115
:: FilePath -- ^ Local `FilePath` to add

0 commit comments

Comments
 (0)