prevent overwriting a repo in the simulation
This commit is contained in:
parent
8f8e35ac3b
commit
65dd018850
1 changed files with 21 additions and 12 deletions
33
Annex/Sim.hs
33
Annex/Sim.hs
|
@ -123,20 +123,23 @@ applySimCommand
|
||||||
-> SimState
|
-> SimState
|
||||||
-> Either String (Either (Annex SimState) SimState)
|
-> Either String (Either (Annex SimState) SimState)
|
||||||
applySimCommand (CommandInit reponame) st =
|
applySimCommand (CommandInit reponame) st =
|
||||||
let (u, st') = genSimUUID st reponame
|
checkNonexistantRepo reponame st $
|
||||||
in Right $ Right $ st'
|
let (u, st') = genSimUUID st reponame
|
||||||
{ simRepos = M.insert reponame u (simRepos st')
|
in Right $ Right $ st'
|
||||||
}
|
{ simRepos = M.insert reponame u (simRepos st')
|
||||||
applySimCommand (CommandInitRemote reponame) st =
|
}
|
||||||
let (u, st') = genSimUUID st reponame
|
applySimCommand (CommandInitRemote reponame) st =
|
||||||
in Right $ Right $ st'
|
checkNonexistantRepo reponame st $
|
||||||
{ simSpecialRemotes = M.insert reponame u (simSpecialRemotes st')
|
let (u, st') = genSimUUID st reponame
|
||||||
}
|
in Right $ Right $ st'
|
||||||
|
{ simSpecialRemotes = M.insert reponame u (simSpecialRemotes st')
|
||||||
|
}
|
||||||
applySimCommand (CommandUse reponame s) st =
|
applySimCommand (CommandUse reponame s) st =
|
||||||
case existingRepoByName (simExistingRepoByName st) s of
|
case existingRepoByName (simExistingRepoByName st) s of
|
||||||
(u:[], _) -> Right $ Right $ st
|
(u:[], _) -> checkNonexistantRepo reponame st $
|
||||||
{ simSpecialRemotes = M.insert reponame u (simSpecialRemotes st)
|
Right $ Right $ st
|
||||||
}
|
{ simSpecialRemotes = M.insert reponame u (simSpecialRemotes st)
|
||||||
|
}
|
||||||
(_, msg) -> Left $ "Unable to use a repository \""
|
(_, msg) -> Left $ "Unable to use a repository \""
|
||||||
++ fromRepoName reponame
|
++ fromRepoName reponame
|
||||||
++ "\" in the simulation because " ++ msg
|
++ "\" in the simulation because " ++ msg
|
||||||
|
@ -235,6 +238,12 @@ applySimCommand (CommandRebalance b) st = Right $ Right $ st
|
||||||
{ simRebalance = b
|
{ simRebalance = b
|
||||||
}
|
}
|
||||||
|
|
||||||
|
checkNonexistantRepo :: RepoName -> SimState -> Either String a -> Either String a
|
||||||
|
checkNonexistantRepo reponame st a = case M.lookup reponame (simRepos st) of
|
||||||
|
Nothing -> a
|
||||||
|
Just _ -> Left $ "There is already a repository in the simulation named \""
|
||||||
|
++ fromRepoName reponame ++ "\"."
|
||||||
|
|
||||||
checkKnownRepo :: RepoName -> SimState -> Either String a -> Either String a
|
checkKnownRepo :: RepoName -> SimState -> Either String a -> Either String a
|
||||||
checkKnownRepo reponame st a = case M.lookup reponame (simRepos st) of
|
checkKnownRepo reponame st a = case M.lookup reponame (simRepos st) of
|
||||||
Just _ -> a
|
Just _ -> a
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue