Skip to content

Commit 722c55f

Browse files
committed
normalize path to relative
1 parent 3ab19f3 commit 722c55f

File tree

3 files changed

+12
-4
lines changed

3 files changed

+12
-4
lines changed

Cargo.lock

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ log = "0.4.17"
2828
memchr = "2.5.0"
2929
opener = "0.6.1"
3030
pulldown-cmark = { version = "0.9.3", default-features = false }
31+
pathdiff = "0.2.1"
3132
regex = "1.8.1"
3233
serde = { version = "1.0.163", features = ["derive"] }
3334
serde_json = "1.0.96"

src/cmd/watch.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ use ignore::gitignore::Gitignore;
44
use mdbook::errors::Result;
55
use mdbook::utils;
66
use mdbook::MDBook;
7+
use pathdiff::diff_paths;
78
use std::env;
89
use std::path::{Path, PathBuf};
910
use std::sync::mpsc::channel;
@@ -93,11 +94,10 @@ fn filter_ignored_files(ignore: Gitignore, paths: &[PathBuf]) -> Vec<PathBuf> {
9394
paths
9495
.iter()
9596
.filter(|path| {
96-
let normalized_path = path
97-
.strip_prefix(&current_dir)
98-
.expect("Could not normalize path");
97+
let relative_path =
98+
diff_paths(&current_dir, &path).expect("One of the paths should be an absolute");
9999
!ignore
100-
.matched_path_or_any_parents(normalized_path, normalized_path.is_dir())
100+
.matched_path_or_any_parents(&relative_path, relative_path.is_dir())
101101
.is_ignore()
102102
})
103103
.map(|path| path.to_path_buf())

0 commit comments

Comments
 (0)