mirror of
https://gitlab.computer.surgery/matrix/grapevine.git
synced 2025-12-17 07:41:23 +01:00
reject overlapping media and database paths
This commit is contained in:
parent
81a449d1d2
commit
b01b70fc20
20 changed files with 146 additions and 4 deletions
|
|
@ -538,5 +538,27 @@ where
|
|||
return Err(Error::RegistrationTokenEmpty);
|
||||
}
|
||||
|
||||
match &config.media.backend {
|
||||
MediaBackendConfig::Filesystem(x) => {
|
||||
let media_path = x
|
||||
.path
|
||||
.canonicalize()
|
||||
.map_err(|e| Error::Canonicalize(e, x.path.clone()))?;
|
||||
|
||||
let database_path =
|
||||
config.database.path.canonicalize().map_err(|e| {
|
||||
Error::Canonicalize(e, config.database.path.clone())
|
||||
})?;
|
||||
|
||||
let overlap = media_path == database_path
|
||||
|| media_path.starts_with(&database_path)
|
||||
|| database_path.starts_with(&media_path);
|
||||
|
||||
if overlap {
|
||||
return Err(Error::DatabaseMediaOverlap);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Ok(config)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -134,8 +134,14 @@ pub(crate) enum Config {
|
|||
#[error("failed to parse configuration file {1:?}")]
|
||||
Parse(#[source] toml::de::Error, PathBuf),
|
||||
|
||||
#[error("failed to canonicalize path {}", .1.display())]
|
||||
Canonicalize(#[source] std::io::Error, PathBuf),
|
||||
|
||||
#[error("registration token must not be empty")]
|
||||
RegistrationTokenEmpty,
|
||||
|
||||
#[error("database and media paths overlap")]
|
||||
DatabaseMediaOverlap,
|
||||
}
|
||||
|
||||
/// Errors that can occur while searching for a config file
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue