Skip to content

Commit

Permalink
Fix file watcher notifier being dropped.
Browse files Browse the repository at this point in the history
  • Loading branch information
hardiesoft committed Oct 13, 2024
1 parent 126207e commit f6c8797
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions src/save_cptv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,20 @@ pub fn save_cptv_file_to_disk(cptv_bytes: Vec<u8>, output_dir: &str) {
);
let decoder = MultiGzDecoder::new(&cptv_bytes[..]);
let mut encoder = GzEncoder::new(decoder, Compression::default());
let mut cptv_bytes = Vec::new();
encoder.read_to_end(&mut cptv_bytes).unwrap();
let mut new_cptv_bytes = Vec::new();
encoder.read_to_end(&mut new_cptv_bytes).unwrap();

// Only use the re-compressed file if it actually got smaller.
if new_cptv_bytes.len() > cptv_bytes.len() {
new_cptv_bytes = cptv_bytes;
}
// If the file already exists, don't re-save it.
let is_existing_file = match fs::metadata(&path) {
Ok(metadata) => metadata.len() as usize == cptv_bytes.len(),
Ok(metadata) => metadata.len() as usize == new_cptv_bytes.len(),
Err(_) => false,
};
if !is_existing_file {
match fs::write(&path, &cptv_bytes) {
match fs::write(&path, &new_cptv_bytes) {
Ok(()) => {
info!("Saved CPTV file {}", path);
}
Expand Down

0 comments on commit f6c8797

Please sign in to comment.