Remove and replace deleted or moved thumbnails
All checks were successful
Core Repos/ImageApi/pipeline/head This commit looks good
All checks were successful
Core Repos/ImageApi/pipeline/head This commit looks good
This commit is contained in:
25
src/main.rs
25
src/main.rs
@@ -326,7 +326,30 @@ fn main() -> std::io::Result<()> {
|
||||
let ev = wrx.recv();
|
||||
if let Ok(event) = ev {
|
||||
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,
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user