Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add a readonly computeStorePathForPath #144

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 22 additions & 3 deletions hnix-store-core/src/System/Nix/ReadonlyStore.hs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ import qualified Data.Text as T
import qualified Data.HashSet as HS
import Data.Text.Encoding
import System.Nix.Hash
import System.Nix.Nar
import System.Nix.StorePath
import Control.Monad.State.Strict


makeStorePath
Expand Down Expand Up @@ -45,9 +47,7 @@ makeTextPath fp nm h refs = makeStorePath fp ty h nm

makeFixedOutputPath
:: forall hashAlgo
. ( ValidAlgo hashAlgo
, NamedAlgo hashAlgo
)
. (NamedAlgo hashAlgo)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed superfluous parens here and pushed to master.

=> FilePath
-> Bool
-> Digest hashAlgo
Expand All @@ -69,3 +69,22 @@ makeFixedOutputPath fp recursive h =
computeStorePathForText
:: FilePath -> StorePathName -> ByteString -> (StorePathSet -> StorePath)
computeStorePathForText fp nm = makeTextPath fp nm . hash

computeStorePathForPath
:: StorePathName -- ^ Name part of the newly created `StorePath`
-> FilePath -- ^ Local `FilePath` to add
-> Bool -- ^ Add target directory recursively
-> (FilePath -> Bool) -- ^ Path filter function
-> Bool -- ^ Only used by local store backend
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I feel like we should do something about these two arguments but I'm not sure what.

-> IO StorePath
computeStorePathForPath name pth recursive _pathFilter _repair = do
selectedHash <- if recursive then recursiveContentHash else flatContentHash
pure $ makeFixedOutputPath "/nix/store" recursive selectedHash name
where
recursiveContentHash :: IO (Digest 'SHA256)
recursiveContentHash = finalize <$> execStateT streamNarUpdate (initialize @'SHA256)
streamNarUpdate :: StateT (AlgoCtx 'SHA256) IO ()
streamNarUpdate = streamNarIO (modify . flip (update @'SHA256)) narEffectsIO pth

flatContentHash :: IO (Digest 'SHA256)
flatContentHash = hashLazy <$> narReadFile narEffectsIO pth