Skip to content

Commit df43823

Browse files
committed
hnix-store-remote: Remove erroneous path putting/getting.
mkPath's logic was completely wrong (tried to make a PathName out of the entire path, made up a hash based on the whole path rather than parsing base32) and putPath ignored the store directory and the hash part. Much of the code that depended on these functions was actually correct, but ultimately did the wrong thing. We can resurrect those from git once the primitives are correctly implemented.
1 parent 13e0724 commit df43823

File tree

3 files changed

+1
-264
lines changed

3 files changed

+1
-264
lines changed

hnix-store-remote/hnix-store-remote.cabal

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name: hnix-store-remote
2-
version: 0.1.0.0
2+
version: 0.2.0.0
33
synopsis: Remote hnix store
44
description: Implementation of the nix store using the daemon protocol.
55
homepage: https://github.com/haskell-nix/hnix-store

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

Lines changed: 0 additions & 226 deletions
Original file line numberDiff line numberDiff line change
@@ -7,244 +7,23 @@
77
{-# LANGUAGE TypeApplications #-}
88
module System.Nix.Store.Remote (
99
runStore
10-
, isValidPathUncached
11-
, queryValidPaths
12-
, queryAllValidPaths
13-
, querySubstitutablePaths
14-
, querySubstitutablePathInfos
15-
, queryPathInfoUncached
16-
, queryReferrers
17-
, queryValidDerivers
18-
, queryDerivationOutputs
19-
, queryDerivationOutputNames
20-
, queryPathFromHashPart
21-
, addToStore
22-
, addTextToStore
23-
, buildPaths
24-
, ensurePath
25-
, addTempRoot
26-
, addIndirectRoot
2710
, syncWithGC
28-
, findRoots
29-
, collectGarbage
3011
, optimiseStore
3112
, verifyStore
32-
, addSignatures
3313
) where
3414

3515
import Control.Monad
36-
import Control.Monad.IO.Class (liftIO)
37-
import qualified Data.Binary.Put as B
38-
import Data.Maybe
39-
import qualified Data.ByteString.Lazy as LBS
40-
import qualified Data.Map.Strict as M
41-
import Data.Proxy (Proxy)
42-
import qualified Data.Text.Lazy as T
43-
import qualified Data.Text.Lazy.Encoding as T
44-
45-
import qualified System.Nix.Build as Build
46-
import qualified System.Nix.GC as GC
47-
import System.Nix.Path
48-
import System.Nix.Hash
49-
import System.Nix.Nar (localPackNar, putNar, narEffectsIO)
50-
import System.Nix.Util
5116

5217
import System.Nix.Store.Remote.Types
5318
import System.Nix.Store.Remote.Protocol
5419
import System.Nix.Store.Remote.Util
5520

5621
type RepairFlag = Bool
5722
type CheckFlag = Bool
58-
type SubstituteFlag = Bool
59-
60-
--setOptions :: StoreSetting -> MonadStore ()
61-
62-
isValidPathUncached :: Path -> MonadStore Bool
63-
isValidPathUncached p = simpleOpArgs IsValidPath $ putPath p
64-
65-
queryValidPaths :: PathSet -> SubstituteFlag -> MonadStore PathSet
66-
queryValidPaths ps substitute = do
67-
runOpArgs QueryValidPaths $ do
68-
putPaths ps
69-
putBool substitute
70-
sockGetPaths
71-
72-
queryAllValidPaths :: MonadStore PathSet
73-
queryAllValidPaths = do
74-
runOp QueryAllValidPaths
75-
sockGetPaths
76-
77-
querySubstitutablePaths :: PathSet -> MonadStore PathSet
78-
querySubstitutablePaths ps = do
79-
runOpArgs QuerySubstitutablePaths $ do
80-
putPaths ps
81-
sockGetPaths
82-
83-
querySubstitutablePathInfos :: PathSet -> MonadStore [SubstitutablePathInfo]
84-
querySubstitutablePathInfos ps = do
85-
runOpArgs QuerySubstitutablePathInfos $ do
86-
putPaths ps
87-
88-
cnt <- sockGetInt
89-
forM (take cnt $ cycle [(0 :: Int)]) $ pure $ do
90-
_pth <- sockGetPath
91-
drv <- sockGetStr
92-
refs <- sockGetPaths
93-
dlSize <- sockGetInt
94-
narSize' <- sockGetInt
95-
return $ SubstitutablePathInfo {
96-
deriver = mkPath drv
97-
, references = refs
98-
, downloadSize = dlSize
99-
, narSize = narSize'
100-
}
101-
102-
queryPathInfoUncached :: Path -> MonadStore ValidPathInfo
103-
queryPathInfoUncached p = do
104-
runOpArgs QueryPathInfo $ do
105-
putPath p
106-
107-
valid <- sockGetBool
108-
unless valid $ error "Path is not valid"
109-
110-
drv <- sockGetStr
111-
hash' <- lBSToText <$> sockGetStr
112-
refs <- sockGetPaths
113-
regTime <- sockGetInt
114-
size <- sockGetInt
115-
ulti <- sockGetBool
116-
sigs' <- map lBSToText <$> sockGetStrings
117-
ca' <- lBSToText <$> sockGetStr
118-
return $ ValidPathInfo {
119-
path = p
120-
, deriverVP = mkPath drv
121-
, narHash = hash'
122-
, referencesVP = refs
123-
, registrationTime = regTime
124-
, narSizeVP = size
125-
, ultimate = ulti
126-
, sigs = sigs'
127-
, ca = ca'
128-
}
129-
130-
queryReferrers :: Path -> MonadStore PathSet
131-
queryReferrers p = do
132-
runOpArgs QueryReferrers $ do
133-
putPath p
134-
sockGetPaths
135-
136-
queryValidDerivers :: Path -> MonadStore PathSet
137-
queryValidDerivers p = do
138-
runOpArgs QueryValidDerivers $ do
139-
putPath p
140-
sockGetPaths
141-
142-
queryDerivationOutputs :: Path -> MonadStore PathSet
143-
queryDerivationOutputs p = do
144-
runOpArgs QueryDerivationOutputs $
145-
putPath p
146-
sockGetPaths
147-
148-
queryDerivationOutputNames :: Path -> MonadStore PathSet
149-
queryDerivationOutputNames p = do
150-
runOpArgs QueryDerivationOutputNames $
151-
putPath p
152-
sockGetPaths
153-
154-
-- XXX: this is broken as I don't know how to get hashes from paths (fix mkPath)
155-
queryPathFromHashPart :: Digest PathHashAlgo -> MonadStore (Maybe Path)
156-
queryPathFromHashPart d = do
157-
runOpArgs QueryPathFromHashPart $
158-
-- TODO: replace `undefined` with digest encoding function when
159-
-- [issue 24](https://github.com/haskell-nix/hnix-store/issues/24) is
160-
-- closed
161-
putByteStringLen $ LBS.fromStrict $ undefined d
162-
sockGetPath
163-
164-
type PathFilter = Path -> Bool
165-
166-
addToStore
167-
:: forall a. (ValidAlgo a, NamedAlgo a)
168-
=> LBS.ByteString
169-
-> FilePath
170-
-> Bool
171-
-> Proxy a
172-
-> PathFilter
173-
-> RepairFlag
174-
-> MonadStore Path
175-
addToStore name pth recursive algoProxy pfilter repair = do
176-
177-
-- TODO: Is this lazy enough? We need `B.putLazyByteString bs` to stream `bs`
178-
bs :: LBS.ByteString <- liftIO $ B.runPut . putNar <$> localPackNar narEffectsIO pth
179-
180-
runOpArgs AddToStore $ do
181-
putByteStringLen name
182-
putInt 1
183-
if recursive
184-
then putInt 1
185-
else putInt 0
186-
187-
putByteStringLen (T.encodeUtf8 . T.toLower . T.fromStrict $ algoName @a)
188-
189-
B.putLazyByteString bs
190-
191-
fmap (fromMaybe $ error "TODO: Error") sockGetPath
192-
193-
194-
addTextToStore :: LBS.ByteString -> LBS.ByteString -> PathSet -> RepairFlag -> MonadStore (Maybe Path)
195-
addTextToStore name text references' repair = do
196-
runOpArgs AddTextToStore $ do
197-
putByteStringLen name
198-
putByteStringLen text
199-
putPaths references'
200-
sockGetPath
201-
202-
buildPaths :: PathSet -> Build.BuildMode -> MonadStore ()
203-
buildPaths ps bm = void $ simpleOpArgs EnsurePath $ do
204-
putPaths ps
205-
putInt $ fromEnum bm
206-
207-
ensurePath :: Path -> MonadStore ()
208-
ensurePath pn = void $ simpleOpArgs EnsurePath $ putPath pn
209-
210-
addTempRoot :: Path -> MonadStore ()
211-
addTempRoot pn = void $ simpleOpArgs AddTempRoot $ putPath pn
212-
213-
addIndirectRoot :: Path -> MonadStore ()
214-
addIndirectRoot pn = void $ simpleOpArgs AddIndirectRoot $ putPath pn
21523

21624
syncWithGC :: MonadStore ()
21725
syncWithGC = void $ simpleOp SyncWithGC
21826

219-
findRoots :: MonadStore Roots
220-
findRoots = do
221-
runOp FindRoots
222-
res <- getSocketIncremental (do
223-
count <- getInt
224-
res <- sequence $ replicate count ((,) <$> getPath <*> getPath)
225-
return res
226-
)
227-
228-
return $ M.fromList $ catMaybesTupled res
229-
where
230-
catMaybesTupled :: [(Maybe a, Maybe b)] -> [(a, b)]
231-
catMaybesTupled ls = map (\(Just x, Just y) -> (x, y)) $ filter (\(x,y) -> isJust x && isJust y) ls
232-
233-
collectGarbage :: GC.Options -> MonadStore GC.Result
234-
collectGarbage opts = do
235-
runOpArgs CollectGarbage $ do
236-
putInt $ fromEnum $ GC.operation opts
237-
putPaths $ GC.pathsToDelete opts
238-
putBool $ GC.ignoreLiveness opts
239-
putInt $ GC.maxFreed opts
240-
forM_ [(0 :: Int)..2] $ pure $ putInt (0 :: Int) -- removed options
241-
242-
paths <- sockGetPaths
243-
freed <- sockGetInt
244-
_obsolete <- sockGetInt :: MonadStore Int
245-
246-
return $ GC.Result paths freed
247-
24827
optimiseStore :: MonadStore ()
24928
optimiseStore = void $ simpleOp OptimiseStore
25029

@@ -253,8 +32,3 @@ verifyStore :: CheckFlag -> RepairFlag -> MonadStore Bool
25332
verifyStore check repair = simpleOpArgs VerifyStore $ do
25433
putBool check
25534
putBool repair
256-
257-
addSignatures :: Path -> [LBS.ByteString] -> MonadStore ()
258-
addSignatures p signatures = void $ simpleOpArgs AddSignatures $ do
259-
putPath p
260-
putByteStrings signatures

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

Lines changed: 0 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ import Network.Socket.ByteString (recv, sendAll)
1616

1717
import System.Nix.Store.Remote.Types
1818
import System.Nix.Hash
19-
import System.Nix.Path
2019
import System.Nix.Util
2120

2221

@@ -44,12 +43,6 @@ sockGet = do
4443
soc <- ask
4544
liftIO $ Just <$> recv soc 8
4645

47-
sockGetPath :: MonadStore (Maybe Path)
48-
sockGetPath = getSocketIncremental getPath
49-
50-
sockGetPaths :: MonadStore PathSet
51-
sockGetPaths = getSocketIncremental getPaths
52-
5346
sockGetInt :: Integral a => MonadStore a
5447
sockGetInt = getSocketIncremental getInt
5548

@@ -68,36 +61,6 @@ lBSToText = T.pack . BSC.unpack . LBS.toStrict
6861
textToLBS :: Text -> LBS.ByteString
6962
textToLBS = LBS.fromStrict . BSC.pack . T.unpack
7063

71-
-- XXX: needs work
72-
mkPath :: LBS.ByteString -> Maybe Path
73-
mkPath p = case (pathName $ lBSToText p) of
74-
-- TODO: replace `undefined` with digest encoding function when
75-
-- [issue 24](https://github.com/haskell-nix/hnix-store/issues/24)
76-
-- is closed
77-
Just x -> Just $ Path (hash $ LBS.toStrict p) x --XXX: hash
78-
Nothing -> Nothing
79-
80-
-- WOOT
81-
-- import Data.ByteString.Base32 as Base32
82-
--drvP = Path (fromJust $ digestFromByteString $ pls $ Base32.decode $ BSC.take 32 $ BSC.drop (BSC.length "/nix/store/") drv) (fromJust $ pathName $ T.pack $ BSC.unpack drv)
83-
--pls (Left _) = error "unable to decode hash"
84-
--pls (Right x) = x
85-
86-
getPath :: Get (Maybe Path)
87-
getPath = mkPath <$> getByteStringLen
88-
89-
getPaths :: Get PathSet
90-
getPaths = HashSet.fromList . catMaybes . map mkPath <$> getByteStrings
91-
92-
putPathName :: PathName -> Put
93-
putPathName = putByteStringLen . textToLBS . pathNameContents
94-
95-
putPath :: Path -> Put
96-
putPath (Path _hash name) = putPathName name
97-
98-
putPaths :: PathSet -> Put
99-
putPaths = putByteStrings . HashSet.map (\(Path _hash name) -> textToLBS $ pathNameContents name)
100-
10164
putBool :: Bool -> Put
10265
putBool True = putInt (1 :: Int)
10366
putBool False = putInt (0 :: Int)

0 commit comments

Comments
 (0)