From 41732a335e2b5622c5434bfeee0ff3ee0ab11223 Mon Sep 17 00:00:00 2001 From: glendc Date: Thu, 14 Nov 2024 20:15:19 +0100 Subject: [PATCH] replace std::fs::canonicalize with cargo-internal fn --- rama-tls/src/keylog.rs | 34 +++++++++++++++++++++++++++++++--- 1 file changed, 31 insertions(+), 3 deletions(-) diff --git a/rama-tls/src/keylog.rs b/rama-tls/src/keylog.rs index 0a860c45..027e5cb3 100644 --- a/rama-tls/src/keylog.rs +++ b/rama-tls/src/keylog.rs @@ -10,7 +10,7 @@ use std::{ collections::{hash_map::Entry, HashMap}, fs::OpenOptions, io::Write, - path::PathBuf, + path::{Component, Path, PathBuf}, sync::OnceLock, }; @@ -31,8 +31,7 @@ pub fn new_key_log_file_handle(path: String) -> Result Result +pub fn normalize_path(path: &Path) -> PathBuf { + let mut components = path.components().peekable(); + let mut ret = if let Some(c @ Component::Prefix(..)) = components.peek().cloned() { + components.next(); + PathBuf::from(c.as_os_str()) + } else { + PathBuf::new() + }; + + for component in components { + match component { + Component::Prefix(..) => unreachable!(), + Component::RootDir => { + ret.push(component.as_os_str()); + } + Component::CurDir => {} + Component::ParentDir => { + ret.pop(); + } + Component::Normal(c) => { + ret.push(c); + } + } + } + ret +} + fn try_init_key_log_file_handle(path: PathBuf) -> Result { tracing::trace!( file = ?path,