Remove and replace deleted or moved thumbnails
All checks were successful
Core Repos/ImageApi/pipeline/head This commit looks good

This commit is contained in:
Cameron Cordes
2021-03-17 22:30:27 -04:00
parent a2a9c27f12
commit 1539255ae0

View File

@@ -326,7 +326,30 @@ fn main() -> std::io::Result<()> {
let ev = wrx.recv(); let ev = wrx.recv();
if let Ok(event) = ev { if let Ok(event) = ev {
match event { match event {
DebouncedEvent::Create(_) | DebouncedEvent::Rename(_, _) => create_thumbnails(), DebouncedEvent::Create(_) => create_thumbnails(),
DebouncedEvent::Rename(orig, _) | DebouncedEvent::Write(orig) => {
let image_base_path = PathBuf::from(env::var("BASE_PATH").unwrap());
let image_relative = orig.strip_prefix(&image_base_path).unwrap();
if let Ok(old_thumbnail) = env::var("THUMBNAILS")
.map(|base| PathBuf::from(base))
.map(|mut base| {
base.push(image_relative);
base
})
{
if let Err(e) = std::fs::remove_file(&old_thumbnail) {
error!(
"Error removing thumbnail: {}\n{}",
old_thumbnail.display(),
e
);
} else {
info!("Deleted moved thumbnail: {}", old_thumbnail.display());
create_thumbnails();
}
}
}
_ => continue, _ => continue,
}; };
} }