Skip to content

Commit

Permalink
normalize path to relative
Browse files Browse the repository at this point in the history
  • Loading branch information
leonzchang committed Nov 1, 2023
1 parent 3ab19f3 commit 722c55f
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 4 deletions.
7 changes: 7 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
8 changes: 4 additions & 4 deletions 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 pathdiff::diff_paths;
use std::env;
use std::path::{Path, PathBuf};
use std::sync::mpsc::channel;
Expand Down Expand Up @@ -93,11 +94,10 @@ fn filter_ignored_files(ignore: Gitignore, paths: &[PathBuf]) -> Vec<PathBuf> {
paths
.iter()
.filter(|path| {
let normalized_path = path
.strip_prefix(&current_dir)
.expect("Could not normalize path");
let relative_path =
diff_paths(&current_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())
Expand Down

0 comments on commit 722c55f

Please sign in to comment.