From fc17b63b344d1a8965cedc296c45308f343eb4b8 Mon Sep 17 00:00:00 2001 From: HJfod <60038575+HJfod@users.noreply.github.com> Date: Fri, 27 Jan 2023 14:28:47 +0200 Subject: [PATCH] make sure relative input dirs get normalized --- Cargo.toml | 2 +- src/cmake.rs | 2 +- src/config.rs | 6 +++--- src/main.rs | 1 + src/normalize.rs | 21 +++++++++++++++++++++ src/url.rs | 1 - 6 files changed, 27 insertions(+), 6 deletions(-) create mode 100644 src/normalize.rs diff --git a/Cargo.toml b/Cargo.toml index 8f6f0f5..3da00cb 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "flash" -version = "0.1.2" +version = "0.1.3" edition = "2021" authors = ["HJfod"] description = "Documentation generator for C++" diff --git a/src/cmake.rs b/src/cmake.rs index 770fb07..798cb12 100644 --- a/src/cmake.rs +++ b/src/cmake.rs @@ -100,5 +100,5 @@ pub fn cmake_compile_args_for(config: Arc) -> Result, String return Ok(cmd.get_command_list(config)); } } - Err(format!("Unable to find compile args for '{}'", from.to_string_lossy())) + Err(format!("Unable to find compile args for '{}'", config.input_dir.join(from).to_string_lossy())) } diff --git a/src/config.rs b/src/config.rs index eec361d..d22e7fb 100644 --- a/src/config.rs +++ b/src/config.rs @@ -3,7 +3,7 @@ use glob::glob; use serde::{Deserialize, Deserializer}; use std::{fs, path::PathBuf, sync::Arc}; -use crate::url::UrlPath; +use crate::{url::UrlPath, normalize::Normalize}; fn parse_template<'de, D>(deserializer: D) -> Result, D::Error> where @@ -161,8 +161,8 @@ impl Config { ) .map_err(|e| format!("Unable to parse config: {e}"))?; - config.input_dir = input_dir; - config.output_dir = output_dir; + config.input_dir = input_dir.normalize(); + config.output_dir = output_dir.normalize(); config.output_url = output_url; Ok(Arc::from(config)) } diff --git a/src/main.rs b/src/main.rs index d6fb3d0..87ed873 100644 --- a/src/main.rs +++ b/src/main.rs @@ -14,6 +14,7 @@ mod cmake; mod config; mod html; mod url; +mod normalize; #[derive(Parser, Debug)] struct Args { diff --git a/src/normalize.rs b/src/normalize.rs new file mode 100644 index 0000000..99d4f21 --- /dev/null +++ b/src/normalize.rs @@ -0,0 +1,21 @@ + +use std::path::{PathBuf, Component}; + +pub trait Normalize { + fn normalize(&self) -> Self; +} + +impl Normalize for PathBuf { + fn normalize(&self) -> Self { + let mut res = Self::new(); + for comp in self.components() { + if comp == Component::ParentDir { + res.pop(); + } + else { + res.push(comp); + } + } + res + } +} diff --git a/src/url.rs b/src/url.rs index 7d48c67..469054c 100644 --- a/src/url.rs +++ b/src/url.rs @@ -223,7 +223,6 @@ impl TryFrom<&str> for UrlPath { impl TryFrom for UrlPath { type Error = String; - fn try_from(value: String) -> Result { UrlPath::parse(&value) }