mirror of
https://gitlab.computer.surgery/matrix/grapevine.git
synced 2025-12-18 08:11:24 +01:00
factor server_name change check into a reusable fn
This commit is contained in:
parent
c2c6083277
commit
1fd20cdeba
3 changed files with 42 additions and 9 deletions
|
|
@ -305,6 +305,37 @@ impl Service {
|
|||
Ok(s)
|
||||
}
|
||||
|
||||
/// Check if `server_name` in the DB and config differ, return error if so
|
||||
///
|
||||
/// Matrix resource ownership is based on the server name; changing it
|
||||
/// requires recreating the database from scratch. This check needs to be
|
||||
/// done before background tasks are started to avoid data races.
|
||||
// Allowed because this function calls `services()`
|
||||
#[allow(clippy::unused_self)]
|
||||
pub(crate) fn err_if_server_name_changed(
|
||||
&self,
|
||||
) -> Result<(), crate::error::ServerNameChanged> {
|
||||
use crate::error::ServerNameChanged as Error;
|
||||
|
||||
if services()
|
||||
.users
|
||||
.count()
|
||||
.map(|x| x > 0)
|
||||
.map_err(Error::NonZeroUsers)?
|
||||
{
|
||||
let admin_bot = self.admin_bot_user_id.as_ref();
|
||||
if !services()
|
||||
.users
|
||||
.exists(admin_bot)
|
||||
.map_err(Error::AdminBotExists)?
|
||||
{
|
||||
return Err(Error::Renamed);
|
||||
}
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Returns this server's keypair.
|
||||
pub(crate) fn keypair(&self) -> &ruma::signatures::Ed25519KeyPair {
|
||||
&self.keypair
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue