diff --git a/src/main.rs b/src/main.rs index db1e329..2f73e3a 100644 --- a/src/main.rs +++ b/src/main.rs @@ -83,14 +83,20 @@ fn main() -> Result<(), Error> { if d.0 == w { wch = true; } - } else { wch = true; } + } else { + wch = true; + } if let Some(h) = args.height.clone() { if d.1 == h { hch = true; } - } else { hch = true; } + } else { + hch = true; + } + } + if wch && hch { + chk = false; } - if wch && hch { chk = false; } } p } else { @@ -101,32 +107,28 @@ fn main() -> Result<(), Error> { if let Some(out) = args.out.to_owned() { // TODO: setup a constant size buffer and read/write that many bytes at a time to prevent // locking up large amounts of system ram running on a large file. - let mut contents; - { - // open readfile after this line + let contents = { + let mut c; let mut f = OpenOptions::new() .read(true) .open(&pick) .expect("unable to open readfile"); let m = metadata(&pick).expect("unable to read metadata"); - contents = vec![0; m.len() as usize]; - f.read(&mut contents).expect("buffer overflow"); - } // readfile closes here due to falling out of scope - let contents = contents; // remove mutability + c = vec![0; m.len() as usize]; + f.read(&mut c).expect("buffer overflow"); + c + }; { - // open outfile after this line let mut f = OpenOptions::new() .write(true) .create(true) .open(out.as_str()) .expect("unable to open outfile"); - f.set_len(0u64).expect("unable to truncate file"); // just call ftruncate() on the poor - // thing + f.set_len(0u64).expect("unable to truncate file"); f.write_all(&contents).expect("unable to write to outfile"); - f.flush().expect( - "unable to flush outfile (if this happens something has gone *terribly* wrong)", - ); - } // outfile closes here due to falling out of scope + f.flush() + .expect("unable to flush outfile (something has gone comically wrong)"); + } } else { println!("{}", pick.display()); }