diff options
| author | Aram Drevekenin <aram@poor.dev> | 2020-11-25 17:08:43 +0100 |
|---|---|---|
| committer | Aram Drevekenin <aram@poor.dev> | 2020-11-25 17:08:43 +0100 |
| commit | 489ade6eb8fc113368ec034efa340c157eb45629 (patch) | |
| tree | 420028d6e36bcdc23a996f872be4ef0514479afd /src/utils/logging.rs | |
| parent | hotfix(controls): clear buffer in normal mode (diff) | |
| download | sl0ppij-489ade6eb8fc113368ec034efa340c157eb45629.tar.gz sl0ppij-489ade6eb8fc113368ec034efa340c157eb45629.tar.xz sl0ppij-489ade6eb8fc113368ec034efa340c157eb45629.zip | |
hotfix(logging): atomically create tmp folders
Diffstat (limited to 'src/utils/logging.rs')
| -rw-r--r-- | src/utils/logging.rs | 14 |
1 files changed, 13 insertions, 1 deletions
diff --git a/src/utils/logging.rs b/src/utils/logging.rs index 031813ed..4bd53743 100644 --- a/src/utils/logging.rs +++ b/src/utils/logging.rs @@ -7,10 +7,22 @@ use std::{ use crate::utils::consts::{MOSAIC_TMP_LOG_DIR, MOSAIC_TMP_LOG_FILE}; -fn atomic_create_file(file_name: &str) { +pub fn atomic_create_file(file_name: &str) { let _ = fs::OpenOptions::new().create(true).open(file_name); } +pub fn atomic_create_dir(dir_name: &str) -> io::Result<()> { + if let Err(e) = fs::create_dir(dir_name) { + if e.kind() == std::io::ErrorKind::AlreadyExists { + Ok(()) + } else { + Err(e) + } + } else { + Ok(()) + } +} + pub fn debug_log_to_file(message: String) -> io::Result<()> { atomic_create_file(MOSAIC_TMP_LOG_FILE); let mut file = fs::OpenOptions::new() |
