From fbb629c02e78821a24ccf9c1a6afb82057da4bf6 Mon Sep 17 00:00:00 2001 From: leonzchang Date: Tue, 31 Oct 2023 12:13:25 +0800 Subject: [PATCH] normalize path in watch cmd --- src/cmd/watch.rs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/cmd/watch.rs b/src/cmd/watch.rs index 9fd5085d..271af265 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 std::env; use std::path::{Path, PathBuf}; use std::sync::mpsc::channel; use std::thread::sleep; @@ -87,11 +88,16 @@ fn find_gitignore(book_root: &Path) -> Option { } fn filter_ignored_files(ignore: Gitignore, paths: &[PathBuf]) -> Vec { + let current_dir = env::current_dir().expect("Unable to determine the current directory"); + paths .iter() .filter(|path| { + let normalized_path = path + .strip_prefix(¤t_dir) + .expect("Could not normalize path"); !ignore - .matched_path_or_any_parents(path, path.is_dir()) + .matched_path_or_any_parents(normalized_path, normalized_path.is_dir()) .is_ignore() }) .map(|path| path.to_path_buf())