From fac83c023dd42d0277ad82e92a33bfc230ddf572 Mon Sep 17 00:00:00 2001 From: Joshua Holmer Date: Fri, 22 Apr 2016 13:31:33 -0400 Subject: [PATCH] Fix issue where output directory would not be created if it did not exist --- CHANGELOG.md | 3 +++ src/main.rs | 8 +++++++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c85e817a..e2a139ec 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,6 @@ +**Version 0.5.1 (unreleased)** + - Fix issue where output directory would not be created if it did not exist + **Version 0.5.0** - [SEMVER_MINOR] Palette entries can now reduced, on by default ([#11](https://github.com/shssoichiro/oxipng/issues/11)) - Don't report that we are in pretend mode if verbosity is set to none diff --git a/src/main.rs b/src/main.rs index 9eb0bf11..23d6a83d 100644 --- a/src/main.rs +++ b/src/main.rs @@ -6,6 +6,7 @@ use clap::{App, Arg, ArgMatches}; use oxipng::png; use regex::Regex; use std::collections::HashSet; +use std::fs::DirBuilder; use std::io::{Write, stderr}; use std::path::PathBuf; @@ -410,7 +411,12 @@ fn parse_opts_into_struct(matches: &ArgMatches, opts: &mut oxipng::Options) -> R if let Some(x) = matches.value_of("output_dir") { let path = PathBuf::from(x); if !path.exists() { - + match DirBuilder::new() + .recursive(true) + .create(&path) { + Ok(_) => (), + Err(x) => return Err(format!("Could not create output directory {}", x)), + }; } else if !path.is_dir() { return Err(format!("{} is an existing file (not a directory), cannot create directory", x));