-
Notifications
You must be signed in to change notification settings - Fork 22
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
Closed
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 | ||
|
@@ -45,9 +47,7 @@ makeTextPath fp nm h refs = makeStorePath fp ty h nm | |
|
||
makeFixedOutputPath | ||
:: forall hashAlgo | ||
. ( ValidAlgo hashAlgo | ||
, NamedAlgo hashAlgo | ||
) | ||
. (NamedAlgo hashAlgo) | ||
=> FilePath | ||
-> Bool | ||
-> Digest hashAlgo | ||
|
@@ -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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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.