prevent overwriting a repo in the simulation

This commit is contained in:
Joey Hess 2024-09-05 16:22:08 -04:00
parent 8f8e35ac3b
commit 65dd018850
No known key found for this signature in database
GPG key ID: DB12DB0FF05F8F38

View file

@ -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