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
|
||||
-> Either String (Either (Annex SimState) SimState)
|
||||
applySimCommand (CommandInit reponame) st =
|
||||
let (u, st') = genSimUUID st reponame
|
||||
in Right $ Right $ st'
|
||||
{ simRepos = M.insert reponame u (simRepos st')
|
||||
}
|
||||
applySimCommand (CommandInitRemote reponame) st =
|
||||
let (u, st') = genSimUUID st reponame
|
||||
in Right $ Right $ st'
|
||||
{ simSpecialRemotes = M.insert reponame u (simSpecialRemotes st')
|
||||
}
|
||||
checkNonexistantRepo reponame st $
|
||||
let (u, st') = genSimUUID st reponame
|
||||
in Right $ Right $ st'
|
||||
{ simRepos = M.insert reponame u (simRepos st')
|
||||
}
|
||||
applySimCommand (CommandInitRemote reponame) st =
|
||||
checkNonexistantRepo reponame st $
|
||||
let (u, st') = genSimUUID st reponame
|
||||
in Right $ Right $ st'
|
||||
{ simSpecialRemotes = M.insert reponame u (simSpecialRemotes st')
|
||||
}
|
||||
applySimCommand (CommandUse reponame s) st =
|
||||
case existingRepoByName (simExistingRepoByName st) s of
|
||||
(u:[], _) -> Right $ Right $ st
|
||||
{ simSpecialRemotes = M.insert reponame u (simSpecialRemotes st)
|
||||
}
|
||||
(u:[], _) -> checkNonexistantRepo reponame st $
|
||||
Right $ Right $ st
|
||||
{ simSpecialRemotes = M.insert reponame u (simSpecialRemotes st)
|
||||
}
|
||||
(_, msg) -> Left $ "Unable to use a repository \""
|
||||
++ fromRepoName reponame
|
||||
++ "\" in the simulation because " ++ msg
|
||||
|
@ -235,6 +238,12 @@ applySimCommand (CommandRebalance b) st = Right $ Right $ st
|
|||
{ 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 st a = case M.lookup reponame (simRepos st) of
|
||||
Just _ -> a
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue