Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin' into i2
Browse files Browse the repository at this point in the history
  • Loading branch information
matrixhead committed Sep 14, 2024
2 parents a21cde7 + 8a9fb84 commit 13a87a7
Show file tree
Hide file tree
Showing 8 changed files with 214 additions and 68 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/CICD.yml
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ jobs:
shell: bash
run: |
RUSTDOCFLAGS="-Dwarnings" cargo doc ${{ steps.vars.outputs.CARGO_FEATURES_OPTION }} --no-deps --workspace --document-private-items
- uses: DavidAnson/markdownlint-cli2-action@v16
- uses: DavidAnson/markdownlint-cli2-action@v17
with:
fix: "true"
globs: |
Expand Down
53 changes: 12 additions & 41 deletions Cargo.lock

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

2 changes: 0 additions & 2 deletions deny.toml
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,6 @@ skip = [
{ name = "bitflags", version = "1.3.2" },
# clap_builder, textwrap
{ name = "terminal_size", version = "0.2.6" },
# bindgen
{ name = "itertools", version = "0.12.1" },
]
# spell-checker: enable

Expand Down
5 changes: 4 additions & 1 deletion src/bin/coreutils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,10 @@ include!(concat!(env!("OUT_DIR"), "/uutils_map.rs"));

fn usage<T>(utils: &UtilityMap<T>, name: &str) {
println!("{name} {VERSION} (multi-call binary)\n");
println!("Usage: {name} [function [arguments...]]\n");
println!("Usage: {name} [function [arguments...]]");
println!(" {name} --list\n");
println!("Options:");
println!(" --list lists all defined functions, one per row\n");
println!("Currently defined functions:\n");
#[allow(clippy::map_clone)]
let mut utils: Vec<&str> = utils.keys().map(|&s| s).collect();
Expand Down
3 changes: 2 additions & 1 deletion src/uu/mkdir/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ path = "src/mkdir.rs"

[dependencies]
clap = { workspace = true }
uucore = { workspace = true, features = ["fs", "mode"] }
uucore = { workspace = true, features = ["fs", "mode", "fsxattr"] }


[[bin]]
name = "mkdir"
Expand Down
62 changes: 41 additions & 21 deletions src/uu/mkdir/src/mkdir.rs
Original file line number Diff line number Diff line change
Expand Up @@ -164,20 +164,14 @@ pub fn mkdir(path: &Path, recursive: bool, mode: u32, verbose: bool) -> UResult<
// std::fs::create_dir("foo/."); fails in pure Rust
let path_buf = dir_strip_dot_for_creation(path);
let path = path_buf.as_path();

if create_dir(path, recursive, verbose, false)? {
chmod(path, mode)?;
}
Ok(())
create_dir(path, recursive, verbose, false, mode)
}

#[cfg(any(unix, target_os = "redox"))]
fn chmod(path: &Path, mode: u32) -> UResult<()> {
use std::fs::{set_permissions, Permissions};
use std::os::unix::fs::PermissionsExt;

let mode = Permissions::from_mode(mode);

set_permissions(path, mode)
.map_err_context(|| format!("cannot set permissions {}", path.quote()))
}
Expand All @@ -191,27 +185,33 @@ fn chmod(_path: &Path, _mode: u32) -> UResult<()> {
// Return true if the directory at `path` has been created by this call.
// `is_parent` argument is not used on windows
#[allow(unused_variables)]
fn create_dir(path: &Path, recursive: bool, verbose: bool, is_parent: bool) -> UResult<bool> {
if path.exists() && !recursive {
fn create_dir(
path: &Path,
recursive: bool,
verbose: bool,
is_parent: bool,
mode: u32,
) -> UResult<()> {
let path_exists = path.exists();
if path_exists && !recursive {
return Err(USimpleError::new(
1,
format!("{}: File exists", path.display()),
));
}
if path == Path::new("") {
return Ok(false);
return Ok(());
}

if recursive {
match path.parent() {
Some(p) => {
create_dir(p, recursive, verbose, true)?;
}
Some(p) => create_dir(p, recursive, verbose, true, mode)?,
None => {
USimpleError::new(1, "failed to create whole tree");
}
}
}

match std::fs::create_dir(path) {
Ok(()) => {
if verbose {
Expand All @@ -221,15 +221,35 @@ fn create_dir(path: &Path, recursive: bool, verbose: bool, is_parent: bool) -> U
path.quote()
);
}
#[cfg(not(windows))]
if is_parent {
// directories created by -p have permission bits set to '=rwx,u+wx',
// which is umask modified by 'u+wx'
chmod(path, (!mode::get_umask() & 0o0777) | 0o0300)?;
}
Ok(true)

#[cfg(all(unix, target_os = "linux"))]
let new_mode = if path_exists {
mode
} else {
// TODO: Make this macos and freebsd compatible by creating a function to get permission bits from
// acl in extended attributes
let acl_perm_bits = uucore::fsxattr::get_acl_perm_bits_from_xattr(path);

if is_parent {
(!mode::get_umask() & 0o777) | 0o300 | acl_perm_bits
} else {
mode | acl_perm_bits
}
};
#[cfg(all(unix, not(target_os = "linux")))]
let new_mode = if is_parent {
(!mode::get_umask() & 0o777) | 0o300
} else {
mode
};
#[cfg(windows)]
let new_mode = mode;

chmod(path, new_mode)?;
Ok(())
}
Err(_) if path.is_dir() => Ok(false),

Err(_) if path.is_dir() => Ok(()),
Err(e) => Err(e.into()),
}
}
Loading

0 comments on commit 13a87a7

Please sign in to comment.