From db91e12a1dce69c020bb97de5b88d330115aedbd Mon Sep 17 00:00:00 2001 From: Ian Douglas Scott Date: Sun, 5 Nov 2023 18:11:04 -0800 Subject: [PATCH] Fix build on Redox, and add `stat` to Redox feature --- Cargo.toml | 1 + src/uu/cp/src/cp.rs | 2 ++ src/uu/date/src/date.rs | 1 - src/uu/df/src/df.rs | 2 +- src/uu/shred/src/shred.rs | 8 ++++---- src/uucore/src/lib/features/entries.rs | 5 ----- src/uucore/src/lib/features/fsext.rs | 11 ++++++++--- src/uucore/src/lib/features/mode.rs | 17 ++++++++++++----- src/uucore/src/lib/features/signals.rs | 2 +- 9 files changed, 29 insertions(+), 20 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 3df108e4e..55dcb378f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -240,6 +240,7 @@ feat_os_unix_redox = [ "feat_common_core", # "chmod", + "stat", "uname", ] # "feat_os_windows_legacy" == slightly restricted set of utilities which can be built/run on early windows platforms (eg, "WinXP") diff --git a/src/uu/cp/src/cp.rs b/src/uu/cp/src/cp.rs index 7265e89f1..de01a5ef3 100644 --- a/src/uu/cp/src/cp.rs +++ b/src/uu/cp/src/cp.rs @@ -1896,6 +1896,7 @@ fn handle_no_preserve_mode(options: &Options, org_mode: u32) -> u32 { target_os = "macos", target_os = "macos-12", target_os = "freebsd", + target_os = "redox", )))] { const MODE_RW_UGO: u32 = S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH; @@ -1911,6 +1912,7 @@ fn handle_no_preserve_mode(options: &Options, org_mode: u32) -> u32 { target_os = "macos", target_os = "macos-12", target_os = "freebsd", + target_os = "redox", ))] { const MODE_RW_UGO: u32 = diff --git a/src/uu/date/src/date.rs b/src/uu/date/src/date.rs index b5ab8993a..ee3c7bfdf 100644 --- a/src/uu/date/src/date.rs +++ b/src/uu/date/src/date.rs @@ -16,7 +16,6 @@ use std::fs::File; use std::io::{BufRead, BufReader}; use std::path::PathBuf; use uucore::display::Quotable; -#[cfg(not(any(target_os = "redox")))] use uucore::error::FromIo; use uucore::error::{UResult, USimpleError}; use uucore::{format_usage, help_about, help_usage, show}; diff --git a/src/uu/df/src/df.rs b/src/uu/df/src/df.rs index 78325f3d2..c21ba9847 100644 --- a/src/uu/df/src/df.rs +++ b/src/uu/df/src/df.rs @@ -336,7 +336,7 @@ fn filter_mount_list(vmi: Vec, opt: &Options) -> Vec { fn get_all_filesystems(opt: &Options) -> Result, std::io::Error> { // Run a sync call before any operation if so instructed. if opt.sync { - #[cfg(not(windows))] + #[cfg(not(any(windows, target_os = "redox")))] unsafe { #[cfg(not(target_os = "android"))] uucore::libc::sync(); diff --git a/src/uu/shred/src/shred.rs b/src/uu/shred/src/shred.rs index 04f81bf23..711fd0485 100644 --- a/src/uu/shred/src/shred.rs +++ b/src/uu/shred/src/shred.rs @@ -369,12 +369,12 @@ fn wipe_file( let metadata = fs::metadata(path).map_err_context(String::new)?; let mut perms = metadata.permissions(); #[cfg(unix)] - #[allow(clippy::useless_conversion)] + #[allow(clippy::useless_conversion, clippy::unnecessary_cast)] { // NOTE: set_readonly(false) makes the file world-writable on Unix. - // NOTE: S_IWUSR type is u16 on macOS. - if (perms.mode() & u32::from(S_IWUSR)) == 0 { - perms.set_mode(u32::from(S_IWUSR)); + // NOTE: S_IWUSR type is u16 on macOS, i32 on Redox. + if (perms.mode() & (S_IWUSR as u32)) == 0 { + perms.set_mode(S_IWUSR as u32); } } #[cfg(not(unix))] diff --git a/src/uucore/src/lib/features/entries.rs b/src/uucore/src/lib/features/entries.rs index 29c9b4372..fa10ba2de 100644 --- a/src/uucore/src/lib/features/entries.rs +++ b/src/uucore/src/lib/features/entries.rs @@ -35,7 +35,6 @@ #[cfg(any(target_os = "freebsd", target_vendor = "apple"))] use libc::time_t; use libc::{c_char, c_int, gid_t, uid_t}; -#[cfg(not(target_os = "redox"))] use libc::{getgrgid, getgrnam, getgroups}; use libc::{getpwnam, getpwuid, group, passwd}; @@ -67,7 +66,6 @@ extern "C" { /// > supplementary group IDs for the process is returned. This allows /// > the caller to determine the size of a dynamically allocated list /// > to be used in a further call to getgroups(). -#[cfg(not(target_os = "redox"))] pub fn get_groups() -> IOResult> { let mut groups = Vec::new(); loop { @@ -337,7 +335,6 @@ macro_rules! f { } f!(getpwnam, getpwuid, uid_t, Passwd); -#[cfg(not(target_os = "redox"))] f!(getgrnam, getgrgid, gid_t, Group); #[inline] @@ -345,7 +342,6 @@ pub fn uid2usr(id: uid_t) -> IOResult { Passwd::locate(id).map(|p| p.name) } -#[cfg(not(target_os = "redox"))] #[inline] pub fn gid2grp(id: gid_t) -> IOResult { Group::locate(id).map(|p| p.name) @@ -356,7 +352,6 @@ pub fn usr2uid(name: &str) -> IOResult { Passwd::locate(name).map(|p| p.uid) } -#[cfg(not(target_os = "redox"))] #[inline] pub fn grp2gid(name: &str) -> IOResult { Group::locate(name).map(|p| p.gid) diff --git a/src/uucore/src/lib/features/fsext.rs b/src/uucore/src/lib/features/fsext.rs index 93fedb44b..9ee5e2464 100644 --- a/src/uucore/src/lib/features/fsext.rs +++ b/src/uucore/src/lib/features/fsext.rs @@ -71,6 +71,7 @@ use std::convert::{AsRef, From}; target_os = "android", target_os = "illumos", target_os = "solaris", + target_os = "redox", ))] use std::ffi::CStr; #[cfg(not(windows))] @@ -106,7 +107,6 @@ pub use libc::statvfs as StatFs; target_vendor = "apple", target_os = "freebsd", target_os = "openbsd", - target_os = "redox" ))] pub use libc::statfs as statfs_fn; #[cfg(any( @@ -114,7 +114,8 @@ pub use libc::statfs as statfs_fn; target_os = "bitrig", target_os = "illumos", target_os = "solaris", - target_os = "dragonfly" + target_os = "dragonfly", + target_os = "redox" ))] pub use libc::statvfs as statfs_fn; @@ -639,6 +640,7 @@ impl FsMeta for StatFs { not(target_os = "openbsd"), not(target_os = "illumos"), not(target_os = "solaris"), + not(target_os = "redox"), not(target_arch = "s390x"), target_pointer_width = "64" ))] @@ -646,6 +648,7 @@ impl FsMeta for StatFs { #[cfg(all( not(target_env = "musl"), not(target_os = "freebsd"), + not(target_os = "redox"), any( target_arch = "s390x", target_vendor = "apple", @@ -659,7 +662,8 @@ impl FsMeta for StatFs { target_env = "musl", target_os = "freebsd", target_os = "illumos", - target_os = "solaris" + target_os = "solaris", + target_os = "redox" ))] return self.f_bsize.try_into().unwrap(); } @@ -875,6 +879,7 @@ pub fn pretty_time(sec: i64, nsec: i64) -> String { // the date was set let local_offset = match UtcOffset::local_offset_at(tm) { Ok(lo) => lo, + Err(_) if cfg!(target_os = "redox") => UtcOffset::UTC, Err(e) => { panic!("error: {e}"); } diff --git a/src/uucore/src/lib/features/mode.rs b/src/uucore/src/lib/features/mode.rs index 147624891..c2da380bf 100644 --- a/src/uucore/src/lib/features/mode.rs +++ b/src/uucore/src/lib/features/mode.rs @@ -137,6 +137,7 @@ fn parse_change(mode: &str, fperm: u32, considering_dir: bool) -> (u32, usize) { (srwx, pos) } +#[allow(clippy::unnecessary_cast)] pub fn parse_mode(mode: &str) -> Result { #[cfg(all( not(target_os = "freebsd"), @@ -148,9 +149,9 @@ pub fn parse_mode(mode: &str) -> Result { let fperm = (S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH) as u32; let result = if mode.chars().any(|c| c.is_ascii_digit()) { - parse_numeric(fperm, mode, true) + parse_numeric(fperm as u32, mode, true) } else { - parse_symbolic(fperm, mode, get_umask(), true) + parse_symbolic(fperm as u32, mode, get_umask(), true) }; result.map(|mode| mode as mode_t) } @@ -168,11 +169,17 @@ pub fn get_umask() -> u32 { #[cfg(all( not(target_os = "freebsd"), not(target_vendor = "apple"), - not(target_os = "android") + not(target_os = "android"), + not(target_os = "redox") ))] return mask; - #[cfg(any(target_os = "freebsd", target_vendor = "apple", target_os = "android"))] - return mask.into(); + #[cfg(any( + target_os = "freebsd", + target_vendor = "apple", + target_os = "android", + target_os = "redox" + ))] + return mask as u32; } // Iterate 'args' and delete the first occurrence diff --git a/src/uucore/src/lib/features/signals.rs b/src/uucore/src/lib/features/signals.rs index 2e8c26a45..a4c85647b 100644 --- a/src/uucore/src/lib/features/signals.rs +++ b/src/uucore/src/lib/features/signals.rs @@ -27,7 +27,7 @@ Linux Programmer's Manual */ -#[cfg(any(target_os = "linux", target_os = "android"))] +#[cfg(any(target_os = "linux", target_os = "android", target_os = "redox"))] pub static ALL_SIGNALS: [&str; 32] = [ "EXIT", "HUP", "INT", "QUIT", "ILL", "TRAP", "ABRT", "BUS", "FPE", "KILL", "USR1", "SEGV", "USR2", "PIPE", "ALRM", "TERM", "STKFLT", "CHLD", "CONT", "STOP", "TSTP", "TTIN", "TTOU",