Skip to content

Commit e6740b5

Browse files
committed
add storePathHashPartToText
1 parent e6f016d commit e6740b5

File tree

4 files changed

+12
-9
lines changed

4 files changed

+12
-9
lines changed

hnix-store-core/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
* `BuildResult`s `timesBuild` field changes type from `Integer` to `Int` [#231](https://github.com/haskell-nix/hnix-store/pull/231)
1010

1111
* Additions:
12+
* `System.Nix.StorePath.storePathHashPartToText` [#231](https://github.com/haskell-nix/hnix-store/pull/231)
1213
* Added `Generic` and `Show` instances for
1314
`Signature` and `NarSignature` [#231](https://github.com/haskell-nix/hnix-store/pull/231)
1415
* Added `Eq` and `Ord` instances for `SomeNamedDigest` [#231](https://github.com/haskell-nix/hnix-store/pull/231)

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

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ module System.Nix.Internal.StorePath
2525
, storePathToRawFilePath
2626
, storePathToText
2727
, storePathToNarInfo
28+
, storePathHashPartToText
2829
, -- * Parsing 'StorePath's
2930
parsePath
3031
, pathParser
@@ -208,7 +209,7 @@ storePathToRawFilePath :: StoreDir -> StorePath -> RawFilePath
208209
storePathToRawFilePath storeDir StorePath{..} =
209210
unStoreDir storeDir <> "/" <> hashPart <> "-" <> name
210211
where
211-
hashPart = encodeUtf8 $ encodeWith NixBase32 $ coerce storePathHash
212+
hashPart = encodeUtf8 $ storePathHashPartToText storePathHash
212213
name = encodeUtf8 $ unStorePathName storePathName
213214

214215
-- | Render a 'StorePath' as a 'FilePath'.
@@ -225,6 +226,12 @@ storePathToNarInfo :: StorePath -> Bytes.Char8.ByteString
225226
storePathToNarInfo StorePath{..} =
226227
encodeUtf8 $ encodeWith NixBase32 (coerce storePathHash) <> ".narinfo"
227228

229+
-- | Render a 'StorePathHashPart' as a 'Text'.
230+
-- This is used by remote store / database
231+
-- via queryPathFromHashPart
232+
storePathHashPartToText :: StorePathHashPart -> Text
233+
storePathHashPartToText = encodeWith NixBase32 . unStorePathHashPart
234+
228235
-- | Parse `StorePath` from `Bytes.Char8.ByteString`, checking
229236
-- that store directory matches `expectedRoot`.
230237
parsePath

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ module System.Nix.StorePath
2222
, storePathToRawFilePath
2323
, storePathToText
2424
, storePathToNarInfo
25+
, storePathHashPartToText
2526
, -- * Parsing 'StorePath's
2627
parsePath
2728
, pathParser

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

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ import Data.HashSet (HashSet)
3939
import Data.Map (Map)
4040
import Data.Text (Text)
4141
import qualified Control.Monad
42-
import qualified Data.ByteString.Lazy
4342
import qualified Data.Text.Encoding
4443
--
4544
import qualified Data.ByteString.Lazy as BSL
@@ -61,7 +60,6 @@ import System.Nix.StorePath ( StorePath
6160
import System.Nix.StorePathMetadata ( Metadata(..)
6261
, StorePathTrust(..)
6362
)
64-
import System.Nix.Internal.Base ( encodeWith )
6563

6664
import qualified Data.Binary.Put
6765
import qualified Data.Map.Strict
@@ -295,12 +293,8 @@ queryDerivationOutputNames p = do
295293
queryPathFromHashPart :: StorePathHashPart -> MonadStore StorePath
296294
queryPathFromHashPart storePathHash = do
297295
runOpArgs QueryPathFromHashPart
298-
$ putByteStringLen
299-
$ Data.ByteString.Lazy.fromStrict
300-
$ Data.Text.Encoding.encodeUtf8
301-
$ encodeWith NixBase32
302-
$ System.Nix.StorePath.unStorePathHashPart
303-
storePathHash
296+
$ putText
297+
$ System.Nix.StorePath.storePathHashPartToText storePathHash
304298
sockGetPath
305299

306300
queryMissing

0 commit comments

Comments
 (0)