diff options
author | Michael Aaron Murphy <mmstickman@gmail.com> | 2016-12-23 11:53:49 -0500 |
---|---|---|
committer | Michael Aaron Murphy <mmstickman@gmail.com> | 2016-12-23 12:06:24 -0500 |
commit | ab5f9162a5a9d2823bebf63ab0c5f62326339717 (patch) | |
tree | c35cfca7fe0204560c909120b5e42c87bc3b4498 | |
parent | 3f53fed98094a82468746c314cddb3b60a017fea (diff) |
0.6.5: Bug Fix Release0.6.5
The problem with programming past midnight is that you make mistakes.
This change will allow the shell to be enabled when it's needed.
It will also only check for Dash if the shell is enabled.
-rw-r--r-- | Cargo.lock | 2 | ||||
-rw-r--r-- | Cargo.toml | 2 | ||||
-rw-r--r-- | src/arguments/mod.rs | 41 | ||||
-rw-r--r-- | src/main.rs | 42 |
4 files changed, 42 insertions, 45 deletions
@@ -1,6 +1,6 @@ [root] name = "parallel" -version = "0.6.4" +version = "0.6.5" dependencies = [ "arrayvec 0.3.20 (registry+https://github.com/rust-lang/crates.io-index)", "num_cpus 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)", @@ -1,6 +1,6 @@ [package] name = "parallel" -version = "0.6.4" +version = "0.6.5" 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 2483454..c499615 100644 --- a/src/arguments/mod.rs +++ b/src/arguments/mod.rs @@ -5,7 +5,6 @@ mod man; mod quote; use std::env; -use std::ffi::OsStr; use std::fs; use std::io::{self, BufRead, BufReader}; use std::path::Path; @@ -291,52 +290,12 @@ impl<'a> Args<'a> { Quoting::Shell => quote::shell(comm), } - if dash_exists() { - self.flags |= DASH_EXISTS; - } - - if !shell_required(&self.arguments) { - self.flags &= 255 ^ SHELL_ENABLED; - if self.flags & SHELL_ENABLED == 1 { - println!("Shell enabled"); - } else { - println!("Shell disabled"); - } - } - // Return an `InputIterator` of the arguments contained within the unprocessed file. let inputs = InputIterator::new(unprocessed_path, number_of_arguments).map_err(ParseErr::File)?; Ok(inputs) } } -fn shell_required(arguments: &[Token]) -> bool { - for token in arguments { - if let &Token::Argument(ref arg) = token { - if arg.contains(';') || arg.contains('&') || arg.contains('|') { - return true - } - } - } - false -} - -fn dash_exists() -> bool { - if let Ok(path) = env::var("PATH") { - for path in path.split(':') { - if let Ok(directory) = fs::read_dir(path) { - for entry in directory { - if let Ok(entry) = entry { - let path = entry.path(); - if path.is_file() && path.file_name() == Some(OsStr::new("dash")) { return true; } - } - } - } - } - } - false -} - /// Attempts to open an input argument and adds each line to the `inputs` list. fn file_parse<P: AsRef<Path>>(inputs: &mut Vec<String>, path: P) -> Result<(), ParseErr> { let path = path.as_ref(); diff --git a/src/main.rs b/src/main.rs index c6346f0..f8e581a 100644 --- a/src/main.rs +++ b/src/main.rs @@ -16,7 +16,9 @@ mod threads; mod tokenizer; mod verbose; -use std::fs::File; +use std::env; +use std::ffi::OsStr; +use std::fs::{self, File}; use std::io::{self, BufRead, BufReader, Write}; use std::mem; use std::process::exit; @@ -26,7 +28,7 @@ use std::sync::mpsc::channel; use arguments::Args; use threads::pipe::State; -use tokenizer::{TokenErr, tokenize}; +use tokenizer::{Token, TokenErr, tokenize}; /// Coercing the `command` `String` into a `&'static str` is required to share it among all threads. /// The command string needs to be available in memory for the entirety of the application, so this @@ -37,6 +39,35 @@ unsafe fn leak_command(comm: String) -> &'static str { static_comm } +/// Determines if a shell is required or not for execution +fn shell_required(arguments: &[Token]) -> bool { + for token in arguments { + if let &Token::Argument(ref arg) = token { + if arg.contains(';') || arg.contains('&') || arg.contains('|') { + return true + } + } + } + false +} + +/// Returns `true` if the Dash shell was found within the `PATH` environment variable. +fn dash_exists() -> bool { + if let Ok(path) = env::var("PATH") { + for path in path.split(':') { + if let Ok(directory) = fs::read_dir(path) { + for entry in directory { + if let Ok(entry) = entry { + let path = entry.path(); + if path.is_file() && path.file_name() == Some(OsStr::new("dash")) { return true; } + } + } + } + } + } + false +} + fn main() { // Obtain a handle to standard error's buffer so we can write directly to it. let stdout = io::stdout(); @@ -69,6 +100,13 @@ fn main() { exit(1) } + // Determines if a shell is required or not + if !shell_required(&args.arguments) { + args.flags &= 255 ^ arguments::SHELL_ENABLED; + } else { + if dash_exists() { args.flags |= arguments::DASH_EXISTS; } + } + let shared_input = Arc::new(Mutex::new(inputs)); // If grouping is enabled, stdout and stderr will be buffered. |