summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichael Aaron Murphy <mmstickman@gmail.com>2017-01-16 13:15:22 -0500
committerMichael Aaron Murphy <mmstickman@gmail.com>2017-01-16 13:17:47 -0500
commit0a0980e39801f36cfc888815ace4e9f72ba37312 (patch)
tree577f1c3750bf940f8bfd399fb1317fce971aa4b7
parentc25d34a14cbabf81d719a24dd574be02a6c854d2 (diff)
0.10.4: Create the tempdir if it does not exist0.10.4
- Prevents an error during parsing
-rw-r--r--Cargo.lock2
-rw-r--r--Cargo.toml2
-rw-r--r--src/arguments/mod.rs12
-rw-r--r--src/main.rs13
4 files changed, 22 insertions, 7 deletions
diff --git a/Cargo.lock b/Cargo.lock
index 3fdd9c0..c2d26d6 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -1,6 +1,6 @@
[root]
name = "parallel"
-version = "0.10.3"
+version = "0.10.4"
dependencies = [
"arrayvec 0.3.20 (registry+https://github.com/rust-lang/crates.io-index)",
"itoa 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
diff --git a/Cargo.toml b/Cargo.toml
index cdbbc7d..d5f25e2 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -1,6 +1,6 @@
[package]
name = "parallel"
-version = "0.10.3"
+version = "0.10.4"
authors = ["Michael Aaron Murphy <mmstickman@gmail.com>"]
license = "MIT"
description = "Command-line CPU load balancer for executing jobs in parallel"
diff --git a/src/arguments/mod.rs b/src/arguments/mod.rs
index 8e6468a..e3f05a0 100644
--- a/src/arguments/mod.rs
+++ b/src/arguments/mod.rs
@@ -5,7 +5,7 @@ mod man;
mod redirection;
use std::env;
-use std::fs;
+use std::fs::{self, create_dir_all};
use std::io::{self, BufRead, BufReader, BufWriter, Write};
use std::num::ParseIntError;
use std::path::{Path, PathBuf};
@@ -174,12 +174,20 @@ impl Args {
},
"verbose" => self.flags |= VERBOSE_MODE,
"version" => {
- println!("MIT/Rust Parallel 0.10.3\n");
+ println!("MIT/Rust Parallel 0.10.4\n");
exit(0);
},
"tmpdir" | "tempdir" => {
*base_path = PathBuf::from(arguments.get(index).ok_or(ParseErr::WorkDirNoValue)?);
index += 1;
+
+ // Create the base directory if it does not exist
+ if let Err(why) = create_dir_all(base_path.as_path()) {
+ let stderr = io::stderr();
+ let stderr = &mut stderr.lock();
+ let _ = writeln!(stderr, "parallel: unable to create tempdir {:?}: {}", base_path.as_path(), why);
+ exit(1);
+ }
}
_ if &argument[2..9] == "shebang" => {
shebang = true;
diff --git a/src/main.rs b/src/main.rs
index 095e0bb..79adc10 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -23,7 +23,7 @@ mod shell;
mod verbose;
use std::env;
-use std::fs::File;
+use std::fs::{create_dir_all, File};
use std::io::{self, BufRead, BufReader, Write};
use std::mem;
use std::process::exit;
@@ -71,6 +71,13 @@ fn main() {
}
};
+ // Create the base directory if it does not exist
+ if let Err(why) = create_dir_all(&base) {
+ let stderr = &mut stderr.lock();
+ let _ = writeln!(stderr, "parallel: unable to create tempdir {:?}: {}", base, why);
+ exit(1);
+ }
+
// Collect the command, arguments, and tempdir base path.
args.ninputs = match args.parse(&mut comm, &raw_arguments, &mut base) {
Ok(inputs) => inputs,
@@ -81,8 +88,8 @@ fn main() {
let base_path = match base.to_str() {
Some(base) => String::from(base),
None => {
- let mut stderr = stderr.lock();
- let _ = stderr.write(b"parallel: tempdir path is invalid");
+ let stderr = &mut stderr.lock();
+ let _ = writeln!(stderr, "parallel: tempdir path, {:?}, is invalid", base);
exit(1);
}
};