Handle relative path case

This commit is contained in:
Johan Sigfrids 2018-08-05 08:59:56 +03:00
parent 9be5e640ff
commit 883357a7dd

View file

@ -322,7 +322,7 @@ fn is_temp_file(path: &Path) -> bool {
/// to be reloaded /// to be reloaded
fn detect_change_kind(pwd: &Path, path: &Path) -> (ChangeKind, PathBuf) { fn detect_change_kind(pwd: &Path, path: &Path) -> (ChangeKind, PathBuf) {
let mut partial_path = PathBuf::from("/"); let mut partial_path = PathBuf::from("/");
partial_path.push(path.strip_prefix(pwd).unwrap()); partial_path.push(path.strip_prefix(pwd).unwrap_or(path));
let change_kind = if partial_path.starts_with("/templates") { let change_kind = if partial_path.starts_with("/templates") {
ChangeKind::Templates ChangeKind::Templates
@ -396,7 +396,6 @@ mod tests {
} }
} }
#[test] #[test]
#[cfg(windows)] #[cfg(windows)]
fn windows_path_handling() { fn windows_path_handling() {
@ -406,4 +405,11 @@ mod tests {
assert_eq!(expected, detect_change_kind(pwd, path)); assert_eq!(expected, detect_change_kind(pwd, path));
} }
#[test]
fn relative_path() {
let expected = (ChangeKind::Templates, PathBuf::from("/templates/hello.html"));
let pwd = Path::new("/home/johan/site");
let path = Path::new("templates/hello.html");
assert_eq!(expected, detect_change_kind(pwd, path));
}
} }