Skip to content

Commit

Permalink
startup notification: create_dir_all parent dir, add context for io ops
Browse files Browse the repository at this point in the history
  • Loading branch information
colemickens committed Aug 29, 2024
1 parent f0b1e69 commit 21a9552
Showing 1 changed file with 27 additions and 2 deletions.
29 changes: 27 additions & 2 deletions magic-nix-cache/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -392,8 +392,33 @@ async fn main_cli() -> Result<()> {

tracing::debug!("Startup notification via file at {startup_notification_file_path:?}");

let mut notification_file = File::create(&startup_notification_file_path).await?;
notification_file.write_all(file_contents).await?;
if let Some(parent_dir) = startup_notification_file_path.parent() {
tokio::fs::create_dir_all(parent_dir)
.await
.with_context(|| {
format!(
"failed to create parent directory for startup notification file path: {}",
startup_notification_file_path.display()
)
})?;
}
let mut notification_file = File::create(&startup_notification_file_path)
.await
.with_context(|| {
format!(
"failed to create startup notification file to path: {}",
startup_notification_file_path.display()
)
})?;
notification_file
.write_all(file_contents)
.await
.with_context(|| {
format!(
"failed to write startup notification file to path: {}",
startup_notification_file_path.display()
)
})?;

tracing::debug!("Created startup notification file at {startup_notification_file_path:?}");
}
Expand Down

0 comments on commit 21a9552

Please sign in to comment.