mirror of
https://github.com/uutils/coreutils.git
synced 2026-06-10 15:48:22 -07:00
uucore: add WASI support for mode and path_ends_with_terminator
- mode: return default umask (022) on WASI instead of calling libc::umask - fs: add WASI variant of path_ends_with_terminator using string conversion
This commit is contained in:
committed by
Daniel Hofstetter
parent
e510449dce
commit
dbb4d6f528
@@ -763,9 +763,12 @@ pub fn are_hardlinks_or_one_way_symlink_to_same_file(source: &Path, target: &Pat
|
||||
/// # Arguments
|
||||
///
|
||||
/// * `path` - A reference to the path to be checked.
|
||||
#[cfg(unix)]
|
||||
#[cfg(any(unix, target_os = "wasi"))]
|
||||
pub fn path_ends_with_terminator(path: &Path) -> bool {
|
||||
#[cfg(unix)]
|
||||
use std::os::unix::prelude::OsStrExt;
|
||||
#[cfg(target_os = "wasi")]
|
||||
use std::os::wasi::ffi::OsStrExt;
|
||||
path.as_os_str()
|
||||
.as_bytes()
|
||||
.last()
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
|
||||
// spell-checker:ignore (vars) fperm srwx
|
||||
|
||||
#[cfg(not(unix))]
|
||||
#[cfg(windows)]
|
||||
use libc::umask;
|
||||
|
||||
pub fn parse_numeric(fperm: u32, mut mode: &str, considering_dir: bool) -> Result<u32, String> {
|
||||
@@ -185,7 +185,7 @@ pub fn get_umask() -> u32 {
|
||||
mask.bits() as u32
|
||||
}
|
||||
|
||||
#[cfg(not(unix))]
|
||||
#[cfg(windows)]
|
||||
{
|
||||
// SAFETY: umask always succeeds and doesn't operate on memory. Races are
|
||||
// possible but it can't violate Rust's guarantees.
|
||||
@@ -193,6 +193,12 @@ pub fn get_umask() -> u32 {
|
||||
unsafe { umask(mask) };
|
||||
mask as u32
|
||||
}
|
||||
|
||||
// WASI has no umask; return a typical default (022).
|
||||
#[cfg(not(any(unix, windows)))]
|
||||
{
|
||||
0o022
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
|
||||
Reference in New Issue
Block a user