Skip to content

Commit

Permalink
normalize path in watch cmd
Browse files Browse the repository at this point in the history
  • Loading branch information
leonzchang committed Oct 31, 2023
1 parent 94e0a44 commit fbb629c
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/cmd/watch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -87,11 +88,16 @@ fn find_gitignore(book_root: &Path) -> Option<PathBuf> {
}

fn filter_ignored_files(ignore: Gitignore, paths: &[PathBuf]) -> Vec<PathBuf> {
let current_dir = env::current_dir().expect("Unable to determine the current directory");

paths
.iter()
.filter(|path| {
let normalized_path = path
.strip_prefix(&current_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())
Expand Down

0 comments on commit fbb629c

Please sign in to comment.