addmulti
This commit is contained in:
parent
2a16796a1c
commit
4c7db31c20
4 changed files with 43 additions and 3 deletions
11
Annex/Sim.hs
11
Annex/Sim.hs
|
@ -199,6 +199,7 @@ data SimCommand
|
|||
| CommandDisconnect Connections
|
||||
| CommandAddTree RepoName PreferredContentExpression
|
||||
| CommandAdd RawFilePath ByteSize [RepoName]
|
||||
| CommandAddMulti Int String ByteSize ByteSize [RepoName]
|
||||
| CommandStep Int
|
||||
| CommandAction SimAction
|
||||
| CommandSeed Int
|
||||
|
@ -319,6 +320,16 @@ applySimCommand' (CommandAdd file sz repos) st _ =
|
|||
{ simFiles = M.insert file k (simFiles st')
|
||||
}
|
||||
in go k st'' rest
|
||||
applySimCommand' (CommandAddMulti n suffix minsz maxsz repos) st repobyname =
|
||||
let (sz, st') = simRandom st (randomR (minsz, maxsz)) id
|
||||
file = toRawFilePath (show n ++ suffix)
|
||||
in case applySimCommand' (CommandAdd file sz repos) st' repobyname of
|
||||
Left err -> Left err
|
||||
Right (Right st'') ->
|
||||
case pred n of
|
||||
0 -> Right (Right st'')
|
||||
n' -> applySimCommand' (CommandAddMulti n' suffix minsz maxsz repos) st'' repobyname
|
||||
Right (Left _) -> error "applySimCommand' CommandAddMulti"
|
||||
applySimCommand' (CommandStep _) _ _ = error "applySimCommand' CommandStep"
|
||||
applySimCommand' (CommandAction act) st _ =
|
||||
case getSimActionComponents act st of
|
||||
|
|
|
@ -49,6 +49,8 @@ generateSimFile = unlines . map unwords . go
|
|||
["addtree", name, expr] : go rest
|
||||
go (CommandAdd f sz repos : rest) =
|
||||
(["add", fromRawFilePath f, showsize sz] ++ map fromRepoName repos) : go rest
|
||||
go (CommandAddMulti n suffix minsz maxsz repos : rest) =
|
||||
(["addmulti", show n, suffix, showsize minsz, showsize maxsz] ++ map fromRepoName repos) : go rest
|
||||
go (CommandStep n : rest) =
|
||||
["step", show n] : go rest
|
||||
go (CommandAction act : rest) = formatAction act : go rest
|
||||
|
@ -127,6 +129,16 @@ parseSimCommand ("add":filename:size:repos) =
|
|||
sz
|
||||
(map RepoName repos)
|
||||
Nothing -> Left $ "Unable to parse file size \"" ++ size ++ "\""
|
||||
parseSimCommand ("addmulti":num:suffix:minsize:maxsize:repos) =
|
||||
case readSize dataUnits minsize of
|
||||
Just minsz -> case readSize dataUnits maxsize of
|
||||
Just maxsz -> case readMaybe num of
|
||||
Just n -> Right $ CommandAddMulti
|
||||
n suffix minsz maxsz
|
||||
(map RepoName repos)
|
||||
Nothing -> Left $ "Unable to parse number \"" ++ num ++ "\""
|
||||
Nothing -> Left $ "Unable to parse file size \"" ++ maxsize ++ "\""
|
||||
Nothing -> Left $ "Unable to parse file size \"" ++ minsize ++ "\""
|
||||
parseSimCommand ("step":n:[]) =
|
||||
case readMaybe n of
|
||||
Just n' -> Right $ CommandStep n'
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue