Browse Source

Handle relative path case

index-subcmd
Johan Sigfrids 6 years ago
parent
commit
883357a7dd
1 changed files with 8 additions and 2 deletions
  1. +8
    -2
      src/cmd/serve.rs

+ 8
- 2
src/cmd/serve.rs 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));
}
} }

Loading…
Cancel
Save