From 33f35926121d910e906b33c9d7ee7b77d1963fdf Mon Sep 17 00:00:00 2001 From: Olivia Lee Date: Sun, 6 Apr 2025 19:38:55 -0700 Subject: [PATCH] fix starting the server when db/media dirs do not exist yet This used to be supported, as we explicitly call std::fs::create_dir_all when initializing these, but it was broken in b01b70fc20f334d5060f14799bca7687eaeafd77, which attempts to canonicalize the paths to check for overlap before creating them. --- src/config.rs | 12 ++++++------ src/utils.rs | 1 - 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/src/config.rs b/src/config.rs index 4a174c35..9ad6e1ec 100644 --- a/src/config.rs +++ b/src/config.rs @@ -15,7 +15,7 @@ use ruma::{ use serde::Deserialize; use strum::{Display, EnumIter, IntoEnumIterator}; -use crate::error; +use crate::{error, utils::partial_canonicalize}; mod env_filter_clone; mod proxy; @@ -548,13 +548,13 @@ where } if !sandboxed { - let media_path = x - .path - .canonicalize() + let media_path = partial_canonicalize(&x.path) + .await .map_err(|e| Error::Canonicalize(e, x.path.clone()))?; - let database_path = - config.database.path.canonicalize().map_err(|e| { + let database_path = partial_canonicalize(&config.database.path) + .await + .map_err(|e| { Error::Canonicalize(e, config.database.path.clone()) })?; diff --git a/src/utils.rs b/src/utils.rs index 568bc5be..48803d82 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -388,7 +388,6 @@ pub(crate) fn u8_slice_to_hex(slice: &[u8]) -> String { /// It's assumed that non-existent components will be created as /// directories. This should match the result of [`fs::canonicalize`] /// _after_ calling [`fs::create_dir_all`] on `path`. -#[allow(dead_code)] pub(crate) async fn partial_canonicalize(path: &Path) -> io::Result { let mut ret = std::env::current_dir()?;