From b965247880485493a21db46a0bef3cc0941edbbc Mon Sep 17 00:00:00 2001 From: glendc Date: Thu, 14 Nov 2024 19:57:14 +0100 Subject: [PATCH] fix sslkeylog canonicalize: seems to require the path to exist... --- rama-tls/src/keylog.rs | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/rama-tls/src/keylog.rs b/rama-tls/src/keylog.rs index a80b9c18..0a860c45 100644 --- a/rama-tls/src/keylog.rs +++ b/rama-tls/src/keylog.rs @@ -22,7 +22,17 @@ use std::{ /// Paths are case-sensitive by default for rama, as utf-8 compatible. /// Normalize yourself prior to passing a path to this function if you're concerned. pub fn new_key_log_file_handle(path: String) -> Result { - let path = std::fs::canonicalize(path).context("canonicalize keylog path")?; + let path: PathBuf = path + .parse() + .with_context(|| format!("parse path str as Path: {path}"))?; + + if let Some(parent) = path.parent() { + std::fs::create_dir_all(parent) + .with_context(|| format!("create parent dir(s) at {parent:?} for key log file"))?; + } + + let path = std::fs::canonicalize(&path) + .with_context(|| format!("canonicalize keylog path: {path:?}"))?; let mapping = GLOBAL_KEY_LOG_FILE_MAPPING.get_or_init(Default::default); if let Some(handle) = mapping.read().get(&path).cloned() {