From 0fb4624e58c548ef83ff6c2ab9b685faaf317c2f Mon Sep 17 00:00:00 2001 From: Oliver Hamlet Date: Mon, 28 Apr 2025 17:45:56 +0100 Subject: [PATCH] Write paths in logs as escaped ASCII text --- src/archive/parse.rs | 7 ++++--- src/game.rs | 17 +++++++++-------- src/metadata/metadata_document.rs | 14 +++++++------- src/plugin/mod.rs | 6 +++--- 4 files changed, 23 insertions(+), 21 deletions(-) diff --git a/src/archive/parse.rs b/src/archive/parse.rs index 0ffb8255..49e4538a 100644 --- a/src/archive/parse.rs +++ b/src/archive/parse.rs @@ -8,6 +8,7 @@ use std::{ use super::error::{ArchiveParsingError, ArchivePathParsingError}; use crate::{ archive::error::slice_too_small, + escape_ascii, logging::{self, format_details}, plugin::has_ascii_extension, }; @@ -20,7 +21,7 @@ pub fn assets_in_archives(archive_paths: &[PathBuf]) -> BTreeMap BTreeMap { logging::error!( "Encountered an error while trying to read the Bethesda archive at \"{}\": {}", - archive_path.display(), + escape_ascii(archive_path), format_details(&e) ); continue; @@ -46,7 +47,7 @@ pub fn assets_in_archives(archive_paths: &[PathBuf]) -> BTreeMap Result { logging::info!( - "Attempting to create a game handle for game type \"{}\" with game path {:?}", + "Attempting to create a game handle for game type \"{}\" with game path \"{}\"", game_type, - game_path + escape_ascii(game_path) ); let resolved_game_path = resolve_path(game_path); @@ -197,10 +198,10 @@ impl Game { game_local_path: &Path, ) -> Result { logging::info!( - "Attempting to create a game handle for game type \"{}\" with game path {:?} and game local path {:?}", + "Attempting to create a game handle for game type \"{}\" with game path \"{}\" and game local path \"{}\"", game_type, - game_path, - game_local_path + escape_ascii(game_path), + escape_ascii(game_local_path) ); let resolved_game_path = resolve_path(game_path); @@ -671,7 +672,7 @@ fn try_load_plugin( Err(e) => { logging::error!( "Caught error while trying to load \"{}\": {}", - plugin_path.display(), + escape_ascii(plugin_path), format_details(&e) ); None @@ -685,8 +686,8 @@ fn resolve_plugin_path(game_type: GameType, data_path: &Path, plugin_path: &Path if game_type != GameType::OpenMW && !plugin_path.exists() { if let Some(filename) = plugin_path.file_name() { logging::debug!( - "Could not find plugin at {}, adding {} file extension", - plugin_path.display(), + "Could not find plugin at \"{}\", adding {} file extension", + escape_ascii(&plugin_path), GHOST_FILE_EXTENSION ); let mut filename = filename.to_os_string(); diff --git a/src/metadata/metadata_document.rs b/src/metadata/metadata_document.rs index 72705097..d1b11629 100644 --- a/src/metadata/metadata_document.rs +++ b/src/metadata/metadata_document.rs @@ -5,7 +5,7 @@ use std::{ use saphyr::{LoadableYamlNode, MarkedYaml, YamlData}; -use crate::logging; +use crate::{escape_ascii, logging}; use super::{ error::{ @@ -37,7 +37,7 @@ impl MetadataDocument { )); } - logging::trace!("Loading file: {:?}", file_path); + logging::trace!("Loading file at \"{}\"", escape_ascii(file_path)); let content = std::fs::read_to_string(file_path) .map_err(|e| LoadMetadataError::from_io_error(file_path.into(), e))?; @@ -46,8 +46,8 @@ impl MetadataDocument { .map_err(|e| LoadMetadataError::new(file_path.into(), e))?; logging::trace!( - "Successfully loaded metadata from file at \"{:?}\".", - file_path + "Successfully loaded metadata from file at \"{}\".", + escape_ascii(file_path) ); Ok(()) @@ -84,8 +84,8 @@ impl MetadataDocument { .map_err(|e| LoadMetadataError::new(masterlist_path.into(), e))?; logging::trace!( - "Successfully loaded metadata from file at \"{:?}\".", - masterlist_path + "Successfully loaded metadata from file at \"{}\".", + escape_ascii(masterlist_path) ); Ok(()) @@ -198,7 +198,7 @@ impl MetadataDocument { } pub fn save(&self, file_path: &Path) -> Result<(), WriteMetadataError> { - logging::trace!("Saving metadata list to: {}", file_path.display()); + logging::trace!("Saving metadata list to: \"{}\"", escape_ascii(file_path)); let mut emitter = YamlEmitter::new(); diff --git a/src/plugin/mod.rs b/src/plugin/mod.rs index 778e5924..3cff3a2e 100644 --- a/src/plugin/mod.rs +++ b/src/plugin/mod.rs @@ -15,7 +15,7 @@ use fancy_regex::{Error as RegexImplError, Regex}; use crate::{ GameType, archive::{assets_in_archives, do_assets_overlap, find_associated_archives}, - case_insensitive_regex, + case_insensitive_regex, escape_ascii, game::GameCache, logging, metadata::plugin_metadata::trim_dot_ghost, @@ -289,7 +289,7 @@ pub(crate) fn validate_plugin_path_and_header( } else if !has_plugin_file_extension(game_type, plugin_path) { logging::debug!( "The file \"{}\" is not a valid plugin", - plugin_path.display() + escape_ascii(plugin_path) ); Err(PluginValidationError::invalid( plugin_path.into(), @@ -301,7 +301,7 @@ pub(crate) fn validate_plugin_path_and_header( } else { logging::debug!( "The file \"{}\" is not a valid plugin", - plugin_path.display() + escape_ascii(plugin_path) ); Err(PluginValidationError::new( plugin_path.into(),