-
Notifications
You must be signed in to change notification settings - Fork 25
Implement 'addToStore' #53
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
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -15,6 +15,8 @@ module System.Nix.Nar ( | |
| , Nar(..) | ||
| , getNar | ||
| , localPackNar | ||
| , localPackNar' | ||
| , FilePathFilter | ||
| , localUnpackNar | ||
| , narEffectsIO | ||
| , putNar | ||
|
|
@@ -240,10 +242,15 @@ localUnpackNar effs basePath (Nar fso) = localUnpackFSO basePath fso | |
|
|
||
| -- | Pack a NAR from a filepath | ||
| localPackNar :: Monad m => NarEffects m -> FilePath -> m Nar | ||
| localPackNar effs basePath = Nar <$> localPackFSO basePath | ||
| localPackNar effs basePath = localPackNar' effs basePath (const True) | ||
|
|
||
| where | ||
| type FilePathFilter = FilePath -> Bool | ||
|
|
||
| -- | Pack a NAR from a filepath, omitting the entries matching `filter` | ||
| localPackNar' :: Monad m => NarEffects m -> FilePath -> FilePathFilter -> m Nar | ||
| localPackNar' effs basePath pathFilter = Nar <$> localPackFSO basePath | ||
|
|
||
| where | ||
| localPackFSO path' = do | ||
| fType <- (,) <$> narIsDir effs path' <*> narIsSymLink effs path' | ||
| case fType of | ||
|
|
@@ -252,7 +259,7 @@ localPackNar effs basePath = Nar <$> localPackFSO basePath | |
| <*> narFileSize effs path' | ||
| <*> narReadFile effs path' | ||
| (True , _) -> fmap (Directory . Map.fromList) $ do | ||
| fs <- narListDir effs path' | ||
| fs <- filter (pathFilter . (path' </>)) <$> narListDir effs path' | ||
|
Collaborator
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.
Contributor
Author
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. Yep, I was not sure myself while wirting it, hence this confusion. But we have to scrape this whole implementation as the only filter that we want to use is a nix function, and hence wrapped in a MonadNix monad. This implementation cannot be used at all from what I have found. |
||
| forM fs $ \fp -> | ||
| (FilePathPart (BSC.pack $ fp),) <$> localPackFSO (path' </> fp) | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| {-# OPTIONS_GHC -F -pgmF tasty-discover #-} |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,54 @@ | ||
| {-# LANGUAGE DataKinds #-} | ||
| {-# LANGUAGE OverloadedStrings #-} | ||
| {-# LANGUAGE ScopedTypeVariables #-} | ||
| {-# LANGUAGE TypeApplications #-} | ||
|
|
||
| module Operations where | ||
|
|
||
| import Control.Monad | ||
| import Control.Monad.Except | ||
| import Control.Monad.Reader | ||
| import Control.Monad.State | ||
| import Data.Maybe | ||
|
|
||
| import Data.Proxy | ||
| import Data.Text.Encoding ( encodeUtf8 ) | ||
| import Data.Text as T | ||
| import Data.Text.Encoding as T | ||
| import Data.Text.Lazy as TL | ||
| import Data.Text.Lazy.Encoding as TL | ||
| import Data.ByteString.Char8 as BS | ||
|
|
||
| import System.FilePath | ||
| import System.Nix.Hash | ||
| import System.Nix.Internal.Hash | ||
| import System.Nix.Nar | ||
| import System.Nix.StorePath | ||
| import System.Nix.Store.Remote | ||
| import System.Nix.Store.Remote.Types | ||
| import System.Nix.Store.Remote.Protocol | ||
| import System.Nix.Store.Remote.Util | ||
| import System.Nix.Util | ||
|
|
||
| import Test.Tasty as T | ||
| import Test.Tasty.Hspec | ||
| import qualified Test.Tasty.HUnit as HU | ||
| import Test.Tasty.QuickCheck | ||
| import Text.Read (readMaybe) | ||
|
|
||
| spec_addToStore :: Spec | ||
| spec_addToStore = do | ||
|
|
||
| describe "addToStore remote operation" $ do | ||
|
|
||
| it "uploads correctly" $ do | ||
| let name = fromJust $ makeStorePathName "test-recursive-add" | ||
| let srcPath = "./tests/data/add-recursive" | ||
| let recursive = True | ||
| let filter :: FilePathFilter | ||
| filter path | takeBaseName path == "ignore" = False | ||
| | otherwise = True | ||
| let repair = False | ||
| res <- runStore $ (addToStore @'SHA256 name srcPath recursive filter repair :: MonadStore "/nix/store" (StorePath "/nix/store")) | ||
| res `shouldBe` (Right (StorePath (Digest $ T.encodeUtf8 "0mbh3xdb9fkqb2i3iwv6hhz7qiicca83") name),[Last]) | ||
|
|
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.
This is just a matter of style, so feel free to ignore it! But, why add a type alias? I like to use them sparingly, since they are another thing for API users to have to learn, and they can pile up over time.
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.
Yep, style has definitely been overlooked while writing this. I wanted to achieve a minimal prototype while ignoring everything else. I would dare say this PR is not for merging, more for sharing ideas and POC implementation. Hopefully it will trigger some more progress HNix.