1
Fork 0
mirror of https://github.com/RGBCube/uutils-coreutils synced 2025-07-28 19:47:45 +00:00

fix(df): Improve MacOSX support

This commit is contained in:
Sylvestre Ledru 2020-04-21 00:28:53 +02:00 committed by Roy Ivy III
parent dd1a212550
commit 8545f03e0f

View file

@ -25,25 +25,39 @@ use kernel32::{
FindFirstVolumeW, FindNextVolumeW, FindVolumeClose, GetDiskFreeSpaceW, GetDriveTypeW,
GetLastError, GetVolumeInformationW, GetVolumePathNamesForVolumeNameW, QueryDosDeviceW,
};
#[cfg(unix)]
#[cfg(target_os = "macos")]
use libc::statfs;
use std::cell::Cell;
use std::collections::HashMap;
use std::collections::HashSet;
use std::ffi::CString;
#[cfg(unix)]
use std::{env, mem};
#[cfg(target_os = "macos")]
use libc::c_int;
#[cfg(target_os = "macos")]
use libc::statfs;
#[cfg(target_os = "macos")]
use std::ffi::CStr;
#[cfg(target_os = "macos")]
use std::ptr;
#[cfg(target_os = "macos")]
use std::slice;
#[cfg(target_os = "linux")]
use std::fs::File;
#[cfg(target_os = "linux")]
use std::io::{BufRead, BufReader};
#[cfg(windows)]
use std::os::windows::prelude::*;
use std::{env, mem};
static VERSION: &str = env!("CARGO_PKG_VERSION");
static ABOUT: &str = "Show information about the file system on which each FILE resides,\n\
or all file systems by default.";
const EXIT_OK: i32 = 0;
static EXIT_OK: i32 = 0;
#[cfg(any(target_os = "freebsd", target_os = "macos", target_os = "windows"))]
static EXIT_ERR: i32 = 1;
#[cfg(windows)]
const MAX_PATH: usize = 266;
@ -493,10 +507,10 @@ fn read_fs_list() -> Vec<MountInfo> {
crash!(EXIT_ERR, "getmntinfo failed");
}
let mounts = unsafe { slice::from_raw_parts(mptr, len as usize) };
return mounts
.into_iter()
mounts
.iter()
.map(|m| MountInfo::from(*m))
.collect::<Vec<_>>();
.collect::<Vec<_>>()
}
#[cfg(windows)]
{
@ -543,7 +557,6 @@ fn read_fs_list() -> Vec<MountInfo> {
}
}
#[allow(clippy::map_entry)]
fn filter_mount_list(vmi: Vec<MountInfo>, opt: &Options) -> Vec<MountInfo> {
vmi.into_iter()
.filter_map(|mi| {
@ -559,6 +572,8 @@ fn filter_mount_list(vmi: Vec<MountInfo>, opt: &Options) -> Vec<MountInfo> {
.fold(
HashMap::<String, Cell<MountInfo>>::new(),
|mut acc, (id, mi)| {
#[allow(clippy::map_entry)]
{
if acc.contains_key(&id) {
let seen = acc.get(&id).unwrap().replace(mi.clone());
let target_nearer_root = seen.mount_dir.len() > mi.mount_dir.len();
@ -584,6 +599,7 @@ fn filter_mount_list(vmi: Vec<MountInfo>, opt: &Options) -> Vec<MountInfo> {
acc.insert(id, Cell::new(mi));
}
acc
}
},
)
.into_iter()