diff --git a/src/config.rs b/src/config.rs index 03487ace..0c1f2e55 100644 --- a/src/config.rs +++ b/src/config.rs @@ -540,6 +540,10 @@ where match &config.media.backend { MediaBackendConfig::Filesystem(x) => { + if overlap(&x.path, &config.database.path) { + return Err(Error::DatabaseMediaOverlap); + } + let media_path = x .path .canonicalize() @@ -550,11 +554,7 @@ where 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 { + if overlap(&media_path, &database_path) { return Err(Error::DatabaseMediaOverlap); } } @@ -562,3 +562,8 @@ where Ok(config) } + +/// Returns `true` if two paths overlap. +fn overlap(a: &Path, b: &Path) -> bool { + a == b || a.starts_with(b) || b.starts_with(a) +}