Skip to content

Commit

Permalink
fix: create parent directory of log file if it doesn't exist yet
Browse files Browse the repository at this point in the history
  • Loading branch information
simongoricar committed Aug 7, 2023
1 parent 37d9172 commit 703476e
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion src/console/frontends/terminal_ui/terminal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ use std::fs::{File, OpenOptions};
use std::io::{stdout, BufWriter, Write};
use std::path::Path;
use std::sync::Arc;
use std::thread;
use std::thread::Scope;
use std::time::Duration;
use std::{fs, thread};

use chrono::Local;
use crossterm::ExecutableCommand;
Expand Down Expand Up @@ -313,6 +313,22 @@ impl<'scope, 'scope_env: 'scope, 'config: 'scope>
scope: &'scope Scope<'scope, 'scope_env>,
) -> Result<()> {
let log_output_file_path = log_output_file_path.as_ref();
let log_output_directory_path = log_output_file_path
.parent()
.ok_or_else(|| miette!("No log file parent directory?!"))?;

if log_output_directory_path.exists()
&& !log_output_directory_path.is_dir()
{
return Err(miette!("Invalid log file path: parent directory path is actually not a directory."));
}
if !log_output_directory_path.exists() {
fs::create_dir_all(log_output_directory_path)
.into_diagnostic()
.wrap_err_with(|| {
miette!("Failed to create log file parent directory.")
})?;
}

let output_file = match log_output_file_path.exists()
&& log_output_file_path.is_file()
Expand Down

0 comments on commit 703476e

Please sign in to comment.