fix(windows): wrong prefix config file path (`\\?\`) when logged
Diff
src/helpers.rs | 19 +++++++++++++++++++
src/server.rs | 7 ++++---
src/winservice.rs | 15 ++-------------
3 files changed, 25 insertions(+), 16 deletions(-)
@@ -72,3 +72,22 @@ pub fn stringify(dst: &mut String, path: &serde_ignored::Path<'_>) {
| Path::NewtypeStruct { parent } => stringify(dst, parent),
}
}
#[cfg(unix)]
pub fn adjust_canonicalization(p: PathBuf) -> String {
p.display().to_string()
}
#[cfg(windows)]
pub fn adjust_canonicalization(p: PathBuf) -> String {
const VERBATIM_PREFIX: &str = r#"\\?\"#;
let p = p.to_str().unwrap_or_default();
let p = if p.starts_with(VERBATIM_PREFIX) {
p.strip_prefix(VERBATIM_PREFIX).unwrap_or_default()
} else {
p
};
p.to_owned()
}
@@ -83,9 +83,10 @@ impl Server {
let advanced_opts = self.opts.advanced;
if general.config_file.is_some() && general.config_file.is_some() {
tracing::info!("config file: {}", general.config_file.unwrap().display());
if let Some(config_file) = general.config_file {
let config_file = helpers::adjust_canonicalization(config_file);
tracing::info!("config file: {}", config_file);
}
@@ -16,7 +16,7 @@ use windows_service::{
service_manager::{ServiceManager, ServiceManagerAccess},
};
use crate::{logger, Context, Result, Server, Settings};
use crate::{helpers, logger, Context, Result, Server, Settings};
const SERVICE_NAME: &str = "static-web-server";
const SERVICE_TYPE: ServiceType = ServiceType::OWN_PROCESS;
@@ -167,17 +167,6 @@ pub fn run_server_as_service() -> Result {
Ok(())
}
fn adjust_canonicalization(p: PathBuf) -> String {
const VERBATIM_PREFIX: &str = r#"\\?\"#;
let p = p.to_str().unwrap_or_default();
let p = if p.starts_with(VERBATIM_PREFIX) {
p.strip_prefix(VERBATIM_PREFIX).unwrap_or_default()
} else {
p
};
p.to_owned()
}
pub fn install_service(config_file: Option<PathBuf>) -> Result {
let manager_access = ServiceManagerAccess::CONNECT | ServiceManagerAccess::CREATE_SERVICE;
@@ -191,7 +180,7 @@ pub fn install_service(config_file: Option<PathBuf>) -> Result {
if let Some(f) = config_file {
let f = adjust_canonicalization(f);
let f = helpers::adjust_canonicalization(f);
if !f.is_empty() {
service_binary_arguments.push(OsString::from(["--config-file=", &f].concat()));
}