Merge branch 'main' into refactor/add_nix_error_auto_conversion

This commit is contained in:
Orhun Parmaksız 2022-10-22 20:35:43 +02:00 committed by GitHub
commit f117f36313
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 62 additions and 16 deletions

16
Cargo.lock generated
View file

@ -367,6 +367,7 @@ dependencies = [
"pretty_assertions",
"procfs",
"rand",
"rand_pcg",
"regex",
"rlimit",
"selinux",
@ -862,14 +863,14 @@ checksum = "31a7a908b8f32538a2143e59a6e4e2508988832d5d4d6f7c156b3cbc762643a5"
[[package]]
name = "filetime"
version = "0.2.17"
version = "0.2.18"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e94a7bbaa59354bc20dd75b67f23e2797b4490e9d6928203fb105c79e448c86c"
checksum = "4b9663d381d07ae25dc88dbdf27df458faa83a9b25336bcac83d5e452b5fc9d3"
dependencies = [
"cfg-if",
"libc",
"redox_syscall",
"windows-sys 0.36.1",
"windows-sys 0.42.0",
]
[[package]]
@ -1664,6 +1665,15 @@ dependencies = [
"getrandom",
]
[[package]]
name = "rand_pcg"
version = "0.3.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "59cad018caf63deb318e5a4586d99a24424a364f40f1e5778c29aca23f4fc73e"
dependencies = [
"rand_core",
]
[[package]]
name = "rayon"
version = "1.5.3"

View file

@ -408,6 +408,7 @@ rlimit = "0.8.3"
[target.'cfg(unix)'.dev-dependencies]
nix = { version = "0.25", default-features = false, features = ["process", "signal", "user"] }
rust-users = { version="0.11", package="users" }
rand_pcg = "0.3"
[build-dependencies]
phf_codegen = "0.11.1"

View file

@ -276,11 +276,10 @@ pub fn uumain(mut args: impl uucore::Args) -> UResult<()> {
};
let check = matches.get_flag("check");
let tag = matches.get_flag("tag");
let nonames = if binary_name == "b3sum" {
matches.get_flag("no-names")
} else {
false
};
let nonames = *matches
.try_get_one("no-names")
.unwrap_or(Some(&false))
.unwrap();
let status = matches.get_flag("status");
let quiet = matches.get_flag("quiet") || status;
let strict = matches.get_flag("strict");

View file

@ -15,7 +15,7 @@ edition = "2021"
path = "src/touch.rs"
[dependencies]
filetime = "0.2.17"
filetime = "0.2.18"
clap = { version = "4.0", features = ["wrap_help", "cargo"] }
time = { version = "0.3", features = ["parsing", "formatting", "local-offset", "macros"] }
uucore = { version=">=0.0.16", package="uucore", path="../../uucore", features=["libc"] }

View file

@ -402,12 +402,26 @@ pub fn canonicalize<P: AsRef<Path>>(
}
#[cfg(not(unix))]
#[allow(unused_variables)]
pub fn display_permissions(metadata: &fs::Metadata, display_file_type: bool) -> String {
let write = if metadata.permissions().readonly() {
'-'
} else {
'w'
};
if display_file_type {
return String::from("----------");
let file_type = if metadata.is_symlink() {
'l'
} else if metadata.is_dir() {
'd'
} else {
'-'
};
format!("{0}r{1}xr{1}xr{1}x", file_type, write)
} else {
format!("r{0}xr{0}xr{0}x", write)
}
String::from("---------")
}
#[cfg(unix)]

View file

@ -34,7 +34,7 @@ macro_rules! test_digest {
fn test_nonames() {
let ts = TestScenario::new("hashsum");
// EXPECTED_FILE has no newline character at the end
if DIGEST_ARG == "b3sum" {
if DIGEST_ARG == "--b3sum" {
// Option only available on b3sum
assert_eq!(format!("{0}\n{0}\n", ts.fixtures.read(EXPECTED_FILE)),
ts.ucmd().arg(DIGEST_ARG).arg(BITS_ARG).arg("--no-names").arg("input.txt").arg("-").pipe_in_fixture("input.txt")

View file

@ -966,7 +966,7 @@ fn test_ls_long() {
result.stdout_matches(&Regex::new(r"[-bcCdDlMnpPsStTx?]([r-][w-][xt-]){3}.*").unwrap());
#[cfg(windows)]
result.stdout_contains("---------- 1 somebody somegroup");
result.stdout_matches(&Regex::new(r"[-dl](r[w-]x){3}.*").unwrap());
}
}

View file

@ -1117,14 +1117,36 @@ fn test_tmp_files_deleted_on_sigint() {
let (at, mut ucmd) = at_and_ucmd!();
at.mkdir("tmp_dir");
let file_name = "big_file_to_sort.txt";
{
use rand::{Rng, SeedableRng};
use std::io::Write;
let mut file = at.make_file(file_name);
// approximately 20 MB
for _ in 0..40 {
let lines = rand_pcg::Pcg32::seed_from_u64(123)
.sample_iter(rand::distributions::uniform::Uniform::new(0, 10000))
.take(100000)
.map(|x| x.to_string() + "\n")
.collect::<String>();
file.write_all(lines.as_bytes()).unwrap();
}
}
ucmd.args(&[
"ext_sort.txt",
file_name,
"--buffer-size=1", // with a small buffer size `sort` will be forced to create a temporary directory very soon.
"--temporary-directory=tmp_dir",
]);
let mut child = ucmd.run_no_wait();
// wait a short amount of time so that `sort` can create a temporary directory.
std::thread::sleep(Duration::from_millis(100));
let mut timeout = Duration::from_millis(100);
for _ in 0..5 {
std::thread::sleep(timeout);
if read_dir(at.plus("tmp_dir")).unwrap().next().is_some() {
break;
}
timeout *= 2;
}
// `sort` should have created a temporary directory.
assert!(read_dir(at.plus("tmp_dir")).unwrap().next().is_some());
// kill sort with SIGINT