diff options
| author | Laurenz <laurmaedje@gmail.com> | 2023-06-08 10:14:47 +0200 |
|---|---|---|
| committer | Laurenz <laurmaedje@gmail.com> | 2023-06-08 10:16:58 +0200 |
| commit | 4e5cc61599e58b93ea67a7ebd4e5da8550e571e0 (patch) | |
| tree | 1058cd7e2bf9f6f923815cb2bfd19490c0ad2591 /cli | |
| parent | c87f802cf60b7ae5dfdca9ccfa011c5105d9947b (diff) | |
Watch root and parent directory
Fixes #1436
Diffstat (limited to 'cli')
| -rw-r--r-- | cli/src/main.rs | 29 |
1 files changed, 17 insertions, 12 deletions
diff --git a/cli/src/main.rs b/cli/src/main.rs index 9756c168..17817655 100644 --- a/cli/src/main.rs +++ b/cli/src/main.rs @@ -199,22 +199,20 @@ impl FontsSettings { /// Execute a compilation command. fn compile(mut command: CompileSettings) -> StrResult<()> { - let root = if let Some(root) = &command.root { - root.clone() - } else if let Some(dir) = command + // Determine the parent directory of the input file. + let parent = command .input .canonicalize() .ok() .as_ref() .and_then(|path| path.parent()) - { - dir.into() - } else { - PathBuf::new() - }; + .unwrap_or(Path::new(".")) + .to_owned(); + + let root = command.root.as_ref().unwrap_or(&parent); // Create the world that serves sources, fonts and files. - let mut world = SystemWorld::new(root, &command.font_paths); + let mut world = SystemWorld::new(root.into(), &command.font_paths); // Perform initial compilation. let ok = compile_once(&mut world, &command)?; @@ -236,10 +234,17 @@ fn compile(mut command: CompileSettings) -> StrResult<()> { let mut watcher = RecommendedWatcher::new(tx, notify::Config::default()) .map_err(|_| "failed to watch directory")?; - // Watch root directory recursively. + // Watch the input file's parent directory recursively. watcher - .watch(&world.root, RecursiveMode::Recursive) - .map_err(|_| "failed to watch directory")?; + .watch(&parent, RecursiveMode::Recursive) + .map_err(|_| "failed to watch parent directory")?; + + // Watch the root directory recursively. + if world.root != parent { + watcher + .watch(&world.root, RecursiveMode::Recursive) + .map_err(|_| "failed to watch root directory")?; + } // Handle events. let timeout = std::time::Duration::from_millis(100); |
