mirror of
https://github.com/nushell/nushell.git
synced 2025-04-09 21:28:55 +02:00
FreeBSD compatibility patches (#11869)
# Description nushell is verified to work on FreeBSD 14 with these patches. What isn't supported on FreeBSD: * the crate 'procfs' doesn't support FreeBSD yet, all functionality depending on procfs is disabled * several RLIMIT_* values aren't supported on FreeBSD - functions related to these are disabled # User-Facing Changes n/a # Tests + Formatting n/a # After Submitting n/a --------- Co-authored-by: sholderbach <sholderbach@users.noreply.github.com>
This commit is contained in:
parent
1c49ca503a
commit
0487e9ffcb
@ -229,7 +229,7 @@ fn have_permission(dir: impl AsRef<Path>) -> PermissionResult<'static> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(any(target_os = "linux", target_os = "android"))]
|
#[cfg(any(target_os = "linux", target_os = "freebsd", target_os = "android"))]
|
||||||
fn any_group(_current_user_gid: gid_t, owner_group: u32) -> bool {
|
fn any_group(_current_user_gid: gid_t, owner_group: u32) -> bool {
|
||||||
use crate::filesystem::util::users;
|
use crate::filesystem::util::users;
|
||||||
let Some(user_groups) = users::current_user_groups() else {
|
let Some(user_groups) = users::current_user_groups() else {
|
||||||
@ -238,7 +238,10 @@ fn any_group(_current_user_gid: gid_t, owner_group: u32) -> bool {
|
|||||||
user_groups.iter().any(|gid| gid.as_raw() == owner_group)
|
user_groups.iter().any(|gid| gid.as_raw() == owner_group)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(all(unix, not(any(target_os = "linux", target_os = "android"))))]
|
#[cfg(all(
|
||||||
|
unix,
|
||||||
|
not(any(target_os = "linux", target_os = "freebsd", target_os = "android"))
|
||||||
|
))]
|
||||||
fn any_group(current_user_gid: gid_t, owner_group: u32) -> bool {
|
fn any_group(current_user_gid: gid_t, owner_group: u32) -> bool {
|
||||||
use crate::filesystem::util::users;
|
use crate::filesystem::util::users;
|
||||||
|
|
||||||
|
@ -141,9 +141,19 @@ impl Command for UCp {
|
|||||||
} else {
|
} else {
|
||||||
uu_cp::OverwriteMode::Clobber(uu_cp::ClobberMode::Standard)
|
uu_cp::OverwriteMode::Clobber(uu_cp::ClobberMode::Standard)
|
||||||
};
|
};
|
||||||
#[cfg(any(target_os = "linux", target_os = "android", target_os = "macos"))]
|
#[cfg(any(
|
||||||
|
target_os = "linux",
|
||||||
|
target_os = "freebsd",
|
||||||
|
target_os = "android",
|
||||||
|
target_os = "macos"
|
||||||
|
))]
|
||||||
let reflink_mode = uu_cp::ReflinkMode::Auto;
|
let reflink_mode = uu_cp::ReflinkMode::Auto;
|
||||||
#[cfg(not(any(target_os = "linux", target_os = "android", target_os = "macos")))]
|
#[cfg(not(any(
|
||||||
|
target_os = "linux",
|
||||||
|
target_os = "freebsd",
|
||||||
|
target_os = "android",
|
||||||
|
target_os = "macos"
|
||||||
|
)))]
|
||||||
let reflink_mode = uu_cp::ReflinkMode::Never;
|
let reflink_mode = uu_cp::ReflinkMode::Never;
|
||||||
let mut paths: Vec<Spanned<NuPath>> = call.rest(engine_state, stack, 0)?;
|
let mut paths: Vec<Spanned<NuPath>> = call.rest(engine_state, stack, 0)?;
|
||||||
if paths.is_empty() {
|
if paths.is_empty() {
|
||||||
@ -283,6 +293,7 @@ fn make_attributes(preserve: Option<Value>) -> Result<uu_cp::Attributes, ShellEr
|
|||||||
let mut attributes = uu_cp::Attributes {
|
let mut attributes = uu_cp::Attributes {
|
||||||
#[cfg(any(
|
#[cfg(any(
|
||||||
target_os = "linux",
|
target_os = "linux",
|
||||||
|
target_os = "freebsd",
|
||||||
target_os = "android",
|
target_os = "android",
|
||||||
target_os = "macos",
|
target_os = "macos",
|
||||||
target_os = "netbsd"
|
target_os = "netbsd"
|
||||||
@ -303,6 +314,7 @@ fn make_attributes(preserve: Option<Value>) -> Result<uu_cp::Attributes, ShellEr
|
|||||||
mode: ATTR_SET,
|
mode: ATTR_SET,
|
||||||
#[cfg(any(
|
#[cfg(any(
|
||||||
target_os = "linux",
|
target_os = "linux",
|
||||||
|
target_os = "freebsd",
|
||||||
target_os = "android",
|
target_os = "android",
|
||||||
target_os = "macos",
|
target_os = "macos",
|
||||||
target_os = "netbsd"
|
target_os = "netbsd"
|
||||||
@ -344,6 +356,7 @@ fn parse_and_set_attribute(
|
|||||||
"mode" => &mut attribute.mode,
|
"mode" => &mut attribute.mode,
|
||||||
#[cfg(any(
|
#[cfg(any(
|
||||||
target_os = "linux",
|
target_os = "linux",
|
||||||
|
target_os = "freebsd",
|
||||||
target_os = "android",
|
target_os = "android",
|
||||||
target_os = "macos",
|
target_os = "macos",
|
||||||
target_os = "netbsd"
|
target_os = "netbsd"
|
||||||
|
@ -107,7 +107,7 @@ pub mod users {
|
|||||||
Gid::current().as_raw()
|
Gid::current().as_raw()
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(not(any(target_os = "linux", target_os = "android")))]
|
#[cfg(not(any(target_os = "linux", target_os = "freebsd", target_os = "android")))]
|
||||||
pub fn get_current_username() -> Option<String> {
|
pub fn get_current_username() -> Option<String> {
|
||||||
User::from_uid(Uid::current())
|
User::from_uid(Uid::current())
|
||||||
.ok()
|
.ok()
|
||||||
@ -115,7 +115,7 @@ pub mod users {
|
|||||||
.map(|user| user.name)
|
.map(|user| user.name)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(any(target_os = "linux", target_os = "android"))]
|
#[cfg(any(target_os = "linux", target_os = "freebsd", target_os = "android"))]
|
||||||
pub fn current_user_groups() -> Option<Vec<Gid>> {
|
pub fn current_user_groups() -> Option<Vec<Gid>> {
|
||||||
// SAFETY:
|
// SAFETY:
|
||||||
// if first arg is 0 then it ignores second argument and returns number of groups present for given user.
|
// if first arg is 0 then it ignores second argument and returns number of groups present for given user.
|
||||||
@ -154,7 +154,7 @@ pub mod users {
|
|||||||
/// println!("User is a member of group #{group}");
|
/// println!("User is a member of group #{group}");
|
||||||
/// }
|
/// }
|
||||||
/// ```
|
/// ```
|
||||||
#[cfg(not(any(target_os = "linux", target_os = "android")))]
|
#[cfg(not(any(target_os = "linux", target_os = "freebsd", target_os = "android")))]
|
||||||
pub fn get_user_groups(username: &str, gid: gid_t) -> Option<Vec<Gid>> {
|
pub fn get_user_groups(username: &str, gid: gid_t) -> Option<Vec<Gid>> {
|
||||||
use std::ffi::CString;
|
use std::ffi::CString;
|
||||||
// MacOS uses i32 instead of gid_t in getgrouplist for unknown reasons
|
// MacOS uses i32 instead of gid_t in getgrouplist for unknown reasons
|
||||||
|
@ -111,6 +111,7 @@ static RESOURCE_ARRAY: Lazy<Vec<ResourceInfo>> = Lazy::new(|| {
|
|||||||
target_os = "freebsd",
|
target_os = "freebsd",
|
||||||
target_os = "openbsd",
|
target_os = "openbsd",
|
||||||
target_os = "linux",
|
target_os = "linux",
|
||||||
|
target_os = "freebsd",
|
||||||
target_os = "netbsd"
|
target_os = "netbsd"
|
||||||
))]
|
))]
|
||||||
(
|
(
|
||||||
@ -126,6 +127,7 @@ static RESOURCE_ARRAY: Lazy<Vec<ResourceInfo>> = Lazy::new(|| {
|
|||||||
target_os = "netbsd",
|
target_os = "netbsd",
|
||||||
target_os = "openbsd",
|
target_os = "openbsd",
|
||||||
target_os = "linux",
|
target_os = "linux",
|
||||||
|
target_os = "freebsd",
|
||||||
target_os = "aix",
|
target_os = "aix",
|
||||||
))]
|
))]
|
||||||
(
|
(
|
||||||
@ -178,6 +180,7 @@ static RESOURCE_ARRAY: Lazy<Vec<ResourceInfo>> = Lazy::new(|| {
|
|||||||
target_os = "netbsd",
|
target_os = "netbsd",
|
||||||
target_os = "openbsd",
|
target_os = "openbsd",
|
||||||
target_os = "linux",
|
target_os = "linux",
|
||||||
|
target_os = "freebsd",
|
||||||
target_os = "aix",
|
target_os = "aix",
|
||||||
))]
|
))]
|
||||||
(
|
(
|
||||||
|
@ -4,6 +4,7 @@ mod nu_check;
|
|||||||
#[cfg(any(
|
#[cfg(any(
|
||||||
target_os = "android",
|
target_os = "android",
|
||||||
target_os = "linux",
|
target_os = "linux",
|
||||||
|
target_os = "freebsd",
|
||||||
target_os = "macos",
|
target_os = "macos",
|
||||||
target_os = "windows"
|
target_os = "windows"
|
||||||
))]
|
))]
|
||||||
@ -20,6 +21,7 @@ pub use nu_check::NuCheck;
|
|||||||
#[cfg(any(
|
#[cfg(any(
|
||||||
target_os = "android",
|
target_os = "android",
|
||||||
target_os = "linux",
|
target_os = "linux",
|
||||||
|
target_os = "freebsd",
|
||||||
target_os = "macos",
|
target_os = "macos",
|
||||||
target_os = "windows"
|
target_os = "windows"
|
||||||
))]
|
))]
|
||||||
|
@ -16,6 +16,7 @@ use nu_protocol::{
|
|||||||
};
|
};
|
||||||
#[cfg(all(
|
#[cfg(all(
|
||||||
unix,
|
unix,
|
||||||
|
not(target_os = "freebsd"),
|
||||||
not(target_os = "macos"),
|
not(target_os = "macos"),
|
||||||
not(target_os = "windows"),
|
not(target_os = "windows"),
|
||||||
not(target_os = "android"),
|
not(target_os = "android"),
|
||||||
@ -27,6 +28,7 @@ use std::time::Duration;
|
|||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
pub struct Ps;
|
pub struct Ps;
|
||||||
|
|
||||||
|
#[cfg(not(target_os = "freebsd"))]
|
||||||
impl Command for Ps {
|
impl Command for Ps {
|
||||||
fn name(&self) -> &str {
|
fn name(&self) -> &str {
|
||||||
"ps"
|
"ps"
|
||||||
@ -93,6 +95,7 @@ impl Command for Ps {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(not(target_os = "freebsd"))]
|
||||||
fn run_ps(
|
fn run_ps(
|
||||||
engine_state: &EngineState,
|
engine_state: &EngineState,
|
||||||
stack: &mut Stack,
|
stack: &mut Stack,
|
||||||
|
@ -603,7 +603,7 @@ fn list_a_directory_not_exists() {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(target_os = "linux")]
|
#[cfg(any(target_os = "linux", target_os = "freebsd"))]
|
||||||
#[test]
|
#[test]
|
||||||
fn list_directory_contains_invalid_utf8() {
|
fn list_directory_contains_invalid_utf8() {
|
||||||
use std::ffi::OsStr;
|
use std::ffi::OsStr;
|
||||||
|
@ -436,19 +436,19 @@ fn mv_change_case_of_directory() {
|
|||||||
.map(|de| de.unwrap().file_name().to_string_lossy().into_owned())
|
.map(|de| de.unwrap().file_name().to_string_lossy().into_owned())
|
||||||
.collect();
|
.collect();
|
||||||
|
|
||||||
#[cfg(target_os = "linux")]
|
#[cfg(any(target_os = "linux", target_os = "freebsd"))]
|
||||||
assert!(
|
assert!(
|
||||||
!_files_in_test_directory.contains(&original_dir)
|
!_files_in_test_directory.contains(&original_dir)
|
||||||
&& _files_in_test_directory.contains(&new_dir)
|
&& _files_in_test_directory.contains(&new_dir)
|
||||||
);
|
);
|
||||||
|
|
||||||
#[cfg(target_os = "linux")]
|
#[cfg(any(target_os = "linux", target_os = "freebsd"))]
|
||||||
assert!(files_exist_at(
|
assert!(files_exist_at(
|
||||||
vec!["somefile.txt",],
|
vec!["somefile.txt",],
|
||||||
dirs.test().join(new_dir)
|
dirs.test().join(new_dir)
|
||||||
));
|
));
|
||||||
|
|
||||||
#[cfg(not(target_os = "linux"))]
|
#[cfg(not(any(target_os = "linux", target_os = "freebsd")))]
|
||||||
_actual.err.contains("to a subdirectory of itself");
|
_actual.err.contains("to a subdirectory of itself");
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@ -474,12 +474,12 @@ fn mv_change_case_of_file() {
|
|||||||
.unwrap()
|
.unwrap()
|
||||||
.map(|de| de.unwrap().file_name().to_string_lossy().into_owned())
|
.map(|de| de.unwrap().file_name().to_string_lossy().into_owned())
|
||||||
.collect();
|
.collect();
|
||||||
#[cfg(target_os = "linux")]
|
#[cfg(any(target_os = "linux", target_os = "freebsd"))]
|
||||||
assert!(
|
assert!(
|
||||||
!_files_in_test_directory.contains(&original_file_name)
|
!_files_in_test_directory.contains(&original_file_name)
|
||||||
&& _files_in_test_directory.contains(&new_file_name)
|
&& _files_in_test_directory.contains(&new_file_name)
|
||||||
);
|
);
|
||||||
#[cfg(not(target_os = "linux"))]
|
#[cfg(not(any(target_os = "linux", target_os = "freebsd")))]
|
||||||
_actual.err.contains("are the same file");
|
_actual.err.contains("are the same file");
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@ -903,7 +903,7 @@ fn test_cp_debug_default() {
|
|||||||
{
|
{
|
||||||
panic!("{}", format!("Failure: stdout was \n{}", actual.out));
|
panic!("{}", format!("Failure: stdout was \n{}", actual.out));
|
||||||
}
|
}
|
||||||
#[cfg(target_os = "linux")]
|
#[cfg(any(target_os = "linux", target_os = "freebsd"))]
|
||||||
if !actual
|
if !actual
|
||||||
.out
|
.out
|
||||||
.contains("copy offload: unknown, reflink: unsupported, sparse detection: no")
|
.contains("copy offload: unknown, reflink: unsupported, sparse detection: no")
|
||||||
|
@ -93,7 +93,7 @@ fn limit_set_invalid1() {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(any(target_os = "linux", target_os = "macos"))]
|
#[cfg(any(target_os = "linux", target_os = "freebsd", target_os = "macos"))]
|
||||||
#[test]
|
#[test]
|
||||||
fn limit_set_invalid2() {
|
fn limit_set_invalid2() {
|
||||||
Playground::setup("limit_set_invalid2", |dirs, _sandbox| {
|
Playground::setup("limit_set_invalid2", |dirs, _sandbox| {
|
||||||
|
Loading…
Reference in New Issue
Block a user