From abedfc9c70242ed09934682f3fc56a4af4246ffb Mon Sep 17 00:00:00 2001 From: Joshua Holmer Date: Thu, 3 Mar 2016 16:30:05 -0500 Subject: [PATCH] Each input file should output to its own file correctly Fixes #15 --- src/lib.rs | 1 + src/main.rs | 19 ++++++++++--------- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index f4f5e5aa..cc366ef8 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -16,6 +16,7 @@ pub mod deflate { } pub mod png; +#[derive(Clone,Debug)] pub struct Options { pub backup: bool, pub out_file: PathBuf, diff --git a/src/main.rs b/src/main.rs index 1e387df7..7a83a635 100644 --- a/src/main.rs +++ b/src/main.rs @@ -230,26 +230,27 @@ fn main() { .iter() .map(PathBuf::from) .collect(), - &mut opts); + opts); } -fn handle_optimization(inputs: Vec, opts: &mut oxipng::Options) { +fn handle_optimization(inputs: Vec, opts: oxipng::Options) { for input in inputs { + let mut current_opts = opts.clone(); if input.is_dir() { - if opts.recursive { + if current_opts.recursive { handle_optimization(input.read_dir().unwrap().map(|x| x.unwrap().path()).collect(), - opts) + current_opts) } else { println!("{} is a directory, skipping", input.display()); } continue; } - if let Some(out_dir) = opts.out_dir.clone() { - opts.out_file = out_dir.join(input.file_name().unwrap()); - } else if opts.out_file.components().count() == 0 { - opts.out_file = input.clone(); + if let Some(out_dir) = current_opts.out_dir.clone() { + current_opts.out_file = out_dir.join(input.file_name().unwrap()); + } else if current_opts.out_file.components().count() == 0 { + current_opts.out_file = input.clone(); } - match oxipng::optimize(&input, opts) { + match oxipng::optimize(&input, ¤t_opts) { Ok(_) => (), Err(x) => println!("{}", x), };