Skip to content

Commit 46a5028

Browse files
committed
Fix: create cookie parent dirs if they don't exist
1 parent 231b16e commit 46a5028

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

src/infrastructure/auth_service.rs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,10 @@ impl AuthService {
175175
})
176176
.to_string();
177177

178-
let mut file = tokio::fs::File::create(&*self.get_cookie_path()?)
178+
let cookie_path = &*self.get_cookie_path()?;
179+
ensure_directory_exists(cookie_path)?;
180+
181+
let mut file = tokio::fs::File::create(cookie_path)
179182
.await
180183
.context("Failed to create cookie file")?;
181184
file.write_all(cookie.as_bytes())
@@ -227,3 +230,12 @@ async fn wait_for_auth_cookie(page: &Page) -> Result<Cookie> {
227230
tokio::time::sleep(POLL_INTERVAL).await;
228231
}
229232
}
233+
234+
fn ensure_directory_exists(file_path: &str) -> Result<()> {
235+
if let Some(parent) = std::path::Path::new(file_path).parent() {
236+
std::fs::create_dir_all(parent)
237+
.with_context(|| format!("Failed to create directories for {file_path}"))?;
238+
}
239+
240+
Ok(())
241+
}

0 commit comments

Comments
 (0)