1
0

Check for write access before change. (#890)

* Check for write access before change. Closes #862

* Formatting.
This commit is contained in:
chaos
2023-11-21 17:37:05 +02:00
committed by GitHub
parent 4b1a3eb41e
commit fd299aabe8
4 changed files with 42 additions and 3 deletions

View File

@@ -1,6 +1,7 @@
//! Theseus profile management interface
use std::path::PathBuf;
use tokio::fs;
use io::IOError;
use tokio::sync::RwLock;
@@ -188,3 +189,17 @@ pub async fn set_config_dir(new_config_dir: PathBuf) -> crate::Result<()> {
Ok(())
}
pub async fn is_dir_writeable(new_config_dir: PathBuf) -> crate::Result<bool> {
let temp_path = new_config_dir.join(".tmp");
match fs::write(temp_path.clone(), "test").await {
Ok(_) => {
fs::remove_file(temp_path).await?;
Ok(true)
}
Err(e) => {
tracing::error!("Error writing to new config dir: {}", e);
Ok(false)
}
}
}