mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-07-27 11:07:44 +00:00
fix clippy src/
This commit is contained in:
parent
0a2394faa0
commit
81de2be5ab
6 changed files with 67 additions and 13 deletions
9
build.rs
9
build.rs
|
@ -11,14 +11,14 @@ use std::io::Write;
|
||||||
use std::path::Path;
|
use std::path::Path;
|
||||||
|
|
||||||
pub fn main() {
|
pub fn main() {
|
||||||
if let Ok(profile) = env::var("PROFILE") {
|
|
||||||
println!("cargo:rustc-cfg=build={profile:?}");
|
|
||||||
}
|
|
||||||
|
|
||||||
const ENV_FEATURE_PREFIX: &str = "CARGO_FEATURE_";
|
const ENV_FEATURE_PREFIX: &str = "CARGO_FEATURE_";
|
||||||
const FEATURE_PREFIX: &str = "feat_";
|
const FEATURE_PREFIX: &str = "feat_";
|
||||||
const OVERRIDE_PREFIX: &str = "uu_";
|
const OVERRIDE_PREFIX: &str = "uu_";
|
||||||
|
|
||||||
|
if let Ok(profile) = env::var("PROFILE") {
|
||||||
|
println!("cargo:rustc-cfg=build={profile:?}");
|
||||||
|
}
|
||||||
|
|
||||||
let out_dir = env::var("OUT_DIR").unwrap();
|
let out_dir = env::var("OUT_DIR").unwrap();
|
||||||
|
|
||||||
let mut crates = Vec::new();
|
let mut crates = Vec::new();
|
||||||
|
@ -46,6 +46,7 @@ pub fn main() {
|
||||||
"type UtilityMap<T> = phf::OrderedMap<&'static str, (fn(T) -> i32, fn() -> Command)>;\n\
|
"type UtilityMap<T> = phf::OrderedMap<&'static str, (fn(T) -> i32, fn() -> Command)>;\n\
|
||||||
\n\
|
\n\
|
||||||
#[allow(clippy::too_many_lines)]
|
#[allow(clippy::too_many_lines)]
|
||||||
|
#[allow(clippy::unreadable_literal)]
|
||||||
fn util_map<T: uucore::Args>() -> UtilityMap<T> {\n"
|
fn util_map<T: uucore::Args>() -> UtilityMap<T> {\n"
|
||||||
.as_bytes(),
|
.as_bytes(),
|
||||||
)
|
)
|
||||||
|
|
|
@ -34,6 +34,8 @@ fn usage<T>(utils: &UtilityMap<T>, name: &str) {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// # Panics
|
||||||
|
/// Panics if the binary path cannot be determined
|
||||||
fn binary_path(args: &mut impl Iterator<Item = OsString>) -> PathBuf {
|
fn binary_path(args: &mut impl Iterator<Item = OsString>) -> PathBuf {
|
||||||
match args.next() {
|
match args.next() {
|
||||||
Some(ref s) if !s.is_empty() => PathBuf::from(s),
|
Some(ref s) if !s.is_empty() => PathBuf::from(s),
|
||||||
|
@ -85,9 +87,8 @@ fn main() {
|
||||||
process::exit(1);
|
process::exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
let util = match util_os.to_str() {
|
let Some(util) = util_os.to_str() else {
|
||||||
Some(util) => util,
|
not_found(&util_os)
|
||||||
None => not_found(&util_os),
|
|
||||||
};
|
};
|
||||||
|
|
||||||
match util {
|
match util {
|
||||||
|
@ -113,9 +114,8 @@ fn main() {
|
||||||
if util == "--help" || util == "-h" {
|
if util == "--help" || util == "-h" {
|
||||||
// see if they want help on a specific util
|
// see if they want help on a specific util
|
||||||
if let Some(util_os) = args.next() {
|
if let Some(util_os) = args.next() {
|
||||||
let util = match util_os.to_str() {
|
let Some(util) = util_os.to_str() else {
|
||||||
Some(util) => util,
|
not_found(&util_os)
|
||||||
None => not_found(&util_os),
|
|
||||||
};
|
};
|
||||||
|
|
||||||
match utils.get(util) {
|
match utils.get(util) {
|
||||||
|
@ -145,6 +145,8 @@ fn main() {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Prints completions for the utility in the first parameter for the shell in the second parameter to stdout
|
/// Prints completions for the utility in the first parameter for the shell in the second parameter to stdout
|
||||||
|
/// # Panics
|
||||||
|
/// Panics if the utility map is empty
|
||||||
fn gen_completions<T: uucore::Args>(
|
fn gen_completions<T: uucore::Args>(
|
||||||
args: impl Iterator<Item = OsString>,
|
args: impl Iterator<Item = OsString>,
|
||||||
util_map: &UtilityMap<T>,
|
util_map: &UtilityMap<T>,
|
||||||
|
@ -183,6 +185,8 @@ fn gen_completions<T: uucore::Args>(
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Generate the manpage for the utility in the first parameter
|
/// Generate the manpage for the utility in the first parameter
|
||||||
|
/// # Panics
|
||||||
|
/// Panics if the utility map is empty
|
||||||
fn gen_manpage<T: uucore::Args>(
|
fn gen_manpage<T: uucore::Args>(
|
||||||
args: impl Iterator<Item = OsString>,
|
args: impl Iterator<Item = OsString>,
|
||||||
util_map: &UtilityMap<T>,
|
util_map: &UtilityMap<T>,
|
||||||
|
@ -215,6 +219,8 @@ fn gen_manpage<T: uucore::Args>(
|
||||||
process::exit(0);
|
process::exit(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// # Panics
|
||||||
|
/// Panics if the utility map is empty
|
||||||
fn gen_coreutils_app<T: uucore::Args>(util_map: &UtilityMap<T>) -> Command {
|
fn gen_coreutils_app<T: uucore::Args>(util_map: &UtilityMap<T>) -> Command {
|
||||||
let mut command = Command::new("coreutils");
|
let mut command = Command::new("coreutils");
|
||||||
for (name, (_, sub_app)) in util_map {
|
for (name, (_, sub_app)) in util_map {
|
||||||
|
|
|
@ -13,6 +13,9 @@ use zip::ZipArchive;
|
||||||
|
|
||||||
include!(concat!(env!("OUT_DIR"), "/uutils_map.rs"));
|
include!(concat!(env!("OUT_DIR"), "/uutils_map.rs"));
|
||||||
|
|
||||||
|
/// # Errors
|
||||||
|
/// Returns an error if the writer fails.
|
||||||
|
#[allow(clippy::too_many_lines)]
|
||||||
fn main() -> io::Result<()> {
|
fn main() -> io::Result<()> {
|
||||||
let mut tldr_zip = File::open("docs/tldr.zip")
|
let mut tldr_zip = File::open("docs/tldr.zip")
|
||||||
.ok()
|
.ok()
|
||||||
|
@ -170,6 +173,8 @@ struct MDWriter<'a, 'b> {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a, 'b> MDWriter<'a, 'b> {
|
impl<'a, 'b> MDWriter<'a, 'b> {
|
||||||
|
/// # Errors
|
||||||
|
/// Returns an error if the writer fails.
|
||||||
fn markdown(&mut self) -> io::Result<()> {
|
fn markdown(&mut self) -> io::Result<()> {
|
||||||
write!(self.w, "# {}\n\n", self.name)?;
|
write!(self.w, "# {}\n\n", self.name)?;
|
||||||
self.additional()?;
|
self.additional()?;
|
||||||
|
@ -180,6 +185,8 @@ impl<'a, 'b> MDWriter<'a, 'b> {
|
||||||
self.examples()
|
self.examples()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// # Errors
|
||||||
|
/// Returns an error if the writer fails.
|
||||||
fn additional(&mut self) -> io::Result<()> {
|
fn additional(&mut self) -> io::Result<()> {
|
||||||
writeln!(self.w, "<div class=\"additional\">")?;
|
writeln!(self.w, "<div class=\"additional\">")?;
|
||||||
self.platforms()?;
|
self.platforms()?;
|
||||||
|
@ -187,6 +194,8 @@ impl<'a, 'b> MDWriter<'a, 'b> {
|
||||||
writeln!(self.w, "</div>")
|
writeln!(self.w, "</div>")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// # Errors
|
||||||
|
/// Returns an error if the writer fails.
|
||||||
fn platforms(&mut self) -> io::Result<()> {
|
fn platforms(&mut self) -> io::Result<()> {
|
||||||
writeln!(self.w, "<div class=\"platforms\">")?;
|
writeln!(self.w, "<div class=\"platforms\">")?;
|
||||||
for (feature, icon) in [
|
for (feature, icon) in [
|
||||||
|
@ -209,6 +218,10 @@ impl<'a, 'b> MDWriter<'a, 'b> {
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// # Errors
|
||||||
|
/// Returns an error if the writer fails.
|
||||||
|
/// # Panics
|
||||||
|
/// Panics if the version is not found.
|
||||||
fn version(&mut self) -> io::Result<()> {
|
fn version(&mut self) -> io::Result<()> {
|
||||||
writeln!(
|
writeln!(
|
||||||
self.w,
|
self.w,
|
||||||
|
@ -217,6 +230,8 @@ impl<'a, 'b> MDWriter<'a, 'b> {
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// # Errors
|
||||||
|
/// Returns an error if the writer fails.
|
||||||
fn usage(&mut self) -> io::Result<()> {
|
fn usage(&mut self) -> io::Result<()> {
|
||||||
if let Some(markdown) = &self.markdown {
|
if let Some(markdown) = &self.markdown {
|
||||||
let usage = uuhelp_parser::parse_usage(markdown);
|
let usage = uuhelp_parser::parse_usage(markdown);
|
||||||
|
@ -230,6 +245,8 @@ impl<'a, 'b> MDWriter<'a, 'b> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// # Errors
|
||||||
|
/// Returns an error if the writer fails.
|
||||||
fn about(&mut self) -> io::Result<()> {
|
fn about(&mut self) -> io::Result<()> {
|
||||||
if let Some(markdown) = &self.markdown {
|
if let Some(markdown) = &self.markdown {
|
||||||
writeln!(self.w, "{}", uuhelp_parser::parse_about(markdown))
|
writeln!(self.w, "{}", uuhelp_parser::parse_about(markdown))
|
||||||
|
@ -238,6 +255,8 @@ impl<'a, 'b> MDWriter<'a, 'b> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// # Errors
|
||||||
|
/// Returns an error if the writer fails.
|
||||||
fn after_help(&mut self) -> io::Result<()> {
|
fn after_help(&mut self) -> io::Result<()> {
|
||||||
if let Some(markdown) = &self.markdown {
|
if let Some(markdown) = &self.markdown {
|
||||||
if let Some(after_help) = uuhelp_parser::parse_section("after help", markdown) {
|
if let Some(after_help) = uuhelp_parser::parse_section("after help", markdown) {
|
||||||
|
@ -248,6 +267,8 @@ impl<'a, 'b> MDWriter<'a, 'b> {
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// # Errors
|
||||||
|
/// Returns an error if the writer fails.
|
||||||
fn examples(&mut self) -> io::Result<()> {
|
fn examples(&mut self) -> io::Result<()> {
|
||||||
if let Some(zip) = self.tldr_zip {
|
if let Some(zip) = self.tldr_zip {
|
||||||
let content = if let Some(f) =
|
let content = if let Some(f) =
|
||||||
|
@ -292,6 +313,8 @@ impl<'a, 'b> MDWriter<'a, 'b> {
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// # Errors
|
||||||
|
/// Returns an error if the writer fails.
|
||||||
fn options(&mut self) -> io::Result<()> {
|
fn options(&mut self) -> io::Result<()> {
|
||||||
writeln!(self.w, "<h2>Options</h2>")?;
|
writeln!(self.w, "<h2>Options</h2>")?;
|
||||||
write!(self.w, "<dl>")?;
|
write!(self.w, "<dl>")?;
|
||||||
|
@ -354,6 +377,8 @@ impl<'a, 'b> MDWriter<'a, 'b> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// # Panics
|
||||||
|
/// Panics if the archive is not ok
|
||||||
fn get_zip_content(archive: &mut ZipArchive<impl Read + Seek>, name: &str) -> Option<String> {
|
fn get_zip_content(archive: &mut ZipArchive<impl Read + Seek>, name: &str) -> Option<String> {
|
||||||
let mut s = String::new();
|
let mut s = String::new();
|
||||||
archive.by_name(name).ok()?.read_to_string(&mut s).unwrap();
|
archive.by_name(name).ok()?.read_to_string(&mut s).unwrap();
|
||||||
|
|
|
@ -198,6 +198,8 @@ extern "C" {
|
||||||
target_os = "freebsd",
|
target_os = "freebsd",
|
||||||
target_os = "openbsd"
|
target_os = "openbsd"
|
||||||
))]
|
))]
|
||||||
|
/// # Safety
|
||||||
|
/// This function is unsafe because it dereferences a raw pointer.
|
||||||
unsafe fn _vprocmgr_detach_from_console(_: u32) -> *const libc::c_int {
|
unsafe fn _vprocmgr_detach_from_console(_: u32) -> *const libc::c_int {
|
||||||
std::ptr::null()
|
std::ptr::null()
|
||||||
}
|
}
|
||||||
|
|
|
@ -36,6 +36,8 @@ mod platform {
|
||||||
#[cfg(any(target_os = "linux", target_os = "android"))]
|
#[cfg(any(target_os = "linux", target_os = "android"))]
|
||||||
use std::os::unix::io::AsRawFd;
|
use std::os::unix::io::AsRawFd;
|
||||||
|
|
||||||
|
/// # Safety
|
||||||
|
/// This function is unsafe because it calls `libc::sync` or `libc::syscall` which are unsafe.
|
||||||
pub unsafe fn do_sync() -> isize {
|
pub unsafe fn do_sync() -> isize {
|
||||||
// see https://github.com/rust-lang/libc/pull/2161
|
// see https://github.com/rust-lang/libc/pull/2161
|
||||||
#[cfg(target_os = "android")]
|
#[cfg(target_os = "android")]
|
||||||
|
@ -46,6 +48,8 @@ mod platform {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(any(target_os = "linux", target_os = "android"))]
|
#[cfg(any(target_os = "linux", target_os = "android"))]
|
||||||
|
/// # Safety
|
||||||
|
/// This function is unsafe because it calls `libc::syscall` which is unsafe.
|
||||||
pub unsafe fn do_syncfs(files: Vec<String>) -> isize {
|
pub unsafe fn do_syncfs(files: Vec<String>) -> isize {
|
||||||
for path in files {
|
for path in files {
|
||||||
let f = File::open(path).unwrap();
|
let f = File::open(path).unwrap();
|
||||||
|
@ -56,6 +60,8 @@ mod platform {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(any(target_os = "linux", target_os = "android"))]
|
#[cfg(any(target_os = "linux", target_os = "android"))]
|
||||||
|
/// # Safety
|
||||||
|
/// This function is unsafe because it calls `libc::syscall` which is unsafe.
|
||||||
pub unsafe fn do_fdatasync(files: Vec<String>) -> isize {
|
pub unsafe fn do_fdatasync(files: Vec<String>) -> isize {
|
||||||
for path in files {
|
for path in files {
|
||||||
let f = File::open(path).unwrap();
|
let f = File::open(path).unwrap();
|
||||||
|
@ -81,6 +87,8 @@ mod platform {
|
||||||
};
|
};
|
||||||
use windows_sys::Win32::System::WindowsProgramming::DRIVE_FIXED;
|
use windows_sys::Win32::System::WindowsProgramming::DRIVE_FIXED;
|
||||||
|
|
||||||
|
/// # Safety
|
||||||
|
/// This function is unsafe because it calls an unsafe function.
|
||||||
unsafe fn flush_volume(name: &str) {
|
unsafe fn flush_volume(name: &str) {
|
||||||
let name_wide = name.to_wide_null();
|
let name_wide = name.to_wide_null();
|
||||||
if GetDriveTypeW(name_wide.as_ptr()) == DRIVE_FIXED {
|
if GetDriveTypeW(name_wide.as_ptr()) == DRIVE_FIXED {
|
||||||
|
@ -99,6 +107,8 @@ mod platform {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// # Safety
|
||||||
|
/// This function is unsafe because it calls an unsafe function.
|
||||||
unsafe fn find_first_volume() -> (String, HANDLE) {
|
unsafe fn find_first_volume() -> (String, HANDLE) {
|
||||||
let mut name: [u16; MAX_PATH as usize] = [0; MAX_PATH as usize];
|
let mut name: [u16; MAX_PATH as usize] = [0; MAX_PATH as usize];
|
||||||
let handle = FindFirstVolumeW(name.as_mut_ptr(), name.len() as u32);
|
let handle = FindFirstVolumeW(name.as_mut_ptr(), name.len() as u32);
|
||||||
|
@ -108,6 +118,8 @@ mod platform {
|
||||||
(String::from_wide_null(&name), handle)
|
(String::from_wide_null(&name), handle)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// # Safety
|
||||||
|
/// This function is unsafe because it calls an unsafe function.
|
||||||
unsafe fn find_all_volumes() -> Vec<String> {
|
unsafe fn find_all_volumes() -> Vec<String> {
|
||||||
let (first_volume, next_volume_handle) = find_first_volume();
|
let (first_volume, next_volume_handle) = find_first_volume();
|
||||||
let mut volumes = vec![first_volume];
|
let mut volumes = vec![first_volume];
|
||||||
|
@ -127,6 +139,8 @@ mod platform {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// # Safety
|
||||||
|
/// This function is unsafe because it calls `find_all_volumes` which is unsafe.
|
||||||
pub unsafe fn do_sync() -> isize {
|
pub unsafe fn do_sync() -> isize {
|
||||||
let volumes = find_all_volumes();
|
let volumes = find_all_volumes();
|
||||||
for vol in &volumes {
|
for vol in &volumes {
|
||||||
|
@ -135,6 +149,8 @@ mod platform {
|
||||||
0
|
0
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// # Safety
|
||||||
|
/// This function is unsafe because it calls `find_all_volumes` which is unsafe.
|
||||||
pub unsafe fn do_syncfs(files: Vec<String>) -> isize {
|
pub unsafe fn do_syncfs(files: Vec<String>) -> isize {
|
||||||
for path in files {
|
for path in files {
|
||||||
flush_volume(
|
flush_volume(
|
||||||
|
|
|
@ -161,7 +161,9 @@ pub struct Passwd {
|
||||||
pub expiration: time_t,
|
pub expiration: time_t,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// SAFETY: ptr must point to a valid C string.
|
/// # Safety
|
||||||
|
/// ptr must point to a valid C string.
|
||||||
|
///
|
||||||
/// Returns None if ptr is null.
|
/// Returns None if ptr is null.
|
||||||
unsafe fn cstr2string(ptr: *const c_char) -> Option<String> {
|
unsafe fn cstr2string(ptr: *const c_char) -> Option<String> {
|
||||||
if ptr.is_null() {
|
if ptr.is_null() {
|
||||||
|
@ -172,7 +174,8 @@ unsafe fn cstr2string(ptr: *const c_char) -> Option<String> {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Passwd {
|
impl Passwd {
|
||||||
/// SAFETY: All the pointed-to strings must be valid and not change while
|
/// # Safety
|
||||||
|
/// All the pointed-to strings must be valid and not change while
|
||||||
/// the function runs. That means PW_LOCK must be held.
|
/// the function runs. That means PW_LOCK must be held.
|
||||||
unsafe fn from_raw(raw: passwd) -> Self {
|
unsafe fn from_raw(raw: passwd) -> Self {
|
||||||
Self {
|
Self {
|
||||||
|
@ -246,7 +249,8 @@ pub struct Group {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Group {
|
impl Group {
|
||||||
/// SAFETY: gr_name must be valid and not change while
|
/// # Safety
|
||||||
|
/// gr_name must be valid and not change while
|
||||||
/// the function runs. That means PW_LOCK must be held.
|
/// the function runs. That means PW_LOCK must be held.
|
||||||
unsafe fn from_raw(raw: group) -> Self {
|
unsafe fn from_raw(raw: group) -> Self {
|
||||||
Self {
|
Self {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue