summaryrefslogtreecommitdiff
path: root/server/common/src/fs_utils.rs
diff options
context:
space:
mode:
authorJoel Klinghed <the_jk@spawned.biz>2025-02-03 23:58:47 +0100
committerJoel Klinghed <the_jk@spawned.biz>2025-02-03 23:58:47 +0100
commitf1663e24c148421692346f7470d77b258d78b585 (patch)
tree2a44cdb4da386fcca6b6be9037dcd9ce0ac88471 /server/common/src/fs_utils.rs
parent67331b851295b0067f74cd410aef7986aa6a848e (diff)
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.
Diffstat (limited to 'server/common/src/fs_utils.rs')
-rw-r--r--server/common/src/fs_utils.rs11
1 files changed, 9 insertions, 2 deletions
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<Path>) -> 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)
}