diff --git a/Cargo.lock b/Cargo.lock index 2346f5b9b2..664e523031 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -974,6 +974,7 @@ dependencies = [ "notify-debouncer-mini", "once_cell", "opener", + "pathdiff", "predicates", "pretty_assertions", "pulldown-cmark", @@ -1151,6 +1152,12 @@ dependencies = [ "windows-targets 0.48.1", ] +[[package]] +name = "pathdiff" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8835116a5c179084a830efb3adc117ab007512b535bc1a21c991d3b32a6b44dd" + [[package]] name = "percent-encoding" version = "2.3.0" diff --git a/Cargo.toml b/Cargo.toml index 9f93cf08f6..033fcbd62d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -28,6 +28,7 @@ log = "0.4.17" memchr = "2.5.0" opener = "0.6.1" pulldown-cmark = { version = "0.9.3", default-features = false } +pathdiff = "0.2.1" regex = "1.8.1" serde = { version = "1.0.163", features = ["derive"] } serde_json = "1.0.96" diff --git a/src/cmd/watch.rs b/src/cmd/watch.rs index 271af265d9..d112a75f15 100644 --- a/src/cmd/watch.rs +++ b/src/cmd/watch.rs @@ -4,6 +4,7 @@ use ignore::gitignore::Gitignore; use mdbook::errors::Result; use mdbook::utils; use mdbook::MDBook; +use pathdiff::diff_paths; use std::env; use std::path::{Path, PathBuf}; use std::sync::mpsc::channel; @@ -93,11 +94,10 @@ fn filter_ignored_files(ignore: Gitignore, paths: &[PathBuf]) -> Vec { paths .iter() .filter(|path| { - let normalized_path = path - .strip_prefix(¤t_dir) - .expect("Could not normalize path"); + let relative_path = + diff_paths(¤t_dir, &path).expect("One of the paths should be an absolute"); !ignore - .matched_path_or_any_parents(normalized_path, normalized_path.is_dir()) + .matched_path_or_any_parents(&relative_path, relative_path.is_dir()) .is_ignore() }) .map(|path| path.to_path_buf())