Skip to content

Commit

Permalink
Merge branch 'main' into refactor-tail
Browse files Browse the repository at this point in the history
  • Loading branch information
Joining7943 committed Sep 13, 2022
2 parents e99fecc + 78a9f6e commit 073de92
Show file tree
Hide file tree
Showing 11 changed files with 106 additions and 64 deletions.
28 changes: 5 additions & 23 deletions .github/workflows/CICD.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ name: CICD
# spell-checker:ignore (shell/tools) choco clippy dmake dpkg esac fakeroot gmake grcov halium lcov libssl mkdir popd printf pushd rsync rustc rustfmt rustup shopt xargs
# spell-checker:ignore (misc) aarch alnum armhf bindir busytest coreutils gnueabihf issuecomment maint nullglob onexitbegin onexitend pell runtest tempfile testsuite uutils DESTDIR multisize Swatinem

# ToDO: [2021-06; rivy] change from `cargo-tree` to `cargo tree` once MSRV is >= 1.45

env:
PROJECT_NAME: coreutils
PROJECT_DESC: "Core universal (cross-platform) utilities"
Expand Down Expand Up @@ -339,14 +337,6 @@ jobs:
toolchain: ${{ env.RUST_MIN_SRV }}
default: true
profile: minimal # minimal component installation (ie, no documentation)
- name: Install `cargo-tree` # for dependency information
uses: actions-rs/[email protected]
with:
crate: cargo-tree
version: latest
use-tool-cache: true
env:
RUSTUP_TOOLCHAIN: stable
- name: Confirm MinSRV compatible 'Cargo.lock'
shell: bash
run: |
Expand Down Expand Up @@ -374,12 +364,12 @@ jobs:
rustup show active-toolchain
cargo -V
rustc -V
cargo-tree tree -V
cargo tree -V
# dependencies
echo "## dependency list"
## * using the 'stable' toolchain is necessary to avoid "unexpected '--filter-platform'" errors
RUSTUP_TOOLCHAIN=stable cargo fetch --locked --quiet
RUSTUP_TOOLCHAIN=stable cargo-tree tree --all --locked --no-dev-dependencies --no-indent ${{ steps.vars.outputs.CARGO_FEATURES_OPTION }} | grep -vE "$PWD" | sort --unique
RUSTUP_TOOLCHAIN=stable cargo tree --all --locked --no-dev-dependencies --no-indent ${{ steps.vars.outputs.CARGO_FEATURES_OPTION }} | grep -vE "$PWD" | sort --unique
- name: Test
uses: actions-rs/cargo@v1
with:
Expand Down Expand Up @@ -715,14 +705,6 @@ jobs:
echo UTILITY_LIST=${UTILITY_LIST}
CARGO_UTILITY_LIST_OPTIONS="$(for u in ${UTILITY_LIST}; do echo "-puu_${u}"; done;)"
outputs CARGO_UTILITY_LIST_OPTIONS
- name: Install `cargo-tree` # for dependency information
uses: actions-rs/[email protected]
with:
crate: cargo-tree
version: latest
use-tool-cache: true
env:
RUSTUP_TOOLCHAIN: stable
- name: Info
shell: bash
run: |
Expand All @@ -741,11 +723,11 @@ jobs:
rustup show active-toolchain
cargo -V
rustc -V
cargo-tree tree -V
cargo tree -V
# dependencies
echo "## dependency list"
cargo fetch --locked --quiet
cargo-tree tree --locked --target=${{ matrix.job.target }} ${{ matrix.job.cargo-options }} ${{ steps.vars.outputs.CARGO_FEATURES_OPTION }} --all --no-dev-dependencies --no-indent | grep -vE "$PWD" | sort --unique
cargo tree --locked --target=${{ matrix.job.target }} ${{ matrix.job.cargo-options }} ${{ steps.vars.outputs.CARGO_FEATURES_OPTION }} --all --no-dev-dependencies --no-indent | grep -vE "$PWD" | sort --unique
- name: Build
uses: actions-rs/cargo@v1
with:
Expand Down Expand Up @@ -923,7 +905,7 @@ jobs:
- uses: Swatinem/rust-cache@v1
- name: Prepare, build and test
## spell-checker:ignore (ToDO) sshfs usesh vmactions
uses: vmactions/[email protected].4
uses: vmactions/[email protected].6
with:
usesh: true
# sync: sshfs
Expand Down
14 changes: 2 additions & 12 deletions .github/workflows/FixPR.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ name: FixPR

# Trigger automated fixes for PRs being merged (with associated commits)

# ToDO: [2021-06; rivy] change from `cargo-tree` to `cargo tree` once MSRV is >= 1.45

env:
BRANCH_TARGET: main

Expand Down Expand Up @@ -45,14 +43,6 @@ jobs:
toolchain: ${{ steps.vars.outputs.RUST_MIN_SRV }}
default: true
profile: minimal # minimal component installation (ie, no documentation)
- name: Install `cargo-tree` # for dependency information
uses: actions-rs/[email protected]
with:
crate: cargo-tree
version: latest
use-tool-cache: true
env:
RUSTUP_TOOLCHAIN: stable
- name: Ensure updated 'Cargo.lock'
shell: bash
run: |
Expand All @@ -73,12 +63,12 @@ jobs:
rustup show active-toolchain
cargo -V
rustc -V
cargo-tree tree -V
cargo tree -V
## dependencies
echo "## dependency list"
cargo fetch --locked --quiet
## * using the 'stable' toolchain is necessary to avoid "unexpected '--filter-platform'" errors
RUSTUP_TOOLCHAIN=stable cargo-tree tree --locked --all --no-dev-dependencies --no-indent --features ${{ matrix.job.features }} | grep -vE "$PWD" | sort --unique
RUSTUP_TOOLCHAIN=stable cargo tree --locked --all --no-dev-dependencies --no-indent --features ${{ matrix.job.features }} | grep -vE "$PWD" | sort --unique
- name: Commit any changes (to '${{ env.BRANCH_TARGET }}')
uses: EndBug/add-and-commit@v9
with:
Expand Down
10 changes: 5 additions & 5 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 8 additions & 1 deletion src/uu/chroot/src/chroot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,14 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
.status()
{
Ok(status) => status,
Err(e) => return Err(ChrootError::CommandFailed(command[0].to_string(), e).into()),
Err(e) => {
return Err(if e.kind() == std::io::ErrorKind::NotFound {
ChrootError::CommandNotFound(command[0].to_string(), e)
} else {
ChrootError::CommandFailed(command[0].to_string(), e)
}
.into())
}
};

let code = if pstatus.success() {
Expand Down
12 changes: 9 additions & 3 deletions src/uu/chroot/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ pub enum ChrootError {
/// Failed to execute the specified command.
CommandFailed(String, Error),

/// Failed to find the specified command.
CommandNotFound(String, Error),

/// The given user and group specification was invalid.
InvalidUserspec(String),

Expand All @@ -43,20 +46,23 @@ pub enum ChrootError {
impl std::error::Error for ChrootError {}

impl UError for ChrootError {
// TODO: Exit status:
// 125 if chroot itself fails
// 126 if command is found but cannot be invoked
// 127 if command cannot be found
fn code(&self) -> i32 {
1
match self {
Self::CommandFailed(_, _) => 126,
Self::CommandNotFound(_, _) => 127,
_ => 125,
}
}
}

impl Display for ChrootError {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
match self {
Self::CannotEnter(s, e) => write!(f, "cannot chroot to {}: {}", s.quote(), e,),
Self::CommandFailed(s, e) => {
Self::CommandFailed(s, e) | Self::CommandNotFound(s, e) => {
write!(f, "failed to run command {}: {}", s.to_string().quote(), e,)
}
Self::InvalidUserspec(s) => write!(f, "invalid userspec: {}", s.quote(),),
Expand Down
2 changes: 1 addition & 1 deletion src/uu/expr/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ path = "src/expr.rs"
clap = { version = "3.2", features = ["wrap_help", "cargo"] }
num-bigint = "0.4.0"
num-traits = "0.2.15"
onig = { version = "~6.3", default-features = false }
onig = { version = "~6.4", default-features = false }
uucore = { version=">=0.0.15", package="uucore", path="../../uucore" }

[[bin]]
Expand Down
27 changes: 21 additions & 6 deletions src/uu/ls/src/ls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ const DEFAULT_BLOCK_SIZE: u64 = 1024;
enum LsError {
InvalidLineWidth(String),
IOError(std::io::Error),
IOErrorContext(std::io::Error, PathBuf),
IOErrorContext(std::io::Error, PathBuf, bool),
BlockSizeParseError(String),
AlreadyListedError(PathBuf),
}
Expand All @@ -163,7 +163,8 @@ impl UError for LsError {
match self {
Self::InvalidLineWidth(_) => 2,
Self::IOError(_) => 1,
Self::IOErrorContext(_, _) => 1,
Self::IOErrorContext(_, _, false) => 1,
Self::IOErrorContext(_, _, true) => 2,
Self::BlockSizeParseError(_) => 1,
Self::AlreadyListedError(_) => 2,
}
Expand All @@ -180,7 +181,7 @@ impl Display for LsError {
}
Self::InvalidLineWidth(s) => write!(f, "invalid line width: {}", s.quote()),
Self::IOError(e) => write!(f, "general io error: {}", e),
Self::IOErrorContext(e, p) => {
Self::IOErrorContext(e, p, _) => {
let error_kind = e.kind();
let errno = e.raw_os_error().unwrap_or(1i32);

Expand Down Expand Up @@ -1566,6 +1567,7 @@ struct PathData {
p_buf: PathBuf,
must_dereference: bool,
security_context: String,
command_line: bool,
}

impl PathData {
Expand Down Expand Up @@ -1649,6 +1651,7 @@ impl PathData {
p_buf,
must_dereference,
security_context,
command_line,
}
}

Expand Down Expand Up @@ -1677,7 +1680,11 @@ impl PathData {
return dir_entry.metadata().ok();
}
}
show!(LsError::IOErrorContext(err, self.p_buf.clone(),));
show!(LsError::IOErrorContext(
err,
self.p_buf.clone(),
self.command_line
));
None
}
Ok(md) => Some(md),
Expand Down Expand Up @@ -1739,7 +1746,11 @@ pub fn list(locs: Vec<&Path>, config: &Config) -> UResult<()> {
Err(err) => {
// flush stdout buffer before the error to preserve formatting and order
out.flush()?;
show!(LsError::IOErrorContext(err, path_data.p_buf.clone()));
show!(LsError::IOErrorContext(
err,
path_data.p_buf.clone(),
path_data.command_line
));
continue;
}
Ok(rd) => rd,
Expand Down Expand Up @@ -1916,7 +1927,11 @@ fn enter_directory(
match fs::read_dir(&e.p_buf) {
Err(err) => {
out.flush()?;
show!(LsError::IOErrorContext(err, e.p_buf.clone()));
show!(LsError::IOErrorContext(
err,
e.p_buf.clone(),
e.command_line
));
continue;
}
Ok(rd) => {
Expand Down
2 changes: 1 addition & 1 deletion src/uu/tail/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ path = "src/tail.rs"
clap = { version = "3.2", features = ["wrap_help", "cargo"] }
libc = "0.2.132"
memchr = "2.5.0"
notify = { version = "=5.0.0-pre.16", features=["macos_kqueue"]}
notify = { version = "=5.0.0", features=["macos_kqueue"]}
uucore = { version=">=0.0.15", package="uucore", path="../../uucore", features=["ringbuffer", "lines"] }
same-file = "1.0.6"

Expand Down
15 changes: 10 additions & 5 deletions tests/by-util/test_chroot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ fn test_invalid_arg() {

#[test]
fn test_missing_operand() {
let result = new_ucmd!().run();
let result = new_ucmd!().fails();

result.code_is(125);

assert!(result
.stderr_str()
Expand All @@ -27,7 +29,7 @@ fn test_enter_chroot_fails() {
at.mkdir("jail");

let result = ucmd.arg("jail").fails();

result.code_is(125);
assert!(result
.stderr_str()
.starts_with("chroot: cannot chroot to 'jail': Operation not permitted (os error 1)"));
Expand All @@ -41,7 +43,8 @@ fn test_no_such_directory() {

ucmd.arg("a")
.fails()
.stderr_is("chroot: cannot change root directory to 'a': no such directory");
.stderr_is("chroot: cannot change root directory to 'a': no such directory")
.code_is(125);
}

#[test]
Expand All @@ -51,7 +54,7 @@ fn test_invalid_user_spec() {
at.mkdir("a");

let result = ucmd.arg("a").arg("--userspec=ARABA:").fails();

result.code_is(125);
assert!(result.stderr_str().starts_with("chroot: invalid userspec"));
}

Expand Down Expand Up @@ -91,7 +94,9 @@ fn test_preference_of_userspec() {
.arg("-G")
.arg("ABC,DEF")
.arg(format!("--userspec={}:{}", username, group_name))
.run();
.fails();

result.code_is(125);

println!("result.stdout = {}", result.stdout_str());
println!("result.stderr = {}", result.stderr_str());
Expand Down
Loading

0 comments on commit 073de92

Please sign in to comment.