Skip to content

Commit

Permalink
Fix: create cookie parent dirs if they don't exist
Browse files Browse the repository at this point in the history
  • Loading branch information
mawkler committed Nov 15, 2024
1 parent 231b16e commit 46a5028
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion src/infrastructure/auth_service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,10 @@ impl AuthService {
})
.to_string();

let mut file = tokio::fs::File::create(&*self.get_cookie_path()?)
let cookie_path = &*self.get_cookie_path()?;
ensure_directory_exists(cookie_path)?;

let mut file = tokio::fs::File::create(cookie_path)
.await
.context("Failed to create cookie file")?;
file.write_all(cookie.as_bytes())
Expand Down Expand Up @@ -227,3 +230,12 @@ async fn wait_for_auth_cookie(page: &Page) -> Result<Cookie> {
tokio::time::sleep(POLL_INTERVAL).await;
}
}

fn ensure_directory_exists(file_path: &str) -> Result<()> {
if let Some(parent) = std::path::Path::new(file_path).parent() {
std::fs::create_dir_all(parent)
.with_context(|| format!("Failed to create directories for {file_path}"))?;
}

Ok(())
}

0 comments on commit 46a5028

Please sign in to comment.