Now canonicalizing paths.

This commit is contained in:
Filipe Rodrigues 2021-12-30 02:59:15 +00:00
parent 28f5d77ebf
commit f9c55c92f3
2 changed files with 18 additions and 1 deletions

2
run.sh
View File

@ -8,7 +8,7 @@ cargo run -- \
--window-geometry "3280x1080+0+0" \
--image-geometry "1920x1080+1360+0" \
--fade-point 0.8 \
--image-backlog 1 \
--image-backlog 4 \
--image-loader-args "image-loader-args.json"
# "1360x768+0+312"

View File

@ -179,11 +179,16 @@ fn handle_fs_event(event: notify::DebouncedEvent, _base_path: &Path, paths: &mut
match event {
// Add the path
notify::DebouncedEvent::Create(path) => {
// Canonicalize the path
let path = self::try_canonicalize(path);
log::debug!("Adding {path:?}");
paths.push(Arc::new(path));
},
// Replace the path
notify::DebouncedEvent::Rename(old_path, new_path) => {
let old_path = self::try_canonicalize(old_path);
let new_path = self::try_canonicalize(new_path);
log::debug!("Renaming {old_path:?} to {new_path:?}");
for path in paths {
if **path == old_path {
@ -194,6 +199,7 @@ fn handle_fs_event(event: notify::DebouncedEvent, _base_path: &Path, paths: &mut
},
// Remove the path
notify::DebouncedEvent::Remove(path_to_remove) => {
let path_to_remove = self::try_canonicalize(path_to_remove);
log::debug!("Removing {path_to_remove:?}");
paths.retain(|path| **path != path_to_remove);
},
@ -216,6 +222,17 @@ fn handle_fs_event(event: notify::DebouncedEvent, _base_path: &Path, paths: &mut
}
}
/// Tries to canonicalize a path
fn try_canonicalize(path: PathBuf) -> PathBuf {
match path.canonicalize() {
Ok(path) => path,
Err(err) => {
log::warn!("Unable to canonicalize {path:?}: {:?}", anyhow::anyhow!(err));
path
},
}
}
/// Loads all paths from `base_path` and sends them to `fs_tx`
fn load_paths(base_path: &Path, fs_tx: &mpsc::Sender<notify::DebouncedEvent>) {
let mut paths_loaded = 0;