mirror of
https://github.com/uutils/coreutils.git
synced 2026-06-10 15:48:22 -07:00
cargo fmt
This commit is contained in:
@@ -16,8 +16,8 @@ pub fn main() {
|
||||
if val == "1" && key.starts_with(feature_prefix) {
|
||||
let krate = key[feature_prefix.len()..].to_lowercase();
|
||||
match krate.as_ref() {
|
||||
"default" | "unix" | "redox" | "redox_generic" | "fuchsia" | "generic" | "windows" | "windows_legacy"
|
||||
| "nightly" | "test_unimplemented" => continue,
|
||||
"default" | "unix" | "redox" | "redox_generic" | "fuchsia" | "generic"
|
||||
| "windows" | "windows_legacy" | "nightly" | "test_unimplemented" => continue,
|
||||
_ => {}
|
||||
}
|
||||
crates.push(krate.to_string());
|
||||
@@ -35,7 +35,8 @@ pub fn main() {
|
||||
fn util_map() -> UtilityMap {
|
||||
let mut map: UtilityMap = HashMap::new();\n"
|
||||
.as_bytes(),
|
||||
).unwrap();
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
for krate in crates {
|
||||
cf.write_all(format!("extern crate uu_{krate};\n", krate = krate).as_bytes())
|
||||
@@ -59,14 +60,18 @@ pub fn main() {
|
||||
map.insert(\"shake128sum\", uu_hashsum::uumain);
|
||||
map.insert(\"shake256sum\", uu_hashsum::uumain);\n"
|
||||
.as_bytes(),
|
||||
).unwrap();
|
||||
)
|
||||
.unwrap();
|
||||
}
|
||||
_ => mf.write_all(
|
||||
format!(
|
||||
"map.insert(\"{krate}\", uu_{krate}::uumain);\n",
|
||||
krate = krate
|
||||
).as_bytes(),
|
||||
).unwrap(),
|
||||
_ => mf
|
||||
.write_all(
|
||||
format!(
|
||||
"map.insert(\"{krate}\", uu_{krate}::uumain);\n",
|
||||
krate = krate
|
||||
)
|
||||
.as_bytes(),
|
||||
)
|
||||
.unwrap(),
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
use std::env;
|
||||
use std::io::Write;
|
||||
use std::fs::File;
|
||||
use std::io::Write;
|
||||
use std::path::Path;
|
||||
|
||||
static TEMPLATE: &'static str = "\
|
||||
|
||||
@@ -16,8 +16,7 @@ use uucore::encoding::Format;
|
||||
mod base_common;
|
||||
|
||||
static SYNTAX: &str = "[OPTION]... [FILE]";
|
||||
static SUMMARY: &str =
|
||||
"Base32 encode or decode FILE, or standard input, to standard output.";
|
||||
static SUMMARY: &str = "Base32 encode or decode FILE, or standard input, to standard output.";
|
||||
static LONG_HELP: &str = "
|
||||
With no FILE, or when FILE is -, read standard input.
|
||||
|
||||
|
||||
@@ -16,8 +16,7 @@ use uucore::encoding::Format;
|
||||
mod base_common;
|
||||
|
||||
static SYNTAX: &str = "[OPTION]... [FILE]";
|
||||
static SUMMARY: &str =
|
||||
"Base64 encode or decode FILE, or standard input, to standard output.";
|
||||
static SUMMARY: &str = "Base64 encode or decode FILE, or standard input, to standard output.";
|
||||
static LONG_HELP: &str = "
|
||||
With no FILE, or when FILE is -, read standard input.
|
||||
|
||||
|
||||
+14
-11
@@ -36,13 +36,11 @@ pub fn execute(
|
||||
"COLS",
|
||||
)
|
||||
.parse(args);
|
||||
|
||||
let line_wrap = matches.opt_str("wrap").map(|s| {
|
||||
match s.parse() {
|
||||
Ok(n) => n,
|
||||
Err(e) => {
|
||||
crash!(1, "invalid wrap size: ‘{}’: {}", s, e);
|
||||
}
|
||||
|
||||
let line_wrap = matches.opt_str("wrap").map(|s| match s.parse() {
|
||||
Ok(n) => n,
|
||||
Err(e) => {
|
||||
crash!(1, "invalid wrap size: ‘{}’: {}", s, e);
|
||||
}
|
||||
});
|
||||
let ignore_garbage = matches.opt_present("ignore-garbage");
|
||||
@@ -55,7 +53,13 @@ pub fn execute(
|
||||
|
||||
if matches.free.is_empty() || &matches.free[0][..] == "-" {
|
||||
let stdin_raw = stdin();
|
||||
handle_input(&mut stdin_raw.lock(), format, line_wrap, ignore_garbage, decode);
|
||||
handle_input(
|
||||
&mut stdin_raw.lock(),
|
||||
format,
|
||||
line_wrap,
|
||||
ignore_garbage,
|
||||
decode,
|
||||
);
|
||||
} else {
|
||||
let path = Path::new(matches.free[0].as_str());
|
||||
let file_buf = safe_unwrap!(File::open(&path));
|
||||
@@ -73,8 +77,7 @@ fn handle_input<R: Read>(
|
||||
ignore_garbage: bool,
|
||||
decode: bool,
|
||||
) {
|
||||
let mut data = Data::new(input, format)
|
||||
.ignore_garbage(ignore_garbage);
|
||||
let mut data = Data::new(input, format).ignore_garbage(ignore_garbage);
|
||||
if let Some(wrap) = line_wrap {
|
||||
data = data.line_wrap(wrap);
|
||||
}
|
||||
@@ -88,4 +91,4 @@ fn handle_input<R: Read>(
|
||||
Err(_) => crash!(1, "invalid input"),
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+23
-28
@@ -168,7 +168,10 @@ pub fn uumain(args: Vec<String>) -> i32 {
|
||||
files.push("-".to_owned());
|
||||
}
|
||||
|
||||
let can_write_fast = !(show_tabs || show_nonprint || show_ends || squeeze_blank
|
||||
let can_write_fast = !(show_tabs
|
||||
|| show_nonprint
|
||||
|| show_ends
|
||||
|| squeeze_blank
|
||||
|| number_mode != NumberingMode::None);
|
||||
|
||||
let success = if can_write_fast {
|
||||
@@ -190,7 +193,11 @@ pub fn uumain(args: Vec<String>) -> i32 {
|
||||
write_lines(files, &options).is_ok()
|
||||
};
|
||||
|
||||
if success { 0 } else { 1 }
|
||||
if success {
|
||||
0
|
||||
} else {
|
||||
1
|
||||
}
|
||||
}
|
||||
|
||||
/// Classifies the `InputType` of file at `path` if possible
|
||||
@@ -205,25 +212,13 @@ fn get_input_type(path: &str) -> CatResult<InputType> {
|
||||
|
||||
match metadata(path).context(path)?.file_type() {
|
||||
#[cfg(unix)]
|
||||
ft if ft.is_block_device() =>
|
||||
{
|
||||
Ok(InputType::BlockDevice)
|
||||
}
|
||||
ft if ft.is_block_device() => Ok(InputType::BlockDevice),
|
||||
#[cfg(unix)]
|
||||
ft if ft.is_char_device() =>
|
||||
{
|
||||
Ok(InputType::CharacterDevice)
|
||||
}
|
||||
ft if ft.is_char_device() => Ok(InputType::CharacterDevice),
|
||||
#[cfg(unix)]
|
||||
ft if ft.is_fifo() =>
|
||||
{
|
||||
Ok(InputType::Fifo)
|
||||
}
|
||||
ft if ft.is_fifo() => Ok(InputType::Fifo),
|
||||
#[cfg(unix)]
|
||||
ft if ft.is_socket() =>
|
||||
{
|
||||
Ok(InputType::Socket)
|
||||
}
|
||||
ft if ft.is_socket() => Ok(InputType::Socket),
|
||||
ft if ft.is_dir() => Ok(InputType::Directory),
|
||||
ft if ft.is_file() => Ok(InputType::File),
|
||||
ft if ft.is_symlink() => Ok(InputType::SymLink),
|
||||
@@ -282,12 +277,14 @@ fn write_fast(files: Vec<String>) -> CatResult<()> {
|
||||
|
||||
for file in files {
|
||||
match open(&file[..]) {
|
||||
Ok(mut handle) => while let Ok(n) = handle.reader.read(&mut in_buf) {
|
||||
if n == 0 {
|
||||
break;
|
||||
Ok(mut handle) => {
|
||||
while let Ok(n) = handle.reader.read(&mut in_buf) {
|
||||
if n == 0 {
|
||||
break;
|
||||
}
|
||||
writer.write_all(&in_buf[..n]).context(&file[..])?;
|
||||
}
|
||||
writer.write_all(&in_buf[..n]).context(&file[..])?;
|
||||
},
|
||||
}
|
||||
Err(error) => {
|
||||
writeln!(&mut stderr(), "{}", error)?;
|
||||
error_count += 1;
|
||||
@@ -421,10 +418,7 @@ fn write_to_end<W: Write>(in_buf: &[u8], writer: &mut W) -> usize {
|
||||
fn write_tab_to_end<W: Write>(mut in_buf: &[u8], writer: &mut W) -> usize {
|
||||
let mut count = 0;
|
||||
loop {
|
||||
match in_buf
|
||||
.iter()
|
||||
.position(|c| *c == b'\n' || *c == b'\t')
|
||||
{
|
||||
match in_buf.iter().position(|c| *c == b'\n' || *c == b'\t') {
|
||||
Some(p) => {
|
||||
writer.write_all(&in_buf[..p]).unwrap();
|
||||
if in_buf[p] == b'\n' {
|
||||
@@ -458,7 +452,8 @@ fn write_nonprint_to_end<W: Write>(in_buf: &[u8], writer: &mut W, tab: &[u8]) ->
|
||||
128..=159 => writer.write_all(&[b'M', b'-', b'^', byte - 64]),
|
||||
160..=254 => writer.write_all(&[b'M', b'-', byte - 128]),
|
||||
_ => writer.write_all(&[b'M', b'-', b'^', 63]),
|
||||
}.unwrap();
|
||||
}
|
||||
.unwrap();
|
||||
count += 1;
|
||||
}
|
||||
if count != in_buf.len() {
|
||||
|
||||
+4
-4
@@ -10,15 +10,15 @@
|
||||
|
||||
#[macro_use]
|
||||
extern crate uucore;
|
||||
use uucore::libc::{self, gid_t, lchown};
|
||||
pub use uucore::entries;
|
||||
use uucore::fs::resolve_relative_path;
|
||||
use uucore::libc::{self, gid_t, lchown};
|
||||
|
||||
extern crate walkdir;
|
||||
use walkdir::WalkDir;
|
||||
|
||||
use std::io::Result as IOResult;
|
||||
use std::io::Error as IOError;
|
||||
use std::io::Result as IOResult;
|
||||
|
||||
use std::fs;
|
||||
use std::fs::Metadata;
|
||||
@@ -183,12 +183,12 @@ struct Chgrper {
|
||||
}
|
||||
|
||||
macro_rules! unwrap {
|
||||
($m:expr, $e:ident, $err:block) => (
|
||||
($m:expr, $e:ident, $err:block) => {
|
||||
match $m {
|
||||
Ok(meta) => meta,
|
||||
Err($e) => $err,
|
||||
}
|
||||
)
|
||||
};
|
||||
}
|
||||
|
||||
impl Chgrper {
|
||||
|
||||
+46
-22
@@ -19,10 +19,10 @@ extern crate uucore;
|
||||
use std::fs;
|
||||
use std::os::unix::fs::{MetadataExt, PermissionsExt};
|
||||
use std::path::Path;
|
||||
use walker::Walker;
|
||||
use uucore::fs::display_permissions_unix;
|
||||
#[cfg(not(windows))]
|
||||
use uucore::mode;
|
||||
use uucore::fs::display_permissions_unix;
|
||||
use walker::Walker;
|
||||
|
||||
const NAME: &str = "chmod";
|
||||
static SUMMARY: &str = "Change the mode of each FILE to MODE.
|
||||
@@ -39,14 +39,31 @@ pub fn uumain(mut args: Vec<String>) -> i32 {
|
||||
NAME
|
||||
);
|
||||
let mut opts = new_coreopts!(&syntax, SUMMARY, LONG_HELP);
|
||||
opts.optflag("c", "changes", "like verbose but report only when a change is made")
|
||||
// TODO: support --silent (can be done using clap)
|
||||
.optflag("f", "quiet", "suppress most error messages")
|
||||
.optflag("v", "verbose", "output a diagnostic for every file processed")
|
||||
.optflag("", "no-preserve-root", "do not treat '/' specially (the default)")
|
||||
.optflag("", "preserve-root", "fail to operate recursively on '/'")
|
||||
.optopt("", "reference", "use RFILE's mode instead of MODE values", "RFILE")
|
||||
.optflag("R", "recursive", "change files and directories recursively");
|
||||
opts.optflag(
|
||||
"c",
|
||||
"changes",
|
||||
"like verbose but report only when a change is made",
|
||||
)
|
||||
// TODO: support --silent (can be done using clap)
|
||||
.optflag("f", "quiet", "suppress most error messages")
|
||||
.optflag(
|
||||
"v",
|
||||
"verbose",
|
||||
"output a diagnostic for every file processed",
|
||||
)
|
||||
.optflag(
|
||||
"",
|
||||
"no-preserve-root",
|
||||
"do not treat '/' specially (the default)",
|
||||
)
|
||||
.optflag("", "preserve-root", "fail to operate recursively on '/'")
|
||||
.optopt(
|
||||
"",
|
||||
"reference",
|
||||
"use RFILE's mode instead of MODE values",
|
||||
"RFILE",
|
||||
)
|
||||
.optflag("R", "recursive", "change files and directories recursively");
|
||||
|
||||
// sanitize input for - at beginning (e.g. chmod -x testfile). Remove
|
||||
// the option and save it for later, after parsing is finished.
|
||||
@@ -148,17 +165,19 @@ impl Chmoder {
|
||||
// on Windows OsStrings cannot be built out of non-UTF-8 chars. One
|
||||
// possible fix is to use CStrings rather than Strings in the args
|
||||
// to chmod() and chmod_file().
|
||||
r = self.chmod(
|
||||
walk_dir
|
||||
.filter_map(|x| match x {
|
||||
Ok(o) => match o.path().into_os_string().to_str() {
|
||||
Some(s) => Some(s.to_owned()),
|
||||
None => None,
|
||||
},
|
||||
Err(_) => None,
|
||||
})
|
||||
.collect(),
|
||||
).and(r);
|
||||
r = self
|
||||
.chmod(
|
||||
walk_dir
|
||||
.filter_map(|x| match x {
|
||||
Ok(o) => match o.path().into_os_string().to_str() {
|
||||
Some(s) => Some(s.to_owned()),
|
||||
None => None,
|
||||
},
|
||||
Err(_) => None,
|
||||
})
|
||||
.collect(),
|
||||
)
|
||||
.and(r);
|
||||
r = self.chmod_file(&file, filename).and(r);
|
||||
}
|
||||
} else {
|
||||
@@ -230,7 +249,12 @@ impl Chmoder {
|
||||
fn change_file(&self, fperm: u32, mode: u32, file: &Path, path: &str) -> Result<(), i32> {
|
||||
if fperm == mode {
|
||||
if self.verbose && !self.changes {
|
||||
show_info!("mode of '{}' retained as {:o} ({})", file.display(), fperm, display_permissions_unix(fperm));
|
||||
show_info!(
|
||||
"mode of '{}' retained as {:o} ({})",
|
||||
file.display(),
|
||||
fperm,
|
||||
display_permissions_unix(fperm)
|
||||
);
|
||||
}
|
||||
Ok(())
|
||||
} else if let Err(err) =
|
||||
|
||||
+4
-4
@@ -11,9 +11,9 @@
|
||||
|
||||
#[macro_use]
|
||||
extern crate uucore;
|
||||
use uucore::libc::{self, gid_t, lchown, uid_t};
|
||||
pub use uucore::entries::{self, Group, Locate, Passwd};
|
||||
use uucore::fs::resolve_relative_path;
|
||||
use uucore::libc::{self, gid_t, lchown, uid_t};
|
||||
|
||||
extern crate walkdir;
|
||||
use walkdir::WalkDir;
|
||||
@@ -24,8 +24,8 @@ use std::os::unix::fs::MetadataExt;
|
||||
use std::io;
|
||||
use std::io::Result as IOResult;
|
||||
|
||||
use std::path::Path;
|
||||
use std::convert::AsRef;
|
||||
use std::path::Path;
|
||||
|
||||
use std::ffi::CString;
|
||||
use std::os::unix::ffi::OsStrExt;
|
||||
@@ -253,12 +253,12 @@ struct Chowner {
|
||||
}
|
||||
|
||||
macro_rules! unwrap {
|
||||
($m:expr, $e:ident, $err:block) => (
|
||||
($m:expr, $e:ident, $err:block) => {
|
||||
match $m {
|
||||
Ok(meta) => meta,
|
||||
Err($e) => $err,
|
||||
}
|
||||
)
|
||||
};
|
||||
}
|
||||
|
||||
impl Chowner {
|
||||
|
||||
@@ -14,8 +14,8 @@ extern crate getopts;
|
||||
|
||||
#[macro_use]
|
||||
extern crate uucore;
|
||||
use uucore::libc::{self, chroot, setgid, setgroups, setuid};
|
||||
use uucore::entries;
|
||||
use uucore::libc::{self, chroot, setgid, setgroups, setuid};
|
||||
|
||||
use std::ffi::CString;
|
||||
use std::io::Error;
|
||||
@@ -140,10 +140,7 @@ fn enter_chroot(root: &Path) {
|
||||
let root_str = root.display();
|
||||
std::env::set_current_dir(root).unwrap();
|
||||
let err = unsafe {
|
||||
chroot(CString::new(".")
|
||||
.unwrap()
|
||||
.as_bytes_with_nul()
|
||||
.as_ptr() as *const libc::c_char)
|
||||
chroot(CString::new(".").unwrap().as_bytes_with_nul().as_ptr() as *const libc::c_char)
|
||||
};
|
||||
if err != 0 {
|
||||
crash!(
|
||||
|
||||
+2
-1
@@ -32,7 +32,8 @@ fn main() {
|
||||
&file,
|
||||
"#[allow(clippy::unreadable_literal)]\nconst CRC_TABLE: [u32; {}] = {:?};",
|
||||
CRC_TABLE_LEN, table
|
||||
).unwrap();
|
||||
)
|
||||
.unwrap();
|
||||
}
|
||||
|
||||
#[inline]
|
||||
|
||||
+28
-21
@@ -1,5 +1,4 @@
|
||||
#![crate_name = "uu_cp"]
|
||||
|
||||
#![allow(clippy::missing_safety_doc)]
|
||||
|
||||
/*
|
||||
@@ -29,35 +28,35 @@ extern crate xattr;
|
||||
#[cfg(windows)]
|
||||
extern crate kernel32;
|
||||
#[cfg(windows)]
|
||||
use kernel32::GetFileInformationByHandle;
|
||||
#[cfg(windows)]
|
||||
use kernel32::CreateFileW;
|
||||
#[cfg(windows)]
|
||||
use kernel32::GetFileInformationByHandle;
|
||||
#[cfg(windows)]
|
||||
extern crate winapi;
|
||||
|
||||
use std::mem;
|
||||
use clap::{App, Arg, ArgMatches};
|
||||
use filetime::FileTime;
|
||||
use quick_error::ResultExt;
|
||||
use std::collections::HashSet;
|
||||
#[cfg(not(windows))]
|
||||
use std::ffi::CString;
|
||||
#[cfg(windows)]
|
||||
use std::ffi::OsStr;
|
||||
use clap::{App, Arg, ArgMatches};
|
||||
use quick_error::ResultExt;
|
||||
use std::collections::HashSet;
|
||||
use std::fs;
|
||||
use std::io::{stdin, stdout, Write};
|
||||
#[cfg(target_os = "linux")]
|
||||
use std::fs::File;
|
||||
use std::fs::OpenOptions;
|
||||
use std::io;
|
||||
use std::io::{stdin, stdout, Write};
|
||||
use std::mem;
|
||||
#[cfg(target_os = "linux")]
|
||||
use std::os::unix::io::IntoRawFd;
|
||||
#[cfg(windows)]
|
||||
use std::os::windows::ffi::OsStrExt;
|
||||
use std::path::{Path, PathBuf, StripPrefixError};
|
||||
use std::str::FromStr;
|
||||
use uucore::fs::{canonicalize, CanonicalizeMode};
|
||||
use walkdir::WalkDir;
|
||||
#[cfg(target_os = "linux")]
|
||||
use std::os::unix::io::IntoRawFd;
|
||||
#[cfg(target_os = "linux")]
|
||||
use std::fs::File;
|
||||
use std::fs::OpenOptions;
|
||||
use filetime::FileTime;
|
||||
|
||||
#[cfg(unix)]
|
||||
use std::os::unix::fs::PermissionsExt;
|
||||
@@ -584,7 +583,8 @@ impl Options {
|
||||
}
|
||||
}
|
||||
|
||||
let recursive = matches.is_present(OPT_RECURSIVE) || matches.is_present(OPT_RECURSIVE_ALIAS)
|
||||
let recursive = matches.is_present(OPT_RECURSIVE)
|
||||
|| matches.is_present(OPT_RECURSIVE_ALIAS)
|
||||
|| matches.is_present(OPT_ARCHIVE);
|
||||
|
||||
let backup = matches.is_present(OPT_BACKUP) || (matches.occurrences_of(OPT_SUFFIX) > 0);
|
||||
@@ -731,7 +731,8 @@ fn preserve_hardlinks(
|
||||
"cannot stat {:?}: {}",
|
||||
src_path,
|
||||
std::io::Error::last_os_error()
|
||||
).into());
|
||||
)
|
||||
.into());
|
||||
}
|
||||
inode = stat.st_ino as u64;
|
||||
nlinks = stat.st_nlink as u64;
|
||||
@@ -755,7 +756,8 @@ fn preserve_hardlinks(
|
||||
"cannot get file information {:?}: {}",
|
||||
source,
|
||||
std::io::Error::last_os_error()
|
||||
).into());
|
||||
)
|
||||
.into());
|
||||
}
|
||||
inode = ((*stat).nFileIndexHigh as u64) << 32 | (*stat).nFileIndexLow as u64;
|
||||
nlinks = (*stat).nNumberOfLinks as u64;
|
||||
@@ -836,7 +838,8 @@ fn construct_dest_path(
|
||||
return Err(format!(
|
||||
"cannot overwrite directory '{}' with non-directory",
|
||||
target.display()
|
||||
).into());
|
||||
)
|
||||
.into());
|
||||
}
|
||||
|
||||
Ok(match *target_type {
|
||||
@@ -1140,7 +1143,8 @@ fn copy_helper(source: &Path, dest: &Path, options: &Options) -> CopyResult<()>
|
||||
source,
|
||||
dest,
|
||||
std::io::Error::last_os_error()
|
||||
).into());
|
||||
)
|
||||
.into());
|
||||
} else {
|
||||
return Ok(());
|
||||
}
|
||||
@@ -1169,7 +1173,8 @@ pub fn verify_target_type(target: &Path, target_type: &TargetType) -> CopyResult
|
||||
(&TargetType::File, true) => Err(format!(
|
||||
"cannot overwrite directory '{}' with non-directory",
|
||||
target.display()
|
||||
).into()),
|
||||
)
|
||||
.into()),
|
||||
_ => Ok(()),
|
||||
}
|
||||
}
|
||||
@@ -1205,6 +1210,8 @@ fn test_cp_localize_to_target() {
|
||||
&Path::new("a/source/"),
|
||||
&Path::new("a/source/c.txt"),
|
||||
&Path::new("target/")
|
||||
).unwrap() == Path::new("target/c.txt")
|
||||
)
|
||||
.unwrap()
|
||||
== Path::new("target/c.txt")
|
||||
)
|
||||
}
|
||||
|
||||
+1
-1
@@ -10,8 +10,8 @@
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
use std::io::{BufRead, BufReader, Read, Write};
|
||||
use std::io::Result as IoResult;
|
||||
use std::io::{BufRead, BufReader, Read, Write};
|
||||
|
||||
#[allow(non_snake_case)]
|
||||
pub mod Bytes {
|
||||
|
||||
+9
-4
@@ -466,8 +466,8 @@ pub fn uumain(args: Vec<String>) -> i32 {
|
||||
)
|
||||
})
|
||||
}
|
||||
(None, None, Some(field_ranges)) => list_to_ranges(&field_ranges[..], complement)
|
||||
.and_then(|ranges| {
|
||||
(None, None, Some(field_ranges)) => {
|
||||
list_to_ranges(&field_ranges[..], complement).and_then(|ranges| {
|
||||
let out_delim = match matches.opt_str("output-delimiter") {
|
||||
Some(s) => {
|
||||
if s.is_empty() {
|
||||
@@ -519,11 +519,16 @@ pub fn uumain(args: Vec<String>) -> i32 {
|
||||
},
|
||||
)),
|
||||
}
|
||||
}),
|
||||
})
|
||||
}
|
||||
(ref b, ref c, ref f) if b.is_some() || c.is_some() || f.is_some() => Err(
|
||||
msg_expects_no_more_than_one_of!("--fields (-f)", "--chars (-c)", "--bytes (-b)"),
|
||||
),
|
||||
_ => Err(msg_expects_one_of!("--fields (-f)", "--chars (-c)", "--bytes (-b)")),
|
||||
_ => Err(msg_expects_one_of!(
|
||||
"--fields (-f)",
|
||||
"--chars (-c)",
|
||||
"--bytes (-b)"
|
||||
)),
|
||||
};
|
||||
|
||||
let mode_parse = match mode_parse {
|
||||
|
||||
+2
-8
@@ -42,10 +42,7 @@ impl FromStr for Range {
|
||||
(Some(n), Some(m)) if m.is_empty() => {
|
||||
if let Ok(low) = n.parse::<usize>() {
|
||||
if low > 0 {
|
||||
Ok(Range {
|
||||
low,
|
||||
high: MAX - 1,
|
||||
})
|
||||
Ok(Range { low, high: MAX - 1 })
|
||||
} else {
|
||||
Err(field)
|
||||
}
|
||||
@@ -67,10 +64,7 @@ impl FromStr for Range {
|
||||
(Some(n), Some(m)) => match (n.parse::<usize>(), m.parse::<usize>()) {
|
||||
(Ok(low), Ok(high)) => {
|
||||
if low > 0 && low <= high {
|
||||
Ok(Range {
|
||||
low,
|
||||
high,
|
||||
})
|
||||
Ok(Range { low, high })
|
||||
} else if low == 0 {
|
||||
Err(field)
|
||||
} else {
|
||||
|
||||
+2
-3
@@ -14,8 +14,8 @@ extern crate chrono;
|
||||
extern crate clap;
|
||||
extern crate uucore;
|
||||
|
||||
use chrono::{DateTime, FixedOffset, Local, Offset};
|
||||
use chrono::offset::Utc;
|
||||
use chrono::{DateTime, FixedOffset, Local, Offset};
|
||||
use std::fs::File;
|
||||
use std::io::{BufRead, BufReader};
|
||||
use std::path::PathBuf;
|
||||
@@ -210,12 +210,11 @@ fn parse_cli(args: Vec<String>) -> Settings {
|
||||
"set time described by STRING")
|
||||
(@arg utc: -u --utc --universal
|
||||
"print or set Coordinated Universal Time (UTC)"))
|
||||
|
||||
// TODO: Decide whether this is appropriate.
|
||||
// The GNU date command has an explanation of all formatting options,
|
||||
// but the `chrono` crate has a few differences (most notably, the %Z option)
|
||||
// (after_help: include_str!("usage.txt")))
|
||||
.get_matches_from(args);
|
||||
.get_matches_from(args);
|
||||
|
||||
let format = if let Some(form) = matches.value_of("custom_format") {
|
||||
let form = form[1..].into();
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
pub const INTERNAL_DB: &str =
|
||||
r#"# Configuration file for dircolors, a utility to help you set the
|
||||
pub const INTERNAL_DB: &str = r#"# Configuration file for dircolors, a utility to help you set the
|
||||
# LS_COLORS environment variable used by GNU ls with the --color option.
|
||||
# Copyright (C) 1996-2016 Free Software Foundation, Inc.
|
||||
# Copying and distribution of this file, with or without modification,
|
||||
|
||||
@@ -13,10 +13,10 @@ extern crate glob;
|
||||
#[macro_use]
|
||||
extern crate uucore;
|
||||
|
||||
use std::fs::File;
|
||||
use std::io::{BufRead, BufReader};
|
||||
use std::borrow::Borrow;
|
||||
use std::env;
|
||||
use std::fs::File;
|
||||
use std::io::{BufRead, BufReader};
|
||||
|
||||
static SYNTAX: &str = "[OPTION]... [FILE]";
|
||||
static SUMMARY: &str = "Output commands to set the LS_COLORS environment variable.";
|
||||
@@ -68,8 +68,11 @@ pub fn uumain(args: Vec<String>) -> i32 {
|
||||
.optflag("p", "print-database", "print the byte counts")
|
||||
.parse(args);
|
||||
|
||||
if (matches.opt_present("csh") || matches.opt_present("c-shell") || matches.opt_present("sh")
|
||||
|| matches.opt_present("bourne-shell")) && matches.opt_present("print-database")
|
||||
if (matches.opt_present("csh")
|
||||
|| matches.opt_present("c-shell")
|
||||
|| matches.opt_present("sh")
|
||||
|| matches.opt_present("bourne-shell"))
|
||||
&& matches.opt_present("print-database")
|
||||
{
|
||||
disp_err!(
|
||||
"the options to output dircolors' internal database and\nto select a shell \
|
||||
@@ -291,7 +294,7 @@ where
|
||||
} else if key.starts_with('*') {
|
||||
result.push_str(format!("{}={}:", key, val).as_str());
|
||||
} else if lower == "options" || lower == "color" || lower == "eightbit" {
|
||||
// Slackware only. Ignore
|
||||
// Slackware only. Ignore
|
||||
} else if let Some(s) = table.get(lower.as_str()) {
|
||||
result.push_str(format!("{}={}:", s, val).as_str());
|
||||
} else {
|
||||
|
||||
+142
-104
@@ -163,40 +163,36 @@ fn du(
|
||||
|
||||
for f in read {
|
||||
match f {
|
||||
Ok(entry) => {
|
||||
match Stat::new(entry.path()) {
|
||||
Ok(this_stat) => {
|
||||
if this_stat.is_dir {
|
||||
futures.push(du(this_stat, options, depth + 1, inodes));
|
||||
} else {
|
||||
if inodes.contains(&this_stat.inode) {
|
||||
continue;
|
||||
}
|
||||
inodes.insert(this_stat.inode);
|
||||
my_stat.size += this_stat.size;
|
||||
my_stat.blocks += this_stat.blocks;
|
||||
if options.all {
|
||||
stats.push(this_stat);
|
||||
}
|
||||
Ok(entry) => match Stat::new(entry.path()) {
|
||||
Ok(this_stat) => {
|
||||
if this_stat.is_dir {
|
||||
futures.push(du(this_stat, options, depth + 1, inodes));
|
||||
} else {
|
||||
if inodes.contains(&this_stat.inode) {
|
||||
continue;
|
||||
}
|
||||
inodes.insert(this_stat.inode);
|
||||
my_stat.size += this_stat.size;
|
||||
my_stat.blocks += this_stat.blocks;
|
||||
if options.all {
|
||||
stats.push(this_stat);
|
||||
}
|
||||
}
|
||||
Err(error) => show_error!("{}", error),
|
||||
}
|
||||
}
|
||||
Err(error) => show_error!("{}", error),
|
||||
},
|
||||
Err(error) => show_error!("{}", error),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
stats.extend(futures.into_iter().flatten().rev().filter(
|
||||
|stat| {
|
||||
if !options.separate_dirs && stat.path.parent().unwrap() == my_stat.path {
|
||||
my_stat.size += stat.size;
|
||||
my_stat.blocks += stat.blocks;
|
||||
}
|
||||
options.max_depth == None || depth < options.max_depth.unwrap()
|
||||
},
|
||||
));
|
||||
stats.extend(futures.into_iter().flatten().rev().filter(|stat| {
|
||||
if !options.separate_dirs && stat.path.parent().unwrap() == my_stat.path {
|
||||
my_stat.size += stat.size;
|
||||
my_stat.blocks += stat.blocks;
|
||||
}
|
||||
options.max_depth == None || depth < options.max_depth.unwrap()
|
||||
}));
|
||||
stats.push(my_stat);
|
||||
Box::new(stats.into_iter())
|
||||
}
|
||||
@@ -220,7 +216,10 @@ fn convert_size_k(size: u64, multiplier: u64, _block_size: u64) -> String {
|
||||
}
|
||||
|
||||
fn convert_size_m(size: u64, multiplier: u64, _block_size: u64) -> String {
|
||||
format!("{}", ((size as f64) / ((multiplier * multiplier) as f64)).ceil())
|
||||
format!(
|
||||
"{}",
|
||||
((size as f64) / ((multiplier * multiplier) as f64)).ceil()
|
||||
)
|
||||
}
|
||||
|
||||
fn convert_size_other(size: u64, _multiplier: u64, block_size: u64) -> String {
|
||||
@@ -235,66 +234,109 @@ pub fn uumain(args: Vec<String>) -> i32 {
|
||||
NAME
|
||||
);
|
||||
let matches = new_coreopts!(&syntax, SUMMARY, LONG_HELP)
|
||||
// In task
|
||||
.optflag("a", "all", " write counts for all files, not just directories")
|
||||
// In main
|
||||
.optflag("", "apparent-size", "print apparent sizes, rather than disk usage
|
||||
// In task
|
||||
.optflag(
|
||||
"a",
|
||||
"all",
|
||||
" write counts for all files, not just directories",
|
||||
)
|
||||
// In main
|
||||
.optflag(
|
||||
"",
|
||||
"apparent-size",
|
||||
"print apparent sizes, rather than disk usage
|
||||
although the apparent size is usually smaller, it may be larger due to holes
|
||||
in ('sparse') files, internal fragmentation, indirect blocks, and the like")
|
||||
// In main
|
||||
.optopt("B", "block-size", "scale sizes by SIZE before printing them.
|
||||
in ('sparse') files, internal fragmentation, indirect blocks, and the like",
|
||||
)
|
||||
// In main
|
||||
.optopt(
|
||||
"B",
|
||||
"block-size",
|
||||
"scale sizes by SIZE before printing them.
|
||||
E.g., '-BM' prints sizes in units of 1,048,576 bytes. See SIZE format below.",
|
||||
"SIZE")
|
||||
// In main
|
||||
.optflag("b", "bytes", "equivalent to '--apparent-size --block-size=1'")
|
||||
// In main
|
||||
"SIZE",
|
||||
)
|
||||
// In main
|
||||
.optflag(
|
||||
"b",
|
||||
"bytes",
|
||||
"equivalent to '--apparent-size --block-size=1'",
|
||||
)
|
||||
// In main
|
||||
.optflag("c", "total", "produce a grand total")
|
||||
// In task
|
||||
// opts.optflag("D", "dereference-args", "dereference only symlinks that are listed
|
||||
// on the command line"),
|
||||
// In main
|
||||
// opts.optopt("", "files0-from", "summarize disk usage of the NUL-terminated file
|
||||
// names specified in file F;
|
||||
// If F is - then read names from standard input", "F"),
|
||||
// // In task
|
||||
// opts.optflag("H", "", "equivalent to --dereference-args (-D)"),
|
||||
// In main
|
||||
.optflag("h", "human-readable", "print sizes in human readable format (e.g., 1K 234M 2G)")
|
||||
// In main
|
||||
// In task
|
||||
// opts.optflag("D", "dereference-args", "dereference only symlinks that are listed
|
||||
// on the command line"),
|
||||
// In main
|
||||
// opts.optopt("", "files0-from", "summarize disk usage of the NUL-terminated file
|
||||
// names specified in file F;
|
||||
// If F is - then read names from standard input", "F"),
|
||||
// // In task
|
||||
// opts.optflag("H", "", "equivalent to --dereference-args (-D)"),
|
||||
// In main
|
||||
.optflag(
|
||||
"h",
|
||||
"human-readable",
|
||||
"print sizes in human readable format (e.g., 1K 234M 2G)",
|
||||
)
|
||||
// In main
|
||||
.optflag("", "si", "like -h, but use powers of 1000 not 1024")
|
||||
// In main
|
||||
// In main
|
||||
.optflag("k", "", "like --block-size=1K")
|
||||
// In task
|
||||
// In task
|
||||
.optflag("l", "count-links", "count sizes many times if hard linked")
|
||||
// // In main
|
||||
// // In main
|
||||
.optflag("m", "", "like --block-size=1M")
|
||||
// // In task
|
||||
// opts.optflag("L", "dereference", "dereference all symbolic links"),
|
||||
// // In task
|
||||
// opts.optflag("P", "no-dereference", "don't follow any symbolic links (this is the default)"),
|
||||
// // In main
|
||||
.optflag("0", "null", "end each output line with 0 byte rather than newline")
|
||||
// In main
|
||||
.optflag("S", "separate-dirs", "do not include size of subdirectories")
|
||||
// In main
|
||||
// // In task
|
||||
// opts.optflag("L", "dereference", "dereference all symbolic links"),
|
||||
// // In task
|
||||
// opts.optflag("P", "no-dereference", "don't follow any symbolic links (this is the default)"),
|
||||
// // In main
|
||||
.optflag(
|
||||
"0",
|
||||
"null",
|
||||
"end each output line with 0 byte rather than newline",
|
||||
)
|
||||
// In main
|
||||
.optflag(
|
||||
"S",
|
||||
"separate-dirs",
|
||||
"do not include size of subdirectories",
|
||||
)
|
||||
// In main
|
||||
.optflag("s", "summarize", "display only a total for each argument")
|
||||
// // In task
|
||||
// opts.optflag("x", "one-file-system", "skip directories on different file systems"),
|
||||
// // In task
|
||||
// opts.optopt("X", "exclude-from", "exclude files that match any pattern in FILE", "FILE"),
|
||||
// // In task
|
||||
// opts.optopt("", "exclude", "exclude files that match PATTERN", "PATTERN"),
|
||||
// In main
|
||||
.optopt("d", "max-depth", "print the total for a directory (or file, with --all)
|
||||
// // In task
|
||||
// opts.optflag("x", "one-file-system", "skip directories on different file systems"),
|
||||
// // In task
|
||||
// opts.optopt("X", "exclude-from", "exclude files that match any pattern in FILE", "FILE"),
|
||||
// // In task
|
||||
// opts.optopt("", "exclude", "exclude files that match PATTERN", "PATTERN"),
|
||||
// In main
|
||||
.optopt(
|
||||
"d",
|
||||
"max-depth",
|
||||
"print the total for a directory (or file, with --all)
|
||||
only if it is N or fewer levels below the command
|
||||
line argument; --max-depth=0 is the same as --summarize", "N")
|
||||
// In main
|
||||
.optflagopt("", "time", "show time of the last modification of any file in the
|
||||
line argument; --max-depth=0 is the same as --summarize",
|
||||
"N",
|
||||
)
|
||||
// In main
|
||||
.optflagopt(
|
||||
"",
|
||||
"time",
|
||||
"show time of the last modification of any file in the
|
||||
directory, or any of its subdirectories. If WORD is given, show time as WORD instead
|
||||
of modification time: atime, access, use, ctime or status", "WORD")
|
||||
// In main
|
||||
.optopt("", "time-style", "show times using style STYLE:
|
||||
full-iso, long-iso, iso, +FORMAT FORMAT is interpreted like 'date'", "STYLE")
|
||||
of modification time: atime, access, use, ctime or status",
|
||||
"WORD",
|
||||
)
|
||||
// In main
|
||||
.optopt(
|
||||
"",
|
||||
"time-style",
|
||||
"show times using style STYLE:
|
||||
full-iso, long-iso, iso, +FORMAT FORMAT is interpreted like 'date'",
|
||||
"STYLE",
|
||||
)
|
||||
.parse(args);
|
||||
|
||||
let summarize = matches.opt_present("summarize");
|
||||
@@ -350,26 +392,24 @@ pub fn uumain(args: Vec<String>) -> i32 {
|
||||
let convert_size = |size| convert_size_fn(size, multiplier, block_size);
|
||||
|
||||
let time_format_str = match matches.opt_str("time-style") {
|
||||
Some(s) => {
|
||||
match &s[..] {
|
||||
"full-iso" => "%Y-%m-%d %H:%M:%S.%f %z",
|
||||
"long-iso" => "%Y-%m-%d %H:%M",
|
||||
"iso" => "%Y-%m-%d",
|
||||
_ => {
|
||||
show_error!(
|
||||
"invalid argument '{}' for 'time style'
|
||||
Some(s) => match &s[..] {
|
||||
"full-iso" => "%Y-%m-%d %H:%M:%S.%f %z",
|
||||
"long-iso" => "%Y-%m-%d %H:%M",
|
||||
"iso" => "%Y-%m-%d",
|
||||
_ => {
|
||||
show_error!(
|
||||
"invalid argument '{}' for 'time style'
|
||||
Valid arguments are:
|
||||
- 'full-iso'
|
||||
- 'long-iso'
|
||||
- 'iso'
|
||||
Try '{} --help' for more information.",
|
||||
s,
|
||||
NAME
|
||||
);
|
||||
return 1;
|
||||
}
|
||||
s,
|
||||
NAME
|
||||
);
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
},
|
||||
None => "%Y-%m-%d %H:%M",
|
||||
};
|
||||
|
||||
@@ -397,23 +437,21 @@ Try '{} --help' for more information.",
|
||||
let tm = {
|
||||
let (secs, nsecs) = {
|
||||
let time = match matches.opt_str("time") {
|
||||
Some(s) => {
|
||||
match &s[..] {
|
||||
"accessed" => stat.accessed,
|
||||
"created" => stat.created,
|
||||
"modified" => stat.modified,
|
||||
_ => {
|
||||
show_error!(
|
||||
"invalid argument 'modified' for '--time'
|
||||
Some(s) => match &s[..] {
|
||||
"accessed" => stat.accessed,
|
||||
"created" => stat.created,
|
||||
"modified" => stat.modified,
|
||||
_ => {
|
||||
show_error!(
|
||||
"invalid argument 'modified' for '--time'
|
||||
Valid arguments are:
|
||||
- 'accessed', 'created', 'modified'
|
||||
Try '{} --help' for more information.",
|
||||
NAME
|
||||
);
|
||||
return 1;
|
||||
}
|
||||
NAME
|
||||
);
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
},
|
||||
None => stat.modified,
|
||||
};
|
||||
((time / 1000) as i64, (time % 1000 * 1_000_000) as i32)
|
||||
|
||||
+8
-4
@@ -71,8 +71,8 @@ fn print_escaped(input: &str, mut output: impl Write) -> io::Result<bool> {
|
||||
'b' => '\x08',
|
||||
'c' => {
|
||||
should_stop = true;
|
||||
break
|
||||
},
|
||||
break;
|
||||
}
|
||||
'e' => '\x1b',
|
||||
'f' => '\x0c',
|
||||
'n' => '\n',
|
||||
@@ -90,7 +90,7 @@ fn print_escaped(input: &str, mut output: impl Write) -> io::Result<bool> {
|
||||
_ => {
|
||||
start = 0;
|
||||
next
|
||||
},
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -110,7 +110,11 @@ pub fn uumain(args: Vec<String>) -> i32 {
|
||||
let matches = new_coreopts!(SYNTAX, SUMMARY, HELP)
|
||||
.optflag("n", "", "do not output the trailing newline")
|
||||
.optflag("e", "", "enable interpretation of backslash escapes")
|
||||
.optflag("E", "", "disable interpretation of backslash escapes (default)")
|
||||
.optflag(
|
||||
"E",
|
||||
"",
|
||||
"disable interpretation of backslash escapes (default)",
|
||||
)
|
||||
.parse(args);
|
||||
|
||||
let no_newline = matches.opt_present("n");
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user