From f1663e24c148421692346f7470d77b258d78b585 Mon Sep 17 00:00:00 2001 From: Joel Klinghed Date: Mon, 3 Feb 2025 23:58:47 +0100 Subject: code coverage: Add tests for common Add coverage for common as well as server. Fix fs_utils::create_dir_allow_existing to fail if entry exists but isn't a dir. --- server/common/src/fs_utils.rs | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) (limited to 'server/common/src/fs_utils.rs') diff --git a/server/common/src/fs_utils.rs b/server/common/src/fs_utils.rs index 7905d01..b8c8554 100644 --- a/server/common/src/fs_utils.rs +++ b/server/common/src/fs_utils.rs @@ -5,11 +5,18 @@ use std::path::Path; use tokio::fs; pub async fn create_dir_allow_existing(path: impl AsRef) -> io::Result<()> { - match fs::create_dir(path).await { + match fs::create_dir(path.as_ref()).await { Ok(_) => Ok(()), Err(e) => { if e.kind() == io::ErrorKind::AlreadyExists { - Ok(()) + match fs::metadata(path).await { + Ok(metadata) => if metadata.is_dir() { + Ok(()) + } else { + Err(e) + } + Err(e) => Err(e), + } } else { Err(e) } -- cgit v1.2.3-70-g09d2