mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-07-29 12:07:46 +00:00
Merge branch 'master' into more/rewrite-drawing-logic
This commit is contained in:
commit
4abe4c4ac5
44 changed files with 364 additions and 464 deletions
16
Cargo.lock
generated
16
Cargo.lock
generated
|
@ -6,16 +6,6 @@ version = "0.11.4"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "fe438c63458706e03479442743baae6c88256498e6431708f6dfc520a26515d3"
|
checksum = "fe438c63458706e03479442743baae6c88256498e6431708f6dfc520a26515d3"
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "advapi32-sys"
|
|
||||||
version = "0.2.0"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "e06588080cb19d0acb6739808aafa5f26bfb2ca015b2b6370028b44cf7cb8a9a"
|
|
||||||
dependencies = [
|
|
||||||
"winapi 0.2.8",
|
|
||||||
"winapi-build",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "aho-corasick"
|
name = "aho-corasick"
|
||||||
version = "0.7.18"
|
version = "0.7.18"
|
||||||
|
@ -1772,6 +1762,7 @@ dependencies = [
|
||||||
name = "uu_cat"
|
name = "uu_cat"
|
||||||
version = "0.0.6"
|
version = "0.0.6"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
|
"atty",
|
||||||
"clap",
|
"clap",
|
||||||
"nix 0.20.0",
|
"nix 0.20.0",
|
||||||
"thiserror",
|
"thiserror",
|
||||||
|
@ -1872,6 +1863,7 @@ dependencies = [
|
||||||
name = "uu_cut"
|
name = "uu_cut"
|
||||||
version = "0.0.6"
|
version = "0.0.6"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
|
"atty",
|
||||||
"bstr",
|
"bstr",
|
||||||
"clap",
|
"clap",
|
||||||
"memchr 2.4.0",
|
"memchr 2.4.0",
|
||||||
|
@ -2262,6 +2254,7 @@ dependencies = [
|
||||||
name = "uu_nohup"
|
name = "uu_nohup"
|
||||||
version = "0.0.6"
|
version = "0.0.6"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
|
"atty",
|
||||||
"clap",
|
"clap",
|
||||||
"libc",
|
"libc",
|
||||||
"uucore",
|
"uucore",
|
||||||
|
@ -2602,7 +2595,6 @@ name = "uu_timeout"
|
||||||
version = "0.0.6"
|
version = "0.0.6"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"clap",
|
"clap",
|
||||||
"getopts",
|
|
||||||
"libc",
|
"libc",
|
||||||
"uucore",
|
"uucore",
|
||||||
"uucore_procs",
|
"uucore_procs",
|
||||||
|
@ -2660,6 +2652,7 @@ dependencies = [
|
||||||
name = "uu_tty"
|
name = "uu_tty"
|
||||||
version = "0.0.6"
|
version = "0.0.6"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
|
"atty",
|
||||||
"clap",
|
"clap",
|
||||||
"libc",
|
"libc",
|
||||||
"uucore",
|
"uucore",
|
||||||
|
@ -2751,7 +2744,6 @@ dependencies = [
|
||||||
name = "uu_whoami"
|
name = "uu_whoami"
|
||||||
version = "0.0.6"
|
version = "0.0.6"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"advapi32-sys",
|
|
||||||
"clap",
|
"clap",
|
||||||
"uucore",
|
"uucore",
|
||||||
"uucore_procs",
|
"uucore_procs",
|
||||||
|
|
|
@ -351,7 +351,7 @@ time = "0.1"
|
||||||
unindent = "0.1"
|
unindent = "0.1"
|
||||||
uucore = { version=">=0.0.8", package="uucore", path="src/uucore", features=["entries", "process"] }
|
uucore = { version=">=0.0.8", package="uucore", path="src/uucore", features=["entries", "process"] }
|
||||||
walkdir = "2.2"
|
walkdir = "2.2"
|
||||||
atty = "0.2.14"
|
atty = "0.2"
|
||||||
|
|
||||||
[target.'cfg(unix)'.dev-dependencies]
|
[target.'cfg(unix)'.dev-dependencies]
|
||||||
rlimit = "0.4.0"
|
rlimit = "0.4.0"
|
||||||
|
|
|
@ -38,18 +38,11 @@ pub fn uumain(args: impl uucore::Args) -> i32 {
|
||||||
|
|
||||||
let config_result: Result<base_common::Config, String> =
|
let config_result: Result<base_common::Config, String> =
|
||||||
base_common::parse_base_cmd_args(args, name, VERSION, ABOUT, &usage);
|
base_common::parse_base_cmd_args(args, name, VERSION, ABOUT, &usage);
|
||||||
|
let config = config_result.unwrap_or_else(|s| crash!(BASE_CMD_PARSE_ERROR, "{}", s));
|
||||||
if config_result.is_err() {
|
|
||||||
match config_result {
|
|
||||||
Ok(_) => panic!(),
|
|
||||||
Err(s) => crash!(BASE_CMD_PARSE_ERROR, "{}", s),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Create a reference to stdin so we can return a locked stdin from
|
// Create a reference to stdin so we can return a locked stdin from
|
||||||
// parse_base_cmd_args
|
// parse_base_cmd_args
|
||||||
let stdin_raw = stdin();
|
let stdin_raw = stdin();
|
||||||
let config = config_result.unwrap();
|
|
||||||
let mut input: Box<dyn Read> = base_common::get_input(&config, &stdin_raw);
|
let mut input: Box<dyn Read> = base_common::get_input(&config, &stdin_raw);
|
||||||
|
|
||||||
base_common::handle_input(
|
base_common::handle_input(
|
||||||
|
|
|
@ -38,18 +38,11 @@ pub fn uumain(args: impl uucore::Args) -> i32 {
|
||||||
let name = executable!();
|
let name = executable!();
|
||||||
let config_result: Result<base_common::Config, String> =
|
let config_result: Result<base_common::Config, String> =
|
||||||
base_common::parse_base_cmd_args(args, name, VERSION, ABOUT, &usage);
|
base_common::parse_base_cmd_args(args, name, VERSION, ABOUT, &usage);
|
||||||
|
let config = config_result.unwrap_or_else(|s| crash!(BASE_CMD_PARSE_ERROR, "{}", s));
|
||||||
if config_result.is_err() {
|
|
||||||
match config_result {
|
|
||||||
Ok(_) => panic!(),
|
|
||||||
Err(s) => crash!(BASE_CMD_PARSE_ERROR, "{}", s),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Create a reference to stdin so we can return a locked stdin from
|
// Create a reference to stdin so we can return a locked stdin from
|
||||||
// parse_base_cmd_args
|
// parse_base_cmd_args
|
||||||
let stdin_raw = stdin();
|
let stdin_raw = stdin();
|
||||||
let config = config_result.unwrap();
|
|
||||||
let mut input: Box<dyn Read> = base_common::get_input(&config, &stdin_raw);
|
let mut input: Box<dyn Read> = base_common::get_input(&config, &stdin_raw);
|
||||||
|
|
||||||
base_common::handle_input(
|
base_common::handle_input(
|
||||||
|
|
|
@ -17,6 +17,7 @@ path = "src/cat.rs"
|
||||||
[dependencies]
|
[dependencies]
|
||||||
clap = "2.33"
|
clap = "2.33"
|
||||||
thiserror = "1.0"
|
thiserror = "1.0"
|
||||||
|
atty = "0.2"
|
||||||
uucore = { version=">=0.0.8", package="uucore", path="../../uucore", features=["fs"] }
|
uucore = { version=">=0.0.8", package="uucore", path="../../uucore", features=["fs"] }
|
||||||
uucore_procs = { version=">=0.0.5", package="uucore_procs", path="../../uucore_procs" }
|
uucore_procs = { version=">=0.0.5", package="uucore_procs", path="../../uucore_procs" }
|
||||||
|
|
||||||
|
|
|
@ -20,7 +20,6 @@ use clap::{crate_version, App, Arg};
|
||||||
use std::fs::{metadata, File};
|
use std::fs::{metadata, File};
|
||||||
use std::io::{self, Read, Write};
|
use std::io::{self, Read, Write};
|
||||||
use thiserror::Error;
|
use thiserror::Error;
|
||||||
use uucore::fs::is_stdin_interactive;
|
|
||||||
|
|
||||||
/// Linux splice support
|
/// Linux splice support
|
||||||
#[cfg(any(target_os = "linux", target_os = "android"))]
|
#[cfg(any(target_os = "linux", target_os = "android"))]
|
||||||
|
@ -306,7 +305,7 @@ fn cat_path(path: &str, options: &OutputOptions, state: &mut OutputState) -> Cat
|
||||||
#[cfg(any(target_os = "linux", target_os = "android"))]
|
#[cfg(any(target_os = "linux", target_os = "android"))]
|
||||||
file_descriptor: stdin.as_raw_fd(),
|
file_descriptor: stdin.as_raw_fd(),
|
||||||
reader: stdin,
|
reader: stdin,
|
||||||
is_interactive: is_stdin_interactive(),
|
is_interactive: atty::is(atty::Stream::Stdin),
|
||||||
};
|
};
|
||||||
return cat_handle(&mut handle, options, state);
|
return cat_handle(&mut handle, options, state);
|
||||||
}
|
}
|
||||||
|
|
|
@ -134,23 +134,25 @@ pub fn uumain(args: impl uucore::Args) -> i32 {
|
||||||
Err(err) => crash!(1, "cannot stat attributes of '{}': {}", fref, err),
|
Err(err) => crash!(1, "cannot stat attributes of '{}': {}", fref, err),
|
||||||
});
|
});
|
||||||
let modes = matches.value_of(options::MODE).unwrap(); // should always be Some because required
|
let modes = matches.value_of(options::MODE).unwrap(); // should always be Some because required
|
||||||
let mut cmode = if mode_had_minus_prefix {
|
let cmode = if mode_had_minus_prefix {
|
||||||
// clap parsing is finished, now put prefix back
|
// clap parsing is finished, now put prefix back
|
||||||
Some(format!("-{}", modes))
|
format!("-{}", modes)
|
||||||
} else {
|
} else {
|
||||||
Some(modes.to_string())
|
modes.to_string()
|
||||||
};
|
};
|
||||||
let mut files: Vec<String> = matches
|
let mut files: Vec<String> = matches
|
||||||
.values_of(options::FILE)
|
.values_of(options::FILE)
|
||||||
.map(|v| v.map(ToString::to_string).collect())
|
.map(|v| v.map(ToString::to_string).collect())
|
||||||
.unwrap_or_default();
|
.unwrap_or_default();
|
||||||
if fmode.is_some() {
|
let cmode = if fmode.is_some() {
|
||||||
// "--reference" and MODE are mutually exclusive
|
// "--reference" and MODE are mutually exclusive
|
||||||
// if "--reference" was used MODE needs to be interpreted as another FILE
|
// if "--reference" was used MODE needs to be interpreted as another FILE
|
||||||
// it wasn't possible to implement this behavior directly with clap
|
// it wasn't possible to implement this behavior directly with clap
|
||||||
files.push(cmode.unwrap());
|
files.push(cmode);
|
||||||
cmode = None;
|
None
|
||||||
}
|
} else {
|
||||||
|
Some(cmode)
|
||||||
|
};
|
||||||
|
|
||||||
let chmoder = Chmoder {
|
let chmoder = Chmoder {
|
||||||
changes,
|
changes,
|
||||||
|
|
|
@ -28,6 +28,7 @@ mod options {
|
||||||
pub const GROUP: &str = "group";
|
pub const GROUP: &str = "group";
|
||||||
pub const GROUPS: &str = "groups";
|
pub const GROUPS: &str = "groups";
|
||||||
pub const USERSPEC: &str = "userspec";
|
pub const USERSPEC: &str = "userspec";
|
||||||
|
pub const COMMAND: &str = "command";
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn uumain(args: impl uucore::Args) -> i32 {
|
pub fn uumain(args: impl uucore::Args) -> i32 {
|
||||||
|
@ -39,7 +40,12 @@ pub fn uumain(args: impl uucore::Args) -> i32 {
|
||||||
.version(crate_version!())
|
.version(crate_version!())
|
||||||
.about(ABOUT)
|
.about(ABOUT)
|
||||||
.usage(SYNTAX)
|
.usage(SYNTAX)
|
||||||
.arg(Arg::with_name(options::NEWROOT).hidden(true).required(true))
|
.arg(
|
||||||
|
Arg::with_name(options::NEWROOT)
|
||||||
|
.hidden(true)
|
||||||
|
.required(true)
|
||||||
|
.index(1),
|
||||||
|
)
|
||||||
.arg(
|
.arg(
|
||||||
Arg::with_name(options::USER)
|
Arg::with_name(options::USER)
|
||||||
.short("u")
|
.short("u")
|
||||||
|
@ -71,6 +77,12 @@ pub fn uumain(args: impl uucore::Args) -> i32 {
|
||||||
)
|
)
|
||||||
.value_name("USER:GROUP"),
|
.value_name("USER:GROUP"),
|
||||||
)
|
)
|
||||||
|
.arg(
|
||||||
|
Arg::with_name(options::COMMAND)
|
||||||
|
.hidden(true)
|
||||||
|
.multiple(true)
|
||||||
|
.index(2),
|
||||||
|
)
|
||||||
.get_matches_from(args);
|
.get_matches_from(args);
|
||||||
|
|
||||||
let default_shell: &'static str = "/bin/sh";
|
let default_shell: &'static str = "/bin/sh";
|
||||||
|
@ -94,7 +106,14 @@ pub fn uumain(args: impl uucore::Args) -> i32 {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
let command: Vec<&str> = match matches.args.len() {
|
let commands = match matches.values_of(options::COMMAND) {
|
||||||
|
Some(v) => v.collect(),
|
||||||
|
None => vec![],
|
||||||
|
};
|
||||||
|
|
||||||
|
// TODO: refactor the args and command matching
|
||||||
|
// See: https://github.com/uutils/coreutils/pull/2365#discussion_r647849967
|
||||||
|
let command: Vec<&str> = match commands.len() {
|
||||||
1 => {
|
1 => {
|
||||||
let shell: &str = match user_shell {
|
let shell: &str = match user_shell {
|
||||||
Err(_) => default_shell,
|
Err(_) => default_shell,
|
||||||
|
@ -102,14 +121,7 @@ pub fn uumain(args: impl uucore::Args) -> i32 {
|
||||||
};
|
};
|
||||||
vec![shell, default_option]
|
vec![shell, default_option]
|
||||||
}
|
}
|
||||||
_ => {
|
_ => commands,
|
||||||
let mut vector: Vec<&str> = Vec::new();
|
|
||||||
for (&k, v) in matches.args.iter() {
|
|
||||||
vector.push(k);
|
|
||||||
vector.push(v.vals[0].to_str().unwrap());
|
|
||||||
}
|
|
||||||
vector
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
set_context(newroot, &matches);
|
set_context(newroot, &matches);
|
||||||
|
|
|
@ -20,6 +20,7 @@ uucore = { version=">=0.0.8", package="uucore", path="../../uucore" }
|
||||||
uucore_procs = { version=">=0.0.5", package="uucore_procs", path="../../uucore_procs" }
|
uucore_procs = { version=">=0.0.5", package="uucore_procs", path="../../uucore_procs" }
|
||||||
memchr = "2"
|
memchr = "2"
|
||||||
bstr = "0.2"
|
bstr = "0.2"
|
||||||
|
atty = "0.2"
|
||||||
|
|
||||||
[[bin]]
|
[[bin]]
|
||||||
name = "cut"
|
name = "cut"
|
||||||
|
|
|
@ -17,7 +17,6 @@ use std::io::{stdin, stdout, BufReader, BufWriter, Read, Write};
|
||||||
use std::path::Path;
|
use std::path::Path;
|
||||||
|
|
||||||
use self::searcher::Searcher;
|
use self::searcher::Searcher;
|
||||||
use uucore::fs::is_stdout_interactive;
|
|
||||||
use uucore::ranges::Range;
|
use uucore::ranges::Range;
|
||||||
use uucore::InvalidEncodingHandling;
|
use uucore::InvalidEncodingHandling;
|
||||||
|
|
||||||
|
@ -127,7 +126,7 @@ enum Mode {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn stdout_writer() -> Box<dyn Write> {
|
fn stdout_writer() -> Box<dyn Write> {
|
||||||
if is_stdout_interactive() {
|
if atty::is(atty::Stream::Stdout) {
|
||||||
Box::new(stdout())
|
Box::new(stdout())
|
||||||
} else {
|
} else {
|
||||||
Box::new(BufWriter::new(stdout())) as Box<dyn Write>
|
Box::new(BufWriter::new(stdout())) as Box<dyn Write>
|
||||||
|
|
|
@ -19,6 +19,8 @@ clap = "2.33"
|
||||||
chrono = "0.4"
|
chrono = "0.4"
|
||||||
uucore = { version=">=0.0.8", package="uucore", path="../../uucore" }
|
uucore = { version=">=0.0.8", package="uucore", path="../../uucore" }
|
||||||
uucore_procs = { version=">=0.0.5", package="uucore_procs", path="../../uucore_procs" }
|
uucore_procs = { version=">=0.0.5", package="uucore_procs", path="../../uucore_procs" }
|
||||||
|
|
||||||
|
[target.'cfg(target_os = "windows")'.dependencies]
|
||||||
winapi = { version="0.3", features=[] }
|
winapi = { version="0.3", features=[] }
|
||||||
|
|
||||||
[[bin]]
|
[[bin]]
|
||||||
|
|
|
@ -57,6 +57,7 @@ mod options {
|
||||||
pub const SI: &str = "si";
|
pub const SI: &str = "si";
|
||||||
pub const TIME: &str = "time";
|
pub const TIME: &str = "time";
|
||||||
pub const TIME_STYLE: &str = "time-style";
|
pub const TIME_STYLE: &str = "time-style";
|
||||||
|
pub const ONE_FILE_SYSTEM: &str = "one-file-system";
|
||||||
pub const FILE: &str = "FILE";
|
pub const FILE: &str = "FILE";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -81,6 +82,7 @@ struct Options {
|
||||||
max_depth: Option<usize>,
|
max_depth: Option<usize>,
|
||||||
total: bool,
|
total: bool,
|
||||||
separate_dirs: bool,
|
separate_dirs: bool,
|
||||||
|
one_file_system: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(PartialEq, Eq, Hash, Clone, Copy)]
|
#[derive(PartialEq, Eq, Hash, Clone, Copy)]
|
||||||
|
@ -229,10 +231,9 @@ fn unit_string_to_number(s: &str) -> Option<u64> {
|
||||||
let mut offset = 0;
|
let mut offset = 0;
|
||||||
let mut s_chars = s.chars().rev();
|
let mut s_chars = s.chars().rev();
|
||||||
|
|
||||||
let (mut ch, multiple) = match s_chars.next() {
|
let (mut ch, multiple) = match s_chars.next()? {
|
||||||
Some('B') | Some('b') => ('B', 1000u64),
|
'B' | 'b' => ('B', 1000u64),
|
||||||
Some(ch) => (ch, 1024u64),
|
ch => (ch, 1024u64),
|
||||||
None => return None,
|
|
||||||
};
|
};
|
||||||
if ch == 'B' {
|
if ch == 'B' {
|
||||||
ch = s_chars.next()?;
|
ch = s_chars.next()?;
|
||||||
|
@ -318,10 +319,18 @@ fn du(
|
||||||
Ok(entry) => match Stat::new(entry.path()) {
|
Ok(entry) => match Stat::new(entry.path()) {
|
||||||
Ok(this_stat) => {
|
Ok(this_stat) => {
|
||||||
if this_stat.is_dir {
|
if this_stat.is_dir {
|
||||||
|
if options.one_file_system {
|
||||||
|
if let (Some(this_inode), Some(my_inode)) =
|
||||||
|
(this_stat.inode, my_stat.inode)
|
||||||
|
{
|
||||||
|
if this_inode.dev_id != my_inode.dev_id {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
futures.push(du(this_stat, options, depth + 1, inodes));
|
futures.push(du(this_stat, options, depth + 1, inodes));
|
||||||
} else {
|
} else {
|
||||||
if this_stat.inode.is_some() {
|
if let Some(inode) = this_stat.inode {
|
||||||
let inode = this_stat.inode.unwrap();
|
|
||||||
if inodes.contains(&inode) {
|
if inodes.contains(&inode) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
@ -360,7 +369,9 @@ fn du(
|
||||||
my_stat.size += stat.size;
|
my_stat.size += stat.size;
|
||||||
my_stat.blocks += stat.blocks;
|
my_stat.blocks += stat.blocks;
|
||||||
}
|
}
|
||||||
options.max_depth == None || depth < options.max_depth.unwrap()
|
options
|
||||||
|
.max_depth
|
||||||
|
.map_or(true, |max_depth| depth < max_depth)
|
||||||
}));
|
}));
|
||||||
stats.push(my_stat);
|
stats.push(my_stat);
|
||||||
Box::new(stats.into_iter())
|
Box::new(stats.into_iter())
|
||||||
|
@ -532,12 +543,12 @@ pub fn uumain(args: impl uucore::Args) -> i32 {
|
||||||
.long(options::SI)
|
.long(options::SI)
|
||||||
.help("like -h, but use powers of 1000 not 1024")
|
.help("like -h, but use powers of 1000 not 1024")
|
||||||
)
|
)
|
||||||
// .arg(
|
.arg(
|
||||||
// Arg::with_name("one-file-system")
|
Arg::with_name(options::ONE_FILE_SYSTEM)
|
||||||
// .short("x")
|
.short("x")
|
||||||
// .long("one-file-system")
|
.long(options::ONE_FILE_SYSTEM)
|
||||||
// .help("skip directories on different file systems")
|
.help("skip directories on different file systems")
|
||||||
// )
|
)
|
||||||
// .arg(
|
// .arg(
|
||||||
// Arg::with_name("")
|
// Arg::with_name("")
|
||||||
// .short("x")
|
// .short("x")
|
||||||
|
@ -602,6 +613,7 @@ pub fn uumain(args: impl uucore::Args) -> i32 {
|
||||||
max_depth,
|
max_depth,
|
||||||
total: matches.is_present(options::TOTAL),
|
total: matches.is_present(options::TOTAL),
|
||||||
separate_dirs: matches.is_present(options::SEPARATE_DIRS),
|
separate_dirs: matches.is_present(options::SEPARATE_DIRS),
|
||||||
|
one_file_system: matches.is_present(options::ONE_FILE_SYSTEM),
|
||||||
};
|
};
|
||||||
|
|
||||||
let files = match matches.value_of(options::FILE) {
|
let files = match matches.value_of(options::FILE) {
|
||||||
|
|
|
@ -56,11 +56,7 @@ fn print_expr_error(expr_error: &str) -> ! {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn evaluate_ast(maybe_ast: Result<Box<syntax_tree::AstNode>, String>) -> Result<String, String> {
|
fn evaluate_ast(maybe_ast: Result<Box<syntax_tree::AstNode>, String>) -> Result<String, String> {
|
||||||
if maybe_ast.is_err() {
|
maybe_ast.and_then(|ast| ast.evaluate())
|
||||||
Err(maybe_ast.err().unwrap())
|
|
||||||
} else {
|
|
||||||
maybe_ast.ok().unwrap().evaluate()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn maybe_handle_help_or_version(args: &[String]) -> bool {
|
fn maybe_handle_help_or_version(args: &[String]) -> bool {
|
||||||
|
|
|
@ -175,23 +175,14 @@ impl AstNode {
|
||||||
pub fn tokens_to_ast(
|
pub fn tokens_to_ast(
|
||||||
maybe_tokens: Result<Vec<(usize, Token)>, String>,
|
maybe_tokens: Result<Vec<(usize, Token)>, String>,
|
||||||
) -> Result<Box<AstNode>, String> {
|
) -> Result<Box<AstNode>, String> {
|
||||||
if maybe_tokens.is_err() {
|
maybe_tokens.and_then(|tokens| {
|
||||||
Err(maybe_tokens.err().unwrap())
|
|
||||||
} else {
|
|
||||||
let tokens = maybe_tokens.ok().unwrap();
|
|
||||||
let mut out_stack: TokenStack = Vec::new();
|
let mut out_stack: TokenStack = Vec::new();
|
||||||
let mut op_stack: TokenStack = Vec::new();
|
let mut op_stack: TokenStack = Vec::new();
|
||||||
|
|
||||||
for (token_idx, token) in tokens {
|
for (token_idx, token) in tokens {
|
||||||
if let Err(reason) =
|
push_token_to_either_stack(token_idx, &token, &mut out_stack, &mut op_stack)?;
|
||||||
push_token_to_either_stack(token_idx, &token, &mut out_stack, &mut op_stack)
|
|
||||||
{
|
|
||||||
return Err(reason);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if let Err(reason) = move_rest_of_ops_to_out(&mut out_stack, &mut op_stack) {
|
|
||||||
return Err(reason);
|
|
||||||
}
|
}
|
||||||
|
move_rest_of_ops_to_out(&mut out_stack, &mut op_stack)?;
|
||||||
assert!(op_stack.is_empty());
|
assert!(op_stack.is_empty());
|
||||||
|
|
||||||
maybe_dump_rpn(&out_stack);
|
maybe_dump_rpn(&out_stack);
|
||||||
|
@ -205,7 +196,7 @@ pub fn tokens_to_ast(
|
||||||
maybe_dump_ast(&result);
|
maybe_dump_ast(&result);
|
||||||
result
|
result
|
||||||
}
|
}
|
||||||
}
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
fn maybe_dump_ast(result: &Result<Box<AstNode>, String>) {
|
fn maybe_dump_ast(result: &Result<Box<AstNode>, String>) {
|
||||||
|
|
|
@ -98,7 +98,7 @@ pub fn uumain(args: impl uucore::Args) -> i32 {
|
||||||
fn handle_obsolete(args: &[String]) -> (Vec<String>, Option<String>) {
|
fn handle_obsolete(args: &[String]) -> (Vec<String>, Option<String>) {
|
||||||
for (i, arg) in args.iter().enumerate() {
|
for (i, arg) in args.iter().enumerate() {
|
||||||
let slice = &arg;
|
let slice = &arg;
|
||||||
if slice.starts_with('-') && slice.len() > 1 && slice.chars().nth(1).unwrap().is_digit(10) {
|
if slice.starts_with('-') && slice.chars().nth(1).map_or(false, |c| c.is_digit(10)) {
|
||||||
let mut v = args.to_vec();
|
let mut v = args.to_vec();
|
||||||
v.remove(i);
|
v.remove(i);
|
||||||
return (v, Some(slice[1..].to_owned()));
|
return (v, Some(slice[1..].to_owned()));
|
||||||
|
|
|
@ -15,7 +15,7 @@ edition = "2018"
|
||||||
path = "src/groups.rs"
|
path = "src/groups.rs"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
uucore = { version=">=0.0.8", package="uucore", path="../../uucore", features=["entries"] }
|
uucore = { version=">=0.0.8", package="uucore", path="../../uucore", features=["entries", "process"] }
|
||||||
uucore_procs = { version=">=0.0.5", package="uucore_procs", path="../../uucore_procs" }
|
uucore_procs = { version=">=0.0.5", package="uucore_procs", path="../../uucore_procs" }
|
||||||
clap = "2.33"
|
clap = "2.33"
|
||||||
|
|
||||||
|
|
|
@ -255,10 +255,8 @@ fn detect_algo<'a>(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if alg.is_none() {
|
let alg = alg.unwrap_or_else(|| crash!(1, "You must specify hash algorithm!"));
|
||||||
crash!(1, "You must specify hash algorithm!")
|
(name, alg, output_bits)
|
||||||
};
|
|
||||||
(name, alg.unwrap(), output_bits)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -111,7 +111,7 @@ fn handle_obsolete(mut args: Vec<String>) -> (Vec<String>, Option<String>) {
|
||||||
while i < args.len() {
|
while i < args.len() {
|
||||||
// this is safe because slice is valid when it is referenced
|
// this is safe because slice is valid when it is referenced
|
||||||
let slice = &args[i].clone();
|
let slice = &args[i].clone();
|
||||||
if slice.starts_with('-') && slice.len() > 1 && slice.chars().nth(1).unwrap().is_digit(10) {
|
if slice.starts_with('-') && slice.chars().nth(1).map_or(false, |c| c.is_digit(10)) {
|
||||||
let val = &slice[1..];
|
let val = &slice[1..];
|
||||||
match val.parse() {
|
match val.parse() {
|
||||||
Ok(num) => {
|
Ok(num) => {
|
||||||
|
|
|
@ -78,17 +78,19 @@ fn get_long_usage() -> String {
|
||||||
|
|
||||||
static ABOUT: &str = "change file owner and group";
|
static ABOUT: &str = "change file owner and group";
|
||||||
|
|
||||||
static OPT_B: &str = "b";
|
mod options {
|
||||||
static OPT_BACKUP: &str = "backup";
|
pub const B: &str = "b";
|
||||||
static OPT_FORCE: &str = "force";
|
pub const BACKUP: &str = "backup";
|
||||||
static OPT_INTERACTIVE: &str = "interactive";
|
pub const FORCE: &str = "force";
|
||||||
static OPT_NO_DEREFERENCE: &str = "no-dereference";
|
pub const INTERACTIVE: &str = "interactive";
|
||||||
static OPT_SYMBOLIC: &str = "symbolic";
|
pub const NO_DEREFERENCE: &str = "no-dereference";
|
||||||
static OPT_SUFFIX: &str = "suffix";
|
pub const SYMBOLIC: &str = "symbolic";
|
||||||
static OPT_TARGET_DIRECTORY: &str = "target-directory";
|
pub const SUFFIX: &str = "suffix";
|
||||||
static OPT_NO_TARGET_DIRECTORY: &str = "no-target-directory";
|
pub const TARGET_DIRECTORY: &str = "target-directory";
|
||||||
static OPT_RELATIVE: &str = "relative";
|
pub const NO_TARGET_DIRECTORY: &str = "no-target-directory";
|
||||||
static OPT_VERBOSE: &str = "verbose";
|
pub const RELATIVE: &str = "relative";
|
||||||
|
pub const VERBOSE: &str = "verbose";
|
||||||
|
}
|
||||||
|
|
||||||
static ARG_FILES: &str = "files";
|
static ARG_FILES: &str = "files";
|
||||||
|
|
||||||
|
@ -101,47 +103,42 @@ pub fn uumain(args: impl uucore::Args) -> i32 {
|
||||||
.about(ABOUT)
|
.about(ABOUT)
|
||||||
.usage(&usage[..])
|
.usage(&usage[..])
|
||||||
.after_help(&long_usage[..])
|
.after_help(&long_usage[..])
|
||||||
.arg(Arg::with_name(OPT_B).short(OPT_B).help(
|
.arg(Arg::with_name(options::B).short(options::B).help(
|
||||||
"make a backup of each file that would otherwise be overwritten or \
|
"make a backup of each file that would otherwise be overwritten or \
|
||||||
removed",
|
removed",
|
||||||
))
|
))
|
||||||
.arg(
|
.arg(
|
||||||
Arg::with_name(OPT_BACKUP)
|
Arg::with_name(options::BACKUP)
|
||||||
.long(OPT_BACKUP)
|
.long(options::BACKUP)
|
||||||
.help(
|
.help(
|
||||||
"make a backup of each file that would otherwise be overwritten \
|
"make a backup of each file that would otherwise be overwritten \
|
||||||
or removed",
|
or removed",
|
||||||
)
|
)
|
||||||
.takes_value(true)
|
.takes_value(true)
|
||||||
.possible_value("simple")
|
.possible_values(&[
|
||||||
.possible_value("never")
|
"simple", "never", "numbered", "t", "existing", "nil", "none", "off",
|
||||||
.possible_value("numbered")
|
])
|
||||||
.possible_value("t")
|
|
||||||
.possible_value("existing")
|
|
||||||
.possible_value("nil")
|
|
||||||
.possible_value("none")
|
|
||||||
.possible_value("off")
|
|
||||||
.value_name("METHOD"),
|
.value_name("METHOD"),
|
||||||
)
|
)
|
||||||
// TODO: opts.arg(
|
// TODO: opts.arg(
|
||||||
// Arg::with_name(("d", "directory", "allow users with appropriate privileges to attempt \
|
// Arg::with_name(("d", "directory", "allow users with appropriate privileges to attempt \
|
||||||
// to make hard links to directories");
|
// to make hard links to directories");
|
||||||
.arg(
|
.arg(
|
||||||
Arg::with_name(OPT_FORCE)
|
Arg::with_name(options::FORCE)
|
||||||
.short("f")
|
.short("f")
|
||||||
.long(OPT_FORCE)
|
.long(options::FORCE)
|
||||||
.help("remove existing destination files"),
|
.help("remove existing destination files"),
|
||||||
)
|
)
|
||||||
.arg(
|
.arg(
|
||||||
Arg::with_name(OPT_INTERACTIVE)
|
Arg::with_name(options::INTERACTIVE)
|
||||||
.short("i")
|
.short("i")
|
||||||
.long(OPT_INTERACTIVE)
|
.long(options::INTERACTIVE)
|
||||||
.help("prompt whether to remove existing destination files"),
|
.help("prompt whether to remove existing destination files"),
|
||||||
)
|
)
|
||||||
.arg(
|
.arg(
|
||||||
Arg::with_name(OPT_NO_DEREFERENCE)
|
Arg::with_name(options::NO_DEREFERENCE)
|
||||||
.short("n")
|
.short("n")
|
||||||
.long(OPT_NO_DEREFERENCE)
|
.long(options::NO_DEREFERENCE)
|
||||||
.help(
|
.help(
|
||||||
"treat LINK_executable!() as a normal file if it is a \
|
"treat LINK_executable!() as a normal file if it is a \
|
||||||
symbolic link to a directory",
|
symbolic link to a directory",
|
||||||
|
@ -153,43 +150,45 @@ pub fn uumain(args: impl uucore::Args) -> i32 {
|
||||||
// TODO: opts.arg(
|
// TODO: opts.arg(
|
||||||
// Arg::with_name(("P", "physical", "make hard links directly to symbolic links");
|
// Arg::with_name(("P", "physical", "make hard links directly to symbolic links");
|
||||||
.arg(
|
.arg(
|
||||||
Arg::with_name(OPT_SYMBOLIC)
|
Arg::with_name(options::SYMBOLIC)
|
||||||
.short("s")
|
.short("s")
|
||||||
.long("symbolic")
|
.long("symbolic")
|
||||||
.help("make symbolic links instead of hard links"),
|
.help("make symbolic links instead of hard links")
|
||||||
|
// override added for https://github.com/uutils/coreutils/issues/2359
|
||||||
|
.overrides_with(options::SYMBOLIC),
|
||||||
)
|
)
|
||||||
.arg(
|
.arg(
|
||||||
Arg::with_name(OPT_SUFFIX)
|
Arg::with_name(options::SUFFIX)
|
||||||
.short("S")
|
.short("S")
|
||||||
.long(OPT_SUFFIX)
|
.long(options::SUFFIX)
|
||||||
.help("override the usual backup suffix")
|
.help("override the usual backup suffix")
|
||||||
.value_name("SUFFIX")
|
.value_name("SUFFIX")
|
||||||
.takes_value(true),
|
.takes_value(true),
|
||||||
)
|
)
|
||||||
.arg(
|
.arg(
|
||||||
Arg::with_name(OPT_TARGET_DIRECTORY)
|
Arg::with_name(options::TARGET_DIRECTORY)
|
||||||
.short("t")
|
.short("t")
|
||||||
.long(OPT_TARGET_DIRECTORY)
|
.long(options::TARGET_DIRECTORY)
|
||||||
.help("specify the DIRECTORY in which to create the links")
|
.help("specify the DIRECTORY in which to create the links")
|
||||||
.value_name("DIRECTORY")
|
.value_name("DIRECTORY")
|
||||||
.conflicts_with(OPT_NO_TARGET_DIRECTORY),
|
.conflicts_with(options::NO_TARGET_DIRECTORY),
|
||||||
)
|
)
|
||||||
.arg(
|
.arg(
|
||||||
Arg::with_name(OPT_NO_TARGET_DIRECTORY)
|
Arg::with_name(options::NO_TARGET_DIRECTORY)
|
||||||
.short("T")
|
.short("T")
|
||||||
.long(OPT_NO_TARGET_DIRECTORY)
|
.long(options::NO_TARGET_DIRECTORY)
|
||||||
.help("treat LINK_executable!() as a normal file always"),
|
.help("treat LINK_executable!() as a normal file always"),
|
||||||
)
|
)
|
||||||
.arg(
|
.arg(
|
||||||
Arg::with_name(OPT_RELATIVE)
|
Arg::with_name(options::RELATIVE)
|
||||||
.short("r")
|
.short("r")
|
||||||
.long(OPT_RELATIVE)
|
.long(options::RELATIVE)
|
||||||
.help("create symbolic links relative to link location"),
|
.help("create symbolic links relative to link location"),
|
||||||
)
|
)
|
||||||
.arg(
|
.arg(
|
||||||
Arg::with_name(OPT_VERBOSE)
|
Arg::with_name(options::VERBOSE)
|
||||||
.short("v")
|
.short("v")
|
||||||
.long(OPT_VERBOSE)
|
.long(options::VERBOSE)
|
||||||
.help("print name of each linked file"),
|
.help("print name of each linked file"),
|
||||||
)
|
)
|
||||||
.arg(
|
.arg(
|
||||||
|
@ -209,18 +208,18 @@ pub fn uumain(args: impl uucore::Args) -> i32 {
|
||||||
.map(PathBuf::from)
|
.map(PathBuf::from)
|
||||||
.collect();
|
.collect();
|
||||||
|
|
||||||
let overwrite_mode = if matches.is_present(OPT_FORCE) {
|
let overwrite_mode = if matches.is_present(options::FORCE) {
|
||||||
OverwriteMode::Force
|
OverwriteMode::Force
|
||||||
} else if matches.is_present(OPT_INTERACTIVE) {
|
} else if matches.is_present(options::INTERACTIVE) {
|
||||||
OverwriteMode::Interactive
|
OverwriteMode::Interactive
|
||||||
} else {
|
} else {
|
||||||
OverwriteMode::NoClobber
|
OverwriteMode::NoClobber
|
||||||
};
|
};
|
||||||
|
|
||||||
let backup_mode = if matches.is_present(OPT_B) {
|
let backup_mode = if matches.is_present(options::B) {
|
||||||
BackupMode::ExistingBackup
|
BackupMode::ExistingBackup
|
||||||
} else if matches.is_present(OPT_BACKUP) {
|
} else if matches.is_present(options::BACKUP) {
|
||||||
match matches.value_of(OPT_BACKUP) {
|
match matches.value_of(options::BACKUP) {
|
||||||
None => BackupMode::ExistingBackup,
|
None => BackupMode::ExistingBackup,
|
||||||
Some(mode) => match mode {
|
Some(mode) => match mode {
|
||||||
"simple" | "never" => BackupMode::SimpleBackup,
|
"simple" | "never" => BackupMode::SimpleBackup,
|
||||||
|
@ -234,8 +233,8 @@ pub fn uumain(args: impl uucore::Args) -> i32 {
|
||||||
BackupMode::NoBackup
|
BackupMode::NoBackup
|
||||||
};
|
};
|
||||||
|
|
||||||
let backup_suffix = if matches.is_present(OPT_SUFFIX) {
|
let backup_suffix = if matches.is_present(options::SUFFIX) {
|
||||||
matches.value_of(OPT_SUFFIX).unwrap()
|
matches.value_of(options::SUFFIX).unwrap()
|
||||||
} else {
|
} else {
|
||||||
"~"
|
"~"
|
||||||
};
|
};
|
||||||
|
@ -243,14 +242,16 @@ pub fn uumain(args: impl uucore::Args) -> i32 {
|
||||||
let settings = Settings {
|
let settings = Settings {
|
||||||
overwrite: overwrite_mode,
|
overwrite: overwrite_mode,
|
||||||
backup: backup_mode,
|
backup: backup_mode,
|
||||||
force: matches.is_present(OPT_FORCE),
|
force: matches.is_present(options::FORCE),
|
||||||
suffix: backup_suffix.to_string(),
|
suffix: backup_suffix.to_string(),
|
||||||
symbolic: matches.is_present(OPT_SYMBOLIC),
|
symbolic: matches.is_present(options::SYMBOLIC),
|
||||||
relative: matches.is_present(OPT_RELATIVE),
|
relative: matches.is_present(options::RELATIVE),
|
||||||
target_dir: matches.value_of(OPT_TARGET_DIRECTORY).map(String::from),
|
target_dir: matches
|
||||||
no_target_dir: matches.is_present(OPT_NO_TARGET_DIRECTORY),
|
.value_of(options::TARGET_DIRECTORY)
|
||||||
no_dereference: matches.is_present(OPT_NO_DEREFERENCE),
|
.map(String::from),
|
||||||
verbose: matches.is_present(OPT_VERBOSE),
|
no_target_dir: matches.is_present(options::NO_TARGET_DIRECTORY),
|
||||||
|
no_dereference: matches.is_present(options::NO_DEREFERENCE),
|
||||||
|
verbose: matches.is_present(options::VERBOSE),
|
||||||
};
|
};
|
||||||
|
|
||||||
exec(&paths[..], &settings)
|
exec(&paths[..], &settings)
|
||||||
|
|
|
@ -19,7 +19,7 @@ clap = "2.33"
|
||||||
uucore = { version = ">=0.0.7", package = "uucore", path = "../../uucore" }
|
uucore = { version = ">=0.0.7", package = "uucore", path = "../../uucore" }
|
||||||
uucore_procs = { version = ">=0.0.5", package = "uucore_procs", path = "../../uucore_procs" }
|
uucore_procs = { version = ">=0.0.5", package = "uucore_procs", path = "../../uucore_procs" }
|
||||||
crossterm = ">=0.19"
|
crossterm = ">=0.19"
|
||||||
atty = "0.2.14"
|
atty = "0.2"
|
||||||
unicode-width = "0.1.7"
|
unicode-width = "0.1.7"
|
||||||
unicode-segmentation = "1.7.1"
|
unicode-segmentation = "1.7.1"
|
||||||
|
|
||||||
|
|
|
@ -31,6 +31,8 @@ use crossterm::{
|
||||||
use unicode_segmentation::UnicodeSegmentation;
|
use unicode_segmentation::UnicodeSegmentation;
|
||||||
use unicode_width::UnicodeWidthStr;
|
use unicode_width::UnicodeWidthStr;
|
||||||
|
|
||||||
|
const BELL: &str = "\x07";
|
||||||
|
|
||||||
pub mod options {
|
pub mod options {
|
||||||
pub const SILENT: &str = "silent";
|
pub const SILENT: &str = "silent";
|
||||||
pub const LOGICAL: &str = "logical";
|
pub const LOGICAL: &str = "logical";
|
||||||
|
@ -52,14 +54,14 @@ pub fn uumain(args: impl uucore::Args) -> i32 {
|
||||||
let matches = App::new(executable!())
|
let matches = App::new(executable!())
|
||||||
.about("A file perusal filter for CRT viewing.")
|
.about("A file perusal filter for CRT viewing.")
|
||||||
.version(crate_version!())
|
.version(crate_version!())
|
||||||
// The commented arguments below are unimplemented:
|
|
||||||
/*
|
|
||||||
.arg(
|
.arg(
|
||||||
Arg::with_name(options::SILENT)
|
Arg::with_name(options::SILENT)
|
||||||
.short("d")
|
.short("d")
|
||||||
.long(options::SILENT)
|
.long(options::SILENT)
|
||||||
.help("Display help instead of ringing bell"),
|
.help("Display help instead of ringing bell"),
|
||||||
)
|
)
|
||||||
|
// The commented arguments below are unimplemented:
|
||||||
|
/*
|
||||||
.arg(
|
.arg(
|
||||||
Arg::with_name(options::LOGICAL)
|
Arg::with_name(options::LOGICAL)
|
||||||
.short("f")
|
.short("f")
|
||||||
|
@ -139,6 +141,7 @@ pub fn uumain(args: impl uucore::Args) -> i32 {
|
||||||
.get_matches_from(args);
|
.get_matches_from(args);
|
||||||
|
|
||||||
let mut buff = String::new();
|
let mut buff = String::new();
|
||||||
|
let silent = matches.is_present(options::SILENT);
|
||||||
if let Some(files) = matches.values_of(options::FILES) {
|
if let Some(files) = matches.values_of(options::FILES) {
|
||||||
let mut stdout = setup_term();
|
let mut stdout = setup_term();
|
||||||
let length = files.len();
|
let length = files.len();
|
||||||
|
@ -161,14 +164,14 @@ pub fn uumain(args: impl uucore::Args) -> i32 {
|
||||||
}
|
}
|
||||||
let mut reader = BufReader::new(File::open(file).unwrap());
|
let mut reader = BufReader::new(File::open(file).unwrap());
|
||||||
reader.read_to_string(&mut buff).unwrap();
|
reader.read_to_string(&mut buff).unwrap();
|
||||||
more(&buff, &mut stdout, next_file.copied());
|
more(&buff, &mut stdout, next_file.copied(), silent);
|
||||||
buff.clear();
|
buff.clear();
|
||||||
}
|
}
|
||||||
reset_term(&mut stdout);
|
reset_term(&mut stdout);
|
||||||
} else if atty::isnt(atty::Stream::Stdin) {
|
} else if atty::isnt(atty::Stream::Stdin) {
|
||||||
stdin().read_to_string(&mut buff).unwrap();
|
stdin().read_to_string(&mut buff).unwrap();
|
||||||
let mut stdout = setup_term();
|
let mut stdout = setup_term();
|
||||||
more(&buff, &mut stdout, None);
|
more(&buff, &mut stdout, None, silent);
|
||||||
reset_term(&mut stdout);
|
reset_term(&mut stdout);
|
||||||
} else {
|
} else {
|
||||||
show_usage_error!("bad usage");
|
show_usage_error!("bad usage");
|
||||||
|
@ -203,17 +206,18 @@ fn reset_term(stdout: &mut std::io::Stdout) {
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
fn reset_term(_: &mut usize) {}
|
fn reset_term(_: &mut usize) {}
|
||||||
|
|
||||||
fn more(buff: &str, mut stdout: &mut Stdout, next_file: Option<&str>) {
|
fn more(buff: &str, mut stdout: &mut Stdout, next_file: Option<&str>, silent: bool) {
|
||||||
let (cols, rows) = terminal::size().unwrap();
|
let (cols, rows) = terminal::size().unwrap();
|
||||||
let lines = break_buff(buff, usize::from(cols));
|
let lines = break_buff(buff, usize::from(cols));
|
||||||
|
|
||||||
let mut pager = Pager::new(rows as usize, lines, next_file);
|
let mut pager = Pager::new(rows as usize, lines, next_file, silent);
|
||||||
pager.draw(stdout);
|
pager.draw(stdout, false);
|
||||||
if pager.should_close() {
|
if pager.should_close() {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
loop {
|
loop {
|
||||||
|
let mut wrong_key = false;
|
||||||
if event::poll(Duration::from_millis(10)).unwrap() {
|
if event::poll(Duration::from_millis(10)).unwrap() {
|
||||||
match event::read().unwrap() {
|
match event::read().unwrap() {
|
||||||
Event::Key(KeyEvent {
|
Event::Key(KeyEvent {
|
||||||
|
@ -243,10 +247,12 @@ fn more(buff: &str, mut stdout: &mut Stdout, next_file: Option<&str>) {
|
||||||
}) => {
|
}) => {
|
||||||
pager.page_up();
|
pager.page_up();
|
||||||
}
|
}
|
||||||
_ => continue,
|
_ => {
|
||||||
|
wrong_key = true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pager.draw(stdout);
|
pager.draw(stdout, wrong_key);
|
||||||
if pager.should_close() {
|
if pager.should_close() {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -263,10 +269,11 @@ struct Pager<'a> {
|
||||||
next_file: Option<&'a str>,
|
next_file: Option<&'a str>,
|
||||||
line_count: usize,
|
line_count: usize,
|
||||||
close_on_down: bool,
|
close_on_down: bool,
|
||||||
|
silent: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> Pager<'a> {
|
impl<'a> Pager<'a> {
|
||||||
fn new(rows: usize, lines: Vec<String>, next_file: Option<&'a str>) -> Self {
|
fn new(rows: usize, lines: Vec<String>, next_file: Option<&'a str>, silent: bool) -> Self {
|
||||||
let line_count = lines.len();
|
let line_count = lines.len();
|
||||||
Self {
|
Self {
|
||||||
upper_mark: 0,
|
upper_mark: 0,
|
||||||
|
@ -275,6 +282,7 @@ impl<'a> Pager<'a> {
|
||||||
next_file,
|
next_file,
|
||||||
line_count,
|
line_count,
|
||||||
close_on_down: false,
|
close_on_down: false,
|
||||||
|
silent,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -302,10 +310,10 @@ impl<'a> Pager<'a> {
|
||||||
self.upper_mark = self.upper_mark.saturating_sub(self.content_rows);
|
self.upper_mark = self.upper_mark.saturating_sub(self.content_rows);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn draw(&self, stdout: &mut std::io::Stdout) {
|
fn draw(&self, stdout: &mut std::io::Stdout, wrong_key: bool) {
|
||||||
let lower_mark = self.line_count.min(self.upper_mark + self.content_rows);
|
let lower_mark = self.line_count.min(self.upper_mark + self.content_rows);
|
||||||
self.draw_lines(stdout);
|
self.draw_lines(stdout);
|
||||||
self.draw_prompt(stdout, lower_mark);
|
self.draw_prompt(stdout, lower_mark, wrong_key);
|
||||||
stdout.flush().unwrap();
|
stdout.flush().unwrap();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -324,20 +332,30 @@ impl<'a> Pager<'a> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn draw_prompt(&self, stdout: &mut Stdout, lower_mark: usize) {
|
fn draw_prompt(&self, stdout: &mut Stdout, lower_mark: usize, wrong_key: bool) {
|
||||||
let status = if lower_mark == self.line_count {
|
let status_inner = if lower_mark == self.line_count {
|
||||||
format!("Next file: {}", self.next_file.unwrap_or_default())
|
format!("Next file: {}", self.next_file.unwrap_or_default())
|
||||||
} else {
|
} else {
|
||||||
format!(
|
format!(
|
||||||
"{}%",
|
"{}%",
|
||||||
(lower_mark as f64 / self.line_count as f64 * 100.0).round() as usize
|
(lower_mark as f64 / self.line_count as f64 * 100.0).round() as u16
|
||||||
)
|
)
|
||||||
};
|
};
|
||||||
|
|
||||||
|
let status = format!("--More--({})", status_inner);
|
||||||
|
|
||||||
|
let banner = match (self.silent, wrong_key) {
|
||||||
|
(true, true) => "[Press 'h' for instructions. (unimplemented)]".to_string(),
|
||||||
|
(true, false) => format!("{}[Press space to continue, 'q' to quit.]", status),
|
||||||
|
(false, true) => format!("{}{}", status, BELL),
|
||||||
|
(false, false) => status,
|
||||||
|
};
|
||||||
|
|
||||||
write!(
|
write!(
|
||||||
stdout,
|
stdout,
|
||||||
"\r{}--More--({}){}",
|
"\r{}{}{}",
|
||||||
Attribute::Reverse,
|
Attribute::Reverse,
|
||||||
status,
|
banner,
|
||||||
Attribute::Reset
|
Attribute::Reset
|
||||||
)
|
)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
|
@ -247,7 +247,7 @@ fn nl<T: Read>(reader: &mut BufReader<T>, settings: &Settings) {
|
||||||
let mut line_filter: fn(&str, ®ex::Regex) -> bool = pass_regex;
|
let mut line_filter: fn(&str, ®ex::Regex) -> bool = pass_regex;
|
||||||
for mut l in reader.lines().map(|r| r.unwrap()) {
|
for mut l in reader.lines().map(|r| r.unwrap()) {
|
||||||
// Sanitize the string. We want to print the newline ourselves.
|
// Sanitize the string. We want to print the newline ourselves.
|
||||||
if !l.is_empty() && l.chars().rev().next().unwrap() == '\n' {
|
if l.chars().last() == Some('\n') {
|
||||||
l.pop();
|
l.pop();
|
||||||
}
|
}
|
||||||
// Next we iterate through the individual chars to see if this
|
// Next we iterate through the individual chars to see if this
|
||||||
|
|
|
@ -17,6 +17,7 @@ path = "src/nohup.rs"
|
||||||
[dependencies]
|
[dependencies]
|
||||||
clap = "2.33"
|
clap = "2.33"
|
||||||
libc = "0.2.42"
|
libc = "0.2.42"
|
||||||
|
atty = "0.2"
|
||||||
uucore = { version=">=0.0.8", package="uucore", path="../../uucore", features=["fs"] }
|
uucore = { version=">=0.0.8", package="uucore", path="../../uucore", features=["fs"] }
|
||||||
uucore_procs = { version=">=0.0.5", package="uucore_procs", path="../../uucore_procs" }
|
uucore_procs = { version=">=0.0.5", package="uucore_procs", path="../../uucore_procs" }
|
||||||
|
|
||||||
|
|
|
@ -19,7 +19,6 @@ use std::fs::{File, OpenOptions};
|
||||||
use std::io::Error;
|
use std::io::Error;
|
||||||
use std::os::unix::prelude::*;
|
use std::os::unix::prelude::*;
|
||||||
use std::path::{Path, PathBuf};
|
use std::path::{Path, PathBuf};
|
||||||
use uucore::fs::{is_stderr_interactive, is_stdin_interactive, is_stdout_interactive};
|
|
||||||
use uucore::InvalidEncodingHandling;
|
use uucore::InvalidEncodingHandling;
|
||||||
|
|
||||||
static ABOUT: &str = "Run COMMAND ignoring hangup signals.";
|
static ABOUT: &str = "Run COMMAND ignoring hangup signals.";
|
||||||
|
@ -84,7 +83,7 @@ pub fn uumain(args: impl uucore::Args) -> i32 {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn replace_fds() {
|
fn replace_fds() {
|
||||||
if is_stdin_interactive() {
|
if atty::is(atty::Stream::Stdin) {
|
||||||
let new_stdin = match File::open(Path::new("/dev/null")) {
|
let new_stdin = match File::open(Path::new("/dev/null")) {
|
||||||
Ok(t) => t,
|
Ok(t) => t,
|
||||||
Err(e) => crash!(2, "Cannot replace STDIN: {}", e),
|
Err(e) => crash!(2, "Cannot replace STDIN: {}", e),
|
||||||
|
@ -94,7 +93,7 @@ fn replace_fds() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if is_stdout_interactive() {
|
if atty::is(atty::Stream::Stdout) {
|
||||||
let new_stdout = find_stdout();
|
let new_stdout = find_stdout();
|
||||||
let fd = new_stdout.as_raw_fd();
|
let fd = new_stdout.as_raw_fd();
|
||||||
|
|
||||||
|
@ -103,7 +102,7 @@ fn replace_fds() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if is_stderr_interactive() && unsafe { dup2(1, 2) } != 2 {
|
if atty::is(atty::Stream::Stderr) && unsafe { dup2(1, 2) } != 2 {
|
||||||
crash!(2, "Cannot replace STDERR: {}", Error::last_os_error())
|
crash!(2, "Cannot replace STDERR: {}", Error::last_os_error())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -275,17 +275,13 @@ fn parse_type_string(params: &str) -> Result<Vec<ParsedFormatterItemInfo>, Strin
|
||||||
let mut chars = params.chars();
|
let mut chars = params.chars();
|
||||||
let mut ch = chars.next();
|
let mut ch = chars.next();
|
||||||
|
|
||||||
while ch.is_some() {
|
while let Some(type_char) = ch {
|
||||||
let type_char = ch.unwrap();
|
let type_char = format_type(type_char).ok_or_else(|| {
|
||||||
let type_char = match format_type(type_char) {
|
format!(
|
||||||
Some(t) => t,
|
"unexpected char '{}' in format specification '{}'",
|
||||||
None => {
|
type_char, params
|
||||||
return Err(format!(
|
)
|
||||||
"unexpected char '{}' in format specification '{}'",
|
})?;
|
||||||
type_char, params
|
|
||||||
));
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
let type_cat = format_type_category(type_char);
|
let type_cat = format_type_category(type_char);
|
||||||
|
|
||||||
|
@ -301,30 +297,25 @@ fn parse_type_string(params: &str) -> Result<Vec<ParsedFormatterItemInfo>, Strin
|
||||||
ch = chars.next();
|
ch = chars.next();
|
||||||
}
|
}
|
||||||
if !decimal_size.is_empty() {
|
if !decimal_size.is_empty() {
|
||||||
byte_size = match decimal_size.parse() {
|
byte_size = decimal_size.parse().map_err(|_| {
|
||||||
Err(_) => {
|
format!(
|
||||||
return Err(format!(
|
"invalid number '{}' in format specification '{}'",
|
||||||
"invalid number '{}' in format specification '{}'",
|
decimal_size, params
|
||||||
decimal_size, params
|
)
|
||||||
))
|
})?;
|
||||||
}
|
|
||||||
Ok(n) => n,
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if is_format_dump_char(ch, &mut show_ascii_dump) {
|
if is_format_dump_char(ch, &mut show_ascii_dump) {
|
||||||
ch = chars.next();
|
ch = chars.next();
|
||||||
}
|
}
|
||||||
|
|
||||||
match od_format_type(type_char, byte_size) {
|
let ft = od_format_type(type_char, byte_size).ok_or_else(|| {
|
||||||
Some(ft) => formats.push(ParsedFormatterItemInfo::new(ft, show_ascii_dump)),
|
format!(
|
||||||
None => {
|
"invalid size '{}' in format specification '{}'",
|
||||||
return Err(format!(
|
byte_size, params
|
||||||
"invalid size '{}' in format specification '{}'",
|
)
|
||||||
byte_size, params
|
})?;
|
||||||
))
|
formats.push(ParsedFormatterItemInfo::new(ft, show_ascii_dump));
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(formats)
|
Ok(formats)
|
||||||
|
@ -335,16 +326,13 @@ pub fn parse_format_flags_str(
|
||||||
args_str: &Vec<&'static str>,
|
args_str: &Vec<&'static str>,
|
||||||
) -> Result<Vec<FormatterItemInfo>, String> {
|
) -> Result<Vec<FormatterItemInfo>, String> {
|
||||||
let args: Vec<String> = args_str.iter().map(|s| s.to_string()).collect();
|
let args: Vec<String> = args_str.iter().map(|s| s.to_string()).collect();
|
||||||
match parse_format_flags(&args) {
|
parse_format_flags(&args).map(|v| {
|
||||||
Err(e) => Err(e),
|
// tests using this function assume add_ascii_dump is not set
|
||||||
Ok(v) => {
|
v.into_iter()
|
||||||
// tests using this function assume add_ascii_dump is not set
|
.inspect(|f| assert!(!f.add_ascii_dump))
|
||||||
Ok(v.into_iter()
|
.map(|f| f.formatter_item_info)
|
||||||
.inspect(|f| assert!(!f.add_ascii_dump))
|
.collect()
|
||||||
.map(|f| f.formatter_item_info)
|
})
|
||||||
.collect())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
|
|
@ -241,13 +241,14 @@ fn no_leading_hyphen(path_segment: &str) -> bool {
|
||||||
|
|
||||||
// check whether a path segment contains only valid (read: portable) characters
|
// check whether a path segment contains only valid (read: portable) characters
|
||||||
fn check_portable_chars(path_segment: &str) -> bool {
|
fn check_portable_chars(path_segment: &str) -> bool {
|
||||||
let valid_str = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789._-".to_string();
|
const VALID_CHARS: &[u8] = b"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789._-";
|
||||||
for ch in path_segment.chars() {
|
for (i, ch) in path_segment.as_bytes().iter().enumerate() {
|
||||||
if !valid_str.contains(ch) {
|
if !VALID_CHARS.contains(ch) {
|
||||||
|
let invalid = path_segment[i..].chars().next().unwrap();
|
||||||
writeln!(
|
writeln!(
|
||||||
&mut std::io::stderr(),
|
&mut std::io::stderr(),
|
||||||
"nonportable character '{}' in file name component '{}'",
|
"nonportable character '{}' in file name component '{}'",
|
||||||
ch,
|
invalid,
|
||||||
path_segment
|
path_segment
|
||||||
);
|
);
|
||||||
return false;
|
return false;
|
||||||
|
|
|
@ -401,18 +401,18 @@ pub fn uumain(args: impl uucore::Args) -> i32 {
|
||||||
|
|
||||||
for file_group in file_groups {
|
for file_group in file_groups {
|
||||||
let result_options = build_options(&matches, &file_group, args.join(" "));
|
let result_options = build_options(&matches, &file_group, args.join(" "));
|
||||||
|
let options = match result_options {
|
||||||
|
Ok(options) => options,
|
||||||
|
Err(err) => {
|
||||||
|
print_error(&matches, err);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
if result_options.is_err() {
|
let cmd_result = if let Ok(group) = file_group.iter().exactly_one() {
|
||||||
print_error(&matches, result_options.err().unwrap());
|
pr(group, &options)
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
let options = &result_options.unwrap();
|
|
||||||
|
|
||||||
let cmd_result = if file_group.len() == 1 {
|
|
||||||
pr(file_group.get(0).unwrap(), options)
|
|
||||||
} else {
|
} else {
|
||||||
mpr(&file_group, options)
|
mpr(&file_group, &options)
|
||||||
};
|
};
|
||||||
|
|
||||||
let status = match cmd_result {
|
let status = match cmd_result {
|
||||||
|
@ -442,11 +442,12 @@ fn recreate_arguments(args: &[String]) -> Vec<String> {
|
||||||
let mut arguments = args.to_owned();
|
let mut arguments = args.to_owned();
|
||||||
let num_option = args.iter().find_position(|x| n_regex.is_match(x.trim()));
|
let num_option = args.iter().find_position(|x| n_regex.is_match(x.trim()));
|
||||||
if let Some((pos, _value)) = num_option {
|
if let Some((pos, _value)) = num_option {
|
||||||
let num_val_opt = args.get(pos + 1);
|
if let Some(num_val_opt) = args.get(pos + 1) {
|
||||||
if num_val_opt.is_some() && !num_regex.is_match(num_val_opt.unwrap()) {
|
if !num_regex.is_match(num_val_opt) {
|
||||||
let could_be_file = arguments.remove(pos + 1);
|
let could_be_file = arguments.remove(pos + 1);
|
||||||
arguments.insert(pos + 1, format!("{}", NumberingMode::default().width));
|
arguments.insert(pos + 1, format!("{}", NumberingMode::default().width));
|
||||||
arguments.insert(pos + 2, could_be_file);
|
arguments.insert(pos + 2, could_be_file);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -666,12 +667,14 @@ fn build_options(
|
||||||
None => end_page_in_plus_option,
|
None => end_page_in_plus_option,
|
||||||
};
|
};
|
||||||
|
|
||||||
if end_page.is_some() && start_page > end_page.unwrap() {
|
if let Some(end_page) = end_page {
|
||||||
return Err(PrError::EncounteredErrors(format!(
|
if start_page > end_page {
|
||||||
"invalid --pages argument '{}:{}'",
|
return Err(PrError::EncounteredErrors(format!(
|
||||||
start_page,
|
"invalid --pages argument '{}:{}'",
|
||||||
end_page.unwrap()
|
start_page,
|
||||||
)));
|
end_page
|
||||||
|
)));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let default_lines_per_page = if form_feed_used {
|
let default_lines_per_page = if form_feed_used {
|
||||||
|
@ -947,7 +950,7 @@ fn read_stream_and_create_pages(
|
||||||
let current_page = x + 1;
|
let current_page = x + 1;
|
||||||
|
|
||||||
current_page >= start_page
|
current_page >= start_page
|
||||||
&& (last_page.is_none() || current_page <= last_page.unwrap())
|
&& last_page.map_or(true, |last_page| current_page <= last_page)
|
||||||
}),
|
}),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
@ -1030,8 +1033,7 @@ fn print_page(lines: &[FileLine], options: &OutputOptions, page: usize) -> Resul
|
||||||
|
|
||||||
let lines_written = write_columns(lines, options, out)?;
|
let lines_written = write_columns(lines, options, out)?;
|
||||||
|
|
||||||
for index in 0..trailer_content.len() {
|
for (index, x) in trailer_content.iter().enumerate() {
|
||||||
let x = trailer_content.get(index).unwrap();
|
|
||||||
out.write_all(x.as_bytes())?;
|
out.write_all(x.as_bytes())?;
|
||||||
if index + 1 != trailer_content.len() {
|
if index + 1 != trailer_content.len() {
|
||||||
out.write_all(line_separator)?;
|
out.write_all(line_separator)?;
|
||||||
|
@ -1074,8 +1076,7 @@ fn write_columns(
|
||||||
let mut offset = 0;
|
let mut offset = 0;
|
||||||
for col in 0..columns {
|
for col in 0..columns {
|
||||||
let mut inserted = 0;
|
let mut inserted = 0;
|
||||||
for i in offset..lines.len() {
|
for line in &lines[offset..] {
|
||||||
let line = lines.get(i).unwrap();
|
|
||||||
if line.file_id != col {
|
if line.file_id != col {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
|
@ -55,18 +55,9 @@ impl Formatter for Decf {
|
||||||
);
|
);
|
||||||
// strip trailing zeroes
|
// strip trailing zeroes
|
||||||
if let Some(ref post_dec) = f_sci.post_decimal {
|
if let Some(ref post_dec) = f_sci.post_decimal {
|
||||||
let mut i = post_dec.len();
|
let trimmed = post_dec.trim_end_matches('0');
|
||||||
{
|
if trimmed.len() != post_dec.len() {
|
||||||
let mut it = post_dec.chars();
|
f_sci.post_decimal = Some(trimmed.to_owned());
|
||||||
while let Some(c) = it.next_back() {
|
|
||||||
if c != '0' {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
i -= 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if i != post_dec.len() {
|
|
||||||
f_sci.post_decimal = Some(String::from(&post_dec[0..i]));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
let f_fl = get_primitive_dec(
|
let f_fl = get_primitive_dec(
|
||||||
|
|
|
@ -247,8 +247,12 @@ pub fn get_primitive_dec(
|
||||||
first_segment.len() as isize - 1,
|
first_segment.len() as isize - 1,
|
||||||
)
|
)
|
||||||
} else {
|
} else {
|
||||||
match first_segment.chars().next() {
|
match first_segment
|
||||||
Some('0') => {
|
.chars()
|
||||||
|
.next()
|
||||||
|
.expect("float_common: no chars in first segment.")
|
||||||
|
{
|
||||||
|
'0' => {
|
||||||
let it = second_segment.chars().enumerate();
|
let it = second_segment.chars().enumerate();
|
||||||
let mut m: isize = 0;
|
let mut m: isize = 0;
|
||||||
let mut pre = String::from("0");
|
let mut pre = String::from("0");
|
||||||
|
@ -266,10 +270,7 @@ pub fn get_primitive_dec(
|
||||||
}
|
}
|
||||||
(pre, post, m)
|
(pre, post, m)
|
||||||
}
|
}
|
||||||
Some(_) => (first_segment, second_segment, 0),
|
_ => (first_segment, second_segment, 0),
|
||||||
None => {
|
|
||||||
panic!("float_common: no chars in first segment.");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -24,7 +24,7 @@ extern crate uucore;
|
||||||
|
|
||||||
static NAME: &str = "shred";
|
static NAME: &str = "shred";
|
||||||
const BLOCK_SIZE: usize = 512;
|
const BLOCK_SIZE: usize = 512;
|
||||||
const NAME_CHARSET: &str = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_.";
|
const NAME_CHARSET: &[u8] = b"0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_.";
|
||||||
|
|
||||||
// Patterns as shown in the GNU coreutils shred implementation
|
// Patterns as shown in the GNU coreutils shred implementation
|
||||||
const PATTERNS: [&[u8]; 22] = [
|
const PATTERNS: [&[u8]; 22] = [
|
||||||
|
@ -89,7 +89,7 @@ impl Iterator for FilenameGenerator {
|
||||||
// Make the return value, then increment
|
// Make the return value, then increment
|
||||||
let mut ret = String::new();
|
let mut ret = String::new();
|
||||||
for i in name_charset_indices.iter() {
|
for i in name_charset_indices.iter() {
|
||||||
let c: char = NAME_CHARSET.chars().nth(*i).unwrap();
|
let c = char::from(NAME_CHARSET[*i]);
|
||||||
ret.push(c);
|
ret.push(c);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -163,16 +163,14 @@ impl<'a> BytesGenerator<'a> {
|
||||||
return None;
|
return None;
|
||||||
}
|
}
|
||||||
|
|
||||||
let this_block_size = {
|
let this_block_size = if !self.exact {
|
||||||
if !self.exact {
|
self.block_size
|
||||||
|
} else {
|
||||||
|
let bytes_left = self.total_bytes - self.bytes_generated.get();
|
||||||
|
if bytes_left >= self.block_size as u64 {
|
||||||
self.block_size
|
self.block_size
|
||||||
} else {
|
} else {
|
||||||
let bytes_left = self.total_bytes - self.bytes_generated.get();
|
(bytes_left % self.block_size as u64) as usize
|
||||||
if bytes_left >= self.block_size as u64 {
|
|
||||||
self.block_size
|
|
||||||
} else {
|
|
||||||
(bytes_left % self.block_size as u64) as usize
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -184,12 +182,10 @@ impl<'a> BytesGenerator<'a> {
|
||||||
rng.fill(bytes);
|
rng.fill(bytes);
|
||||||
}
|
}
|
||||||
PassType::Pattern(pattern) => {
|
PassType::Pattern(pattern) => {
|
||||||
let skip = {
|
let skip = if self.bytes_generated.get() == 0 {
|
||||||
if self.bytes_generated.get() == 0 {
|
0
|
||||||
0
|
} else {
|
||||||
} else {
|
(pattern.len() as u64 % self.bytes_generated.get()) as usize
|
||||||
(pattern.len() as u64 % self.bytes_generated.get()) as usize
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// Copy the pattern in chunks rather than simply one byte at a time
|
// Copy the pattern in chunks rather than simply one byte at a time
|
||||||
|
|
|
@ -174,7 +174,7 @@ pub fn uumain(args: impl uucore::Args) -> i32 {
|
||||||
match matches.value_of(options::LINES) {
|
match matches.value_of(options::LINES) {
|
||||||
Some(n) => {
|
Some(n) => {
|
||||||
let mut slice: &str = n;
|
let mut slice: &str = n;
|
||||||
if slice.chars().next().unwrap_or('_') == '+' {
|
if slice.as_bytes().first() == Some(&b'+') {
|
||||||
settings.beginning = true;
|
settings.beginning = true;
|
||||||
slice = &slice[1..];
|
slice = &slice[1..];
|
||||||
}
|
}
|
||||||
|
@ -189,7 +189,7 @@ pub fn uumain(args: impl uucore::Args) -> i32 {
|
||||||
None => {
|
None => {
|
||||||
if let Some(n) = matches.value_of(options::BYTES) {
|
if let Some(n) = matches.value_of(options::BYTES) {
|
||||||
let mut slice: &str = n;
|
let mut slice: &str = n;
|
||||||
if slice.chars().next().unwrap_or('_') == '+' {
|
if slice.as_bytes().first() == Some(&b'+') {
|
||||||
settings.beginning = true;
|
settings.beginning = true;
|
||||||
slice = &slice[1..];
|
slice = &slice[1..];
|
||||||
}
|
}
|
||||||
|
@ -305,41 +305,35 @@ impl ParseSizeErr {
|
||||||
pub type ParseSizeResult = Result<u64, ParseSizeErr>;
|
pub type ParseSizeResult = Result<u64, ParseSizeErr>;
|
||||||
|
|
||||||
pub fn parse_size(mut size_slice: &str) -> Result<u64, ParseSizeErr> {
|
pub fn parse_size(mut size_slice: &str) -> Result<u64, ParseSizeErr> {
|
||||||
let mut base = if size_slice.chars().last().unwrap_or('_') == 'B' {
|
let mut base = if size_slice.as_bytes().last() == Some(&b'B') {
|
||||||
size_slice = &size_slice[..size_slice.len() - 1];
|
size_slice = &size_slice[..size_slice.len() - 1];
|
||||||
1000u64
|
1000u64
|
||||||
} else {
|
} else {
|
||||||
1024u64
|
1024u64
|
||||||
};
|
};
|
||||||
|
|
||||||
let exponent = if !size_slice.is_empty() {
|
let exponent = match size_slice.as_bytes().last() {
|
||||||
let mut has_suffix = true;
|
Some(unit) => match unit {
|
||||||
let exp = match size_slice.chars().last().unwrap_or('_') {
|
b'K' | b'k' => 1u64,
|
||||||
'K' | 'k' => 1u64,
|
b'M' => 2u64,
|
||||||
'M' => 2u64,
|
b'G' => 3u64,
|
||||||
'G' => 3u64,
|
b'T' => 4u64,
|
||||||
'T' => 4u64,
|
b'P' => 5u64,
|
||||||
'P' => 5u64,
|
b'E' => 6u64,
|
||||||
'E' => 6u64,
|
b'Z' | b'Y' => {
|
||||||
'Z' | 'Y' => {
|
|
||||||
return Err(ParseSizeErr::size_too_big(size_slice));
|
return Err(ParseSizeErr::size_too_big(size_slice));
|
||||||
}
|
}
|
||||||
'b' => {
|
b'b' => {
|
||||||
base = 512u64;
|
base = 512u64;
|
||||||
1u64
|
1u64
|
||||||
}
|
}
|
||||||
_ => {
|
_ => 0u64,
|
||||||
has_suffix = false;
|
},
|
||||||
0u64
|
None => 0u64,
|
||||||
}
|
|
||||||
};
|
|
||||||
if has_suffix {
|
|
||||||
size_slice = &size_slice[..size_slice.len() - 1];
|
|
||||||
}
|
|
||||||
exp
|
|
||||||
} else {
|
|
||||||
0u64
|
|
||||||
};
|
};
|
||||||
|
if exponent != 0 {
|
||||||
|
size_slice = &size_slice[..size_slice.len() - 1];
|
||||||
|
}
|
||||||
|
|
||||||
let mut multiplier = 1u64;
|
let mut multiplier = 1u64;
|
||||||
for _ in 0u64..exponent {
|
for _ in 0u64..exponent {
|
||||||
|
|
|
@ -16,7 +16,6 @@ path = "src/timeout.rs"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
clap = "2.33"
|
clap = "2.33"
|
||||||
getopts = "0.2.18"
|
|
||||||
libc = "0.2.42"
|
libc = "0.2.42"
|
||||||
uucore = { version=">=0.0.8", package="uucore", path="../../uucore", features=["parse_time", "process", "signals"] }
|
uucore = { version=">=0.0.8", package="uucore", path="../../uucore", features=["parse_time", "process", "signals"] }
|
||||||
uucore_procs = { version=">=0.0.5", package="uucore_procs", path="../../uucore_procs" }
|
uucore_procs = { version=">=0.0.5", package="uucore_procs", path="../../uucore_procs" }
|
||||||
|
|
|
@ -22,14 +22,15 @@ use std::ops::RangeInclusive;
|
||||||
/// character; octal escape sequences consume 1 to 3 octal digits.
|
/// character; octal escape sequences consume 1 to 3 octal digits.
|
||||||
#[inline]
|
#[inline]
|
||||||
fn parse_sequence(s: &str) -> (char, usize) {
|
fn parse_sequence(s: &str) -> (char, usize) {
|
||||||
let c = s.chars().next().expect("invalid escape: empty string");
|
let mut s = s.chars();
|
||||||
|
let c = s.next().expect("invalid escape: empty string");
|
||||||
|
|
||||||
if ('0'..='7').contains(&c) {
|
if ('0'..='7').contains(&c) {
|
||||||
let mut v = c.to_digit(8).unwrap();
|
let mut v = c.to_digit(8).unwrap();
|
||||||
let mut consumed = 1;
|
let mut consumed = 1;
|
||||||
let bits_per_digit = 3;
|
let bits_per_digit = 3;
|
||||||
|
|
||||||
for c in s.chars().skip(1).take(2) {
|
for c in s.take(2) {
|
||||||
match c.to_digit(8) {
|
match c.to_digit(8) {
|
||||||
Some(c) => {
|
Some(c) => {
|
||||||
v = (v << bits_per_digit) | c;
|
v = (v << bits_per_digit) | c;
|
||||||
|
|
|
@ -363,10 +363,7 @@ fn parse_size(size: &str) -> Result<u64, ()> {
|
||||||
// Get the numeric part of the size argument. For example, if the
|
// Get the numeric part of the size argument. For example, if the
|
||||||
// argument is "123K", then the numeric part is "123".
|
// argument is "123K", then the numeric part is "123".
|
||||||
let numeric_string: String = size.chars().take_while(|c| c.is_digit(10)).collect();
|
let numeric_string: String = size.chars().take_while(|c| c.is_digit(10)).collect();
|
||||||
let number: u64 = match numeric_string.parse() {
|
let number: u64 = numeric_string.parse().map_err(|_| ())?;
|
||||||
Ok(n) => n,
|
|
||||||
Err(_) => return Err(()),
|
|
||||||
};
|
|
||||||
|
|
||||||
// Get the alphabetic units part of the size argument and compute
|
// Get the alphabetic units part of the size argument and compute
|
||||||
// the factor it represents. For example, if the argument is "123K",
|
// the factor it represents. For example, if the argument is "123K",
|
||||||
|
|
|
@ -17,6 +17,7 @@ path = "src/tty.rs"
|
||||||
[dependencies]
|
[dependencies]
|
||||||
clap = "2.33"
|
clap = "2.33"
|
||||||
libc = "0.2.42"
|
libc = "0.2.42"
|
||||||
|
atty = "0.2"
|
||||||
uucore = { version=">=0.0.8", package="uucore", path="../../uucore", features=["fs"] }
|
uucore = { version=">=0.0.8", package="uucore", path="../../uucore", features=["fs"] }
|
||||||
uucore_procs = { version=">=0.0.5", package="uucore_procs", path="../../uucore_procs" }
|
uucore_procs = { version=">=0.0.5", package="uucore_procs", path="../../uucore_procs" }
|
||||||
|
|
||||||
|
|
|
@ -14,7 +14,6 @@ extern crate uucore;
|
||||||
|
|
||||||
use clap::{crate_version, App, Arg};
|
use clap::{crate_version, App, Arg};
|
||||||
use std::ffi::CStr;
|
use std::ffi::CStr;
|
||||||
use uucore::fs::is_stdin_interactive;
|
|
||||||
use uucore::InvalidEncodingHandling;
|
use uucore::InvalidEncodingHandling;
|
||||||
|
|
||||||
static ABOUT: &str = "Print the file name of the terminal connected to standard input.";
|
static ABOUT: &str = "Print the file name of the terminal connected to standard input.";
|
||||||
|
@ -67,7 +66,7 @@ pub fn uumain(args: impl uucore::Args) -> i32 {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if is_stdin_interactive() {
|
if atty::is(atty::Stream::Stdin) {
|
||||||
libc::EXIT_SUCCESS
|
libc::EXIT_SUCCESS
|
||||||
} else {
|
} else {
|
||||||
libc::EXIT_FAILURE
|
libc::EXIT_FAILURE
|
||||||
|
|
|
@ -179,124 +179,58 @@ pub fn uumain(args: impl uucore::Args) -> i32 {
|
||||||
// Ignored for 'who am i'.
|
// Ignored for 'who am i'.
|
||||||
let short_list = matches.is_present(options::COUNT);
|
let short_list = matches.is_present(options::COUNT);
|
||||||
|
|
||||||
// If true, display only name, line, and time fields.
|
let all = matches.is_present(options::ALL);
|
||||||
let mut short_output = false;
|
|
||||||
|
|
||||||
// If true, display the hours:minutes since each user has touched
|
|
||||||
// the keyboard, or "." if within the last minute, or "old" if
|
|
||||||
// not within the last day.
|
|
||||||
let mut include_idle = false;
|
|
||||||
|
|
||||||
// If true, display a line at the top describing each field.
|
// If true, display a line at the top describing each field.
|
||||||
let include_heading = matches.is_present(options::HEADING);
|
let include_heading = matches.is_present(options::HEADING);
|
||||||
|
|
||||||
// If true, display a '+' for each user if mesg y, a '-' if mesg n,
|
// If true, display a '+' for each user if mesg y, a '-' if mesg n,
|
||||||
// or a '?' if their tty cannot be statted.
|
// or a '?' if their tty cannot be statted.
|
||||||
let include_mesg = matches.is_present(options::ALL)
|
let include_mesg = all || matches.is_present(options::MESG) || matches.is_present("w");
|
||||||
|| matches.is_present(options::MESG)
|
|
||||||
|| matches.is_present("w");
|
|
||||||
|
|
||||||
// If true, display process termination & exit status.
|
|
||||||
let mut include_exit = false;
|
|
||||||
|
|
||||||
// If true, display the last boot time.
|
// If true, display the last boot time.
|
||||||
let mut need_boottime = false;
|
let need_boottime = all || matches.is_present(options::BOOT);
|
||||||
|
|
||||||
// If true, display dead processes.
|
// If true, display dead processes.
|
||||||
let mut need_deadprocs = false;
|
let need_deadprocs = all || matches.is_present(options::DEAD);
|
||||||
|
|
||||||
// If true, display processes waiting for user login.
|
// If true, display processes waiting for user login.
|
||||||
let mut need_login = false;
|
let need_login = all || matches.is_present(options::LOGIN);
|
||||||
|
|
||||||
// If true, display processes started by init.
|
// If true, display processes started by init.
|
||||||
let mut need_initspawn = false;
|
let need_initspawn = all || matches.is_present(options::PROCESS);
|
||||||
|
|
||||||
// If true, display the last clock change.
|
// If true, display the last clock change.
|
||||||
let mut need_clockchange = false;
|
let need_clockchange = all || matches.is_present(options::TIME);
|
||||||
|
|
||||||
// If true, display the current runlevel.
|
// If true, display the current runlevel.
|
||||||
let mut need_runlevel = false;
|
let need_runlevel = all || matches.is_present(options::RUNLEVEL);
|
||||||
|
|
||||||
|
let use_defaults = !(all
|
||||||
|
|| need_boottime
|
||||||
|
|| need_deadprocs
|
||||||
|
|| need_login
|
||||||
|
|| need_initspawn
|
||||||
|
|| need_runlevel
|
||||||
|
|| need_clockchange
|
||||||
|
|| matches.is_present(options::USERS));
|
||||||
|
|
||||||
// If true, display user processes.
|
// If true, display user processes.
|
||||||
let mut need_users = false;
|
let need_users = all || matches.is_present(options::USERS) || use_defaults;
|
||||||
|
|
||||||
|
// If true, display the hours:minutes since each user has touched
|
||||||
|
// the keyboard, or "." if within the last minute, or "old" if
|
||||||
|
// not within the last day.
|
||||||
|
let include_idle = need_deadprocs || need_login || need_runlevel || need_users;
|
||||||
|
|
||||||
|
// If true, display process termination & exit status.
|
||||||
|
let include_exit = need_deadprocs;
|
||||||
|
|
||||||
|
// If true, display only name, line, and time fields.
|
||||||
|
let short_output = !include_exit && use_defaults;
|
||||||
|
|
||||||
// If true, display info only for the controlling tty.
|
// If true, display info only for the controlling tty.
|
||||||
let mut my_line_only = false;
|
let my_line_only = matches.is_present(options::ONLY_HOSTNAME_USER) || files.len() == 2;
|
||||||
|
|
||||||
let mut assumptions = true;
|
|
||||||
|
|
||||||
#[allow(clippy::useless_let_if_seq)]
|
|
||||||
{
|
|
||||||
if matches.is_present(options::ALL) {
|
|
||||||
need_boottime = true;
|
|
||||||
need_deadprocs = true;
|
|
||||||
need_login = true;
|
|
||||||
need_initspawn = true;
|
|
||||||
need_runlevel = true;
|
|
||||||
need_clockchange = true;
|
|
||||||
need_users = true;
|
|
||||||
include_idle = true;
|
|
||||||
include_exit = true;
|
|
||||||
assumptions = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if matches.is_present(options::BOOT) {
|
|
||||||
need_boottime = true;
|
|
||||||
assumptions = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if matches.is_present(options::DEAD) {
|
|
||||||
need_deadprocs = true;
|
|
||||||
include_idle = true;
|
|
||||||
include_exit = true;
|
|
||||||
assumptions = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if matches.is_present(options::LOGIN) {
|
|
||||||
need_login = true;
|
|
||||||
include_idle = true;
|
|
||||||
assumptions = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if matches.is_present(options::ONLY_HOSTNAME_USER) || files.len() == 2 {
|
|
||||||
my_line_only = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
if matches.is_present(options::PROCESS) {
|
|
||||||
need_initspawn = true;
|
|
||||||
assumptions = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if matches.is_present(options::RUNLEVEL) {
|
|
||||||
need_runlevel = true;
|
|
||||||
include_idle = true;
|
|
||||||
assumptions = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if matches.is_present(options::SHORT) {
|
|
||||||
short_output = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
if matches.is_present(options::TIME) {
|
|
||||||
need_clockchange = true;
|
|
||||||
assumptions = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if matches.is_present(options::USERS) {
|
|
||||||
need_users = true;
|
|
||||||
include_idle = true;
|
|
||||||
assumptions = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if assumptions {
|
|
||||||
need_users = true;
|
|
||||||
short_output = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
if include_exit {
|
|
||||||
short_output = false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
let mut who = Who {
|
let mut who = Who {
|
||||||
do_lookup,
|
do_lookup,
|
||||||
|
|
|
@ -20,7 +20,6 @@ uucore = { version=">=0.0.8", package="uucore", path="../../uucore", features=["
|
||||||
uucore_procs = { version=">=0.0.5", package="uucore_procs", path="../../uucore_procs" }
|
uucore_procs = { version=">=0.0.5", package="uucore_procs", path="../../uucore_procs" }
|
||||||
|
|
||||||
[target.'cfg(target_os = "windows")'.dependencies]
|
[target.'cfg(target_os = "windows")'.dependencies]
|
||||||
advapi32-sys = "0.2.0"
|
|
||||||
winapi = { version = "0.3", features = ["lmcons"] }
|
winapi = { version = "0.3", features = ["lmcons"] }
|
||||||
|
|
||||||
[[bin]]
|
[[bin]]
|
||||||
|
|
|
@ -11,7 +11,7 @@ extern crate winapi;
|
||||||
|
|
||||||
use self::winapi::shared::lmcons;
|
use self::winapi::shared::lmcons;
|
||||||
use self::winapi::shared::minwindef;
|
use self::winapi::shared::minwindef;
|
||||||
use self::winapi::um::winnt;
|
use self::winapi::um::{winbase, winnt};
|
||||||
use std::io::{Error, Result};
|
use std::io::{Error, Result};
|
||||||
use std::mem;
|
use std::mem;
|
||||||
use uucore::wide::FromWide;
|
use uucore::wide::FromWide;
|
||||||
|
@ -20,7 +20,7 @@ pub unsafe fn get_username() -> Result<String> {
|
||||||
#[allow(deprecated)]
|
#[allow(deprecated)]
|
||||||
let mut buffer: [winnt::WCHAR; lmcons::UNLEN as usize + 1] = mem::uninitialized();
|
let mut buffer: [winnt::WCHAR; lmcons::UNLEN as usize + 1] = mem::uninitialized();
|
||||||
let mut len = buffer.len() as minwindef::DWORD;
|
let mut len = buffer.len() as minwindef::DWORD;
|
||||||
if advapi32::GetUserNameW(buffer.as_mut_ptr(), &mut len) == 0 {
|
if winbase::GetUserNameW(buffer.as_mut_ptr(), &mut len) == 0 {
|
||||||
return Err(Error::last_os_error());
|
return Err(Error::last_os_error());
|
||||||
}
|
}
|
||||||
let username = String::from_wide(&buffer[..len as usize - 1]);
|
let username = String::from_wide(&buffer[..len as usize - 1]);
|
||||||
|
|
|
@ -94,16 +94,20 @@ pub fn get_groups() -> IOResult<Vec<gid_t>> {
|
||||||
/// groups is the same (in the mathematical sense of ``set''). (The
|
/// groups is the same (in the mathematical sense of ``set''). (The
|
||||||
/// history of a process and its parents could affect the details of
|
/// history of a process and its parents could affect the details of
|
||||||
/// the result.)
|
/// the result.)
|
||||||
|
#[cfg(all(unix, feature = "process"))]
|
||||||
pub fn get_groups_gnu(arg_id: Option<u32>) -> IOResult<Vec<gid_t>> {
|
pub fn get_groups_gnu(arg_id: Option<u32>) -> IOResult<Vec<gid_t>> {
|
||||||
let mut groups = get_groups()?;
|
let groups = get_groups()?;
|
||||||
let egid = arg_id.unwrap_or_else(crate::features::process::getegid);
|
let egid = arg_id.unwrap_or_else(crate::features::process::getegid);
|
||||||
if !groups.is_empty() && *groups.first().unwrap() == egid {
|
Ok(sort_groups(groups, egid))
|
||||||
return Ok(groups);
|
}
|
||||||
} else if let Some(index) = groups.iter().position(|&x| x == egid) {
|
|
||||||
groups.remove(index);
|
fn sort_groups(mut groups: Vec<gid_t>, egid: gid_t) -> Vec<gid_t> {
|
||||||
|
if let Some(index) = groups.iter().position(|&x| x == egid) {
|
||||||
|
groups[..=index].rotate_right(1);
|
||||||
|
} else {
|
||||||
|
groups.insert(0, egid);
|
||||||
}
|
}
|
||||||
groups.insert(0, egid);
|
groups
|
||||||
Ok(groups)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Copy, Clone)]
|
#[derive(Copy, Clone)]
|
||||||
|
@ -308,6 +312,15 @@ pub fn grp2gid(name: &str) -> IOResult<gid_t> {
|
||||||
mod test {
|
mod test {
|
||||||
use super::*;
|
use super::*;
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_sort_groups() {
|
||||||
|
assert_eq!(sort_groups(vec![1, 2, 3], 4), vec![4, 1, 2, 3]);
|
||||||
|
assert_eq!(sort_groups(vec![1, 2, 3], 3), vec![3, 1, 2]);
|
||||||
|
assert_eq!(sort_groups(vec![1, 2, 3], 2), vec![2, 1, 3]);
|
||||||
|
assert_eq!(sort_groups(vec![1, 2, 3], 1), vec![1, 2, 3]);
|
||||||
|
assert_eq!(sort_groups(vec![1, 2, 3], 0), vec![0, 1, 2, 3]);
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_entries_get_groups_gnu() {
|
fn test_entries_get_groups_gnu() {
|
||||||
if let Ok(mut groups) = get_groups() {
|
if let Ok(mut groups) = get_groups() {
|
||||||
|
|
|
@ -225,51 +225,6 @@ pub fn canonicalize<P: AsRef<Path>>(original: P, can_mode: CanonicalizeMode) ->
|
||||||
Ok(result)
|
Ok(result)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(unix)]
|
|
||||||
pub fn is_stdin_interactive() -> bool {
|
|
||||||
unsafe { libc::isatty(libc::STDIN_FILENO) == 1 }
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg(windows)]
|
|
||||||
pub fn is_stdin_interactive() -> bool {
|
|
||||||
false
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg(target_os = "redox")]
|
|
||||||
pub fn is_stdin_interactive() -> bool {
|
|
||||||
termion::is_tty(&io::stdin())
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg(unix)]
|
|
||||||
pub fn is_stdout_interactive() -> bool {
|
|
||||||
unsafe { libc::isatty(libc::STDOUT_FILENO) == 1 }
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg(windows)]
|
|
||||||
pub fn is_stdout_interactive() -> bool {
|
|
||||||
false
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg(target_os = "redox")]
|
|
||||||
pub fn is_stdout_interactive() -> bool {
|
|
||||||
termion::is_tty(&io::stdout())
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg(unix)]
|
|
||||||
pub fn is_stderr_interactive() -> bool {
|
|
||||||
unsafe { libc::isatty(libc::STDERR_FILENO) == 1 }
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg(windows)]
|
|
||||||
pub fn is_stderr_interactive() -> bool {
|
|
||||||
false
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg(target_os = "redox")]
|
|
||||||
pub fn is_stderr_interactive() -> bool {
|
|
||||||
termion::is_tty(&io::stderr())
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg(not(unix))]
|
#[cfg(not(unix))]
|
||||||
#[allow(unused_variables)]
|
#[allow(unused_variables)]
|
||||||
pub fn display_permissions(metadata: &fs::Metadata, display_file_type: bool) -> String {
|
pub fn display_permissions(metadata: &fs::Metadata, display_file_type: bool) -> String {
|
||||||
|
|
|
@ -312,3 +312,20 @@ fn _du_no_permission(s: &str) {
|
||||||
fn _du_no_permission(s: &str) {
|
fn _du_no_permission(s: &str) {
|
||||||
assert_eq!(s, "4\tsubdir/links\n");
|
assert_eq!(s, "4\tsubdir/links\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_du_one_file_system() {
|
||||||
|
let scene = TestScenario::new(util_name!());
|
||||||
|
|
||||||
|
let result = scene.ucmd().arg("-x").arg(SUB_DIR).succeeds();
|
||||||
|
|
||||||
|
#[cfg(target_os = "linux")]
|
||||||
|
{
|
||||||
|
let result_reference = scene.cmd("du").arg("-x").arg(SUB_DIR).run();
|
||||||
|
if result_reference.succeeded() {
|
||||||
|
assert_eq!(result.stdout_str(), result_reference.stdout_str());
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
_du_basics_subdir(result.stdout_str());
|
||||||
|
}
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
use crate::common::util::*;
|
use crate::common::util::*;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
#[cfg(any(target_vendor = "apple", target_os = "linux"))]
|
#[cfg(unix)]
|
||||||
fn test_groups() {
|
fn test_groups() {
|
||||||
if !is_ci() {
|
if !is_ci() {
|
||||||
new_ucmd!().succeeds().stdout_is(expected_result(&[]));
|
new_ucmd!().succeeds().stdout_is(expected_result(&[]));
|
||||||
|
@ -13,7 +13,7 @@ fn test_groups() {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
#[cfg(any(target_os = "linux"))]
|
#[cfg(unix)]
|
||||||
#[ignore = "fixme: 'groups USERNAME' needs more debugging"]
|
#[ignore = "fixme: 'groups USERNAME' needs more debugging"]
|
||||||
fn test_groups_username() {
|
fn test_groups_username() {
|
||||||
let scene = TestScenario::new(util_name!());
|
let scene = TestScenario::new(util_name!());
|
||||||
|
@ -37,17 +37,20 @@ fn test_groups_username() {
|
||||||
.stdout_is(expected_result(&[&username]));
|
.stdout_is(expected_result(&[&username]));
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(any(target_vendor = "apple", target_os = "linux"))]
|
#[cfg(unix)]
|
||||||
fn expected_result(args: &[&str]) -> String {
|
fn expected_result(args: &[&str]) -> String {
|
||||||
#[cfg(target_os = "linux")]
|
// We want to use GNU id. On most linux systems, this is "id", but on
|
||||||
let util_name = util_name!();
|
// bsd-like systems (e.g. FreeBSD, MacOS), it is commonly "gid".
|
||||||
#[cfg(target_vendor = "apple")]
|
#[cfg(any(target_os = "linux"))]
|
||||||
let util_name = format!("g{}", util_name!());
|
let util_name = "id";
|
||||||
|
#[cfg(not(target_os = "linux"))]
|
||||||
|
let util_name = "gid";
|
||||||
|
|
||||||
TestScenario::new(&util_name)
|
TestScenario::new(util_name)
|
||||||
.cmd_keepenv(util_name)
|
.cmd_keepenv(util_name)
|
||||||
.env("LANGUAGE", "C")
|
.env("LANGUAGE", "C")
|
||||||
.args(args)
|
.args(args)
|
||||||
|
.args(&["-Gn"])
|
||||||
.succeeds()
|
.succeeds()
|
||||||
.stdout_move_str()
|
.stdout_move_str()
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,12 +5,12 @@
|
||||||
set -e
|
set -e
|
||||||
if test ! -d ../gnu; then
|
if test ! -d ../gnu; then
|
||||||
echo "Could not find ../gnu"
|
echo "Could not find ../gnu"
|
||||||
echo "git clone git@github.com:coreutils/coreutils.git ../gnu"
|
echo "git clone git@github.com:coreutils/coreutils.git gnu"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
if test ! -d ../gnulib; then
|
if test ! -d ../gnulib; then
|
||||||
echo "Could not find ../gnulib"
|
echo "Could not find ../gnulib"
|
||||||
echo "git clone git@github.com:coreutils/gnulib.git ../gnulib"
|
echo "git clone git@github.com:coreutils/gnulib.git gnulib"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue