-
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 1 commit
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 |
|---|---|---|
|
|
@@ -7,19 +7,33 @@ | |
| {-# LANGUAGE TypeApplications #-} | ||
| module System.Nix.Store.Remote ( | ||
| runStore | ||
| , addToStore | ||
| , syncWithGC | ||
| , optimiseStore | ||
| , verifyStore | ||
| ) where | ||
|
|
||
| import Control.Monad | ||
| import Control.Monad.Except | ||
|
|
||
| import Data.Text.Lazy as TL | ||
| import Data.Text.Lazy.Encoding as TL | ||
|
|
||
| import System.Nix.Hash | ||
| import System.Nix.Nar | ||
| import System.Nix.StorePath | ||
| import System.Nix.Store.Remote.Types | ||
| import System.Nix.Store.Remote.Protocol | ||
| import System.Nix.Store.Remote.Util | ||
| import System.Nix.Util | ||
|
|
||
| import Data.ByteString.Lazy as LBS | ||
|
|
||
|
|
||
| type RepairFlag = Bool | ||
| type CheckFlag = Bool | ||
| type RecursiveFlag = Bool | ||
| type PathFilter = FilePath -> Bool | ||
|
|
||
| syncWithGC :: MonadStore () | ||
| syncWithGC = void $ simpleOp SyncWithGC | ||
|
|
@@ -32,3 +46,23 @@ verifyStore :: CheckFlag -> RepairFlag -> MonadStore Bool | |
| verifyStore check repair = simpleOpArgs VerifyStore $ do | ||
| putBool check | ||
| putBool repair | ||
|
|
||
| addToStore :: forall hashAlgo. (NamedAlgo hashAlgo, ValidAlgo hashAlgo) | ||
| => StorePathName | ||
| -> FilePath | ||
| -> RecursiveFlag | ||
| -> PathFilter | ||
| -> RepairFlag | ||
| -> MonadStore LBS.ByteString | ||
| addToStore name srcPath recursive filter repair = do | ||
| nar <- liftIO $ localPackNar narEffectsIO srcPath -- TODO actually use filter. | ||
| runOpArgs AddToStore $ do | ||
| putByteStringLen $ strToN $ unStorePathName name | ||
| putBool $ not (recursive && algoName @hashAlgo == "sha256") -- backwards compatibility hack | ||
|
||
| putBool recursive | ||
| putByteStringLen $ strToN (algoName @hashAlgo) | ||
| putNar nar | ||
|
|
||
| sockGetStr | ||
| where | ||
| strToN = TL.encodeUtf8 . TL.fromStrict | ||
| 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,47 @@ | ||
| {-# 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.Lazy as TL | ||
| import Data.Text.Lazy.Encoding as TL | ||
|
|
||
| import System.Nix.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 path = False -- not used anyway. | ||
| let repair = False | ||
| res <- runStore $ addToStore @'SHA256 name srcPath recursive filter repair | ||
| res `shouldBe` (Right "/nix/store/0mbh3xdb9fkqb2i3iwv6hhz7qiicca83-test-recursive-add",[Last]) | ||
|
|
Uh oh!
There was an error while loading. Please reload this page.