mirror of
https://github.com/uutils/coreutils.git
synced 2026-06-10 15:48:22 -07:00
df: get rid of clone calls
This commit is contained in:
committed by
Daniel Hofstetter
parent
91328849a2
commit
77302dbc87
+9
-17
@@ -333,25 +333,17 @@ fn get_all_filesystems(opt: &Options) -> UResult<Vec<Filesystem>> {
|
||||
|
||||
// Convert each `MountInfo` into a `Filesystem`, which contains
|
||||
// both the mount information and usage information.
|
||||
|
||||
#[cfg(not(windows))]
|
||||
{
|
||||
let maybe_mount = |m| Filesystem::from_mount(&mounts, &m, None).ok();
|
||||
Ok(mounts
|
||||
.clone()
|
||||
.into_iter()
|
||||
.filter_map(maybe_mount)
|
||||
.filter(|fs| opt.show_all_fs || fs.usage.blocks > 0)
|
||||
.collect())
|
||||
}
|
||||
let maybe_mount = |m| Filesystem::from_mount(&mounts, m, None).ok();
|
||||
#[cfg(windows)]
|
||||
{
|
||||
let maybe_mount = |m| Filesystem::from_mount(&m, None).ok();
|
||||
Ok(mounts
|
||||
.into_iter()
|
||||
.filter_map(maybe_mount)
|
||||
.filter(|fs| opt.show_all_fs || fs.usage.blocks > 0)
|
||||
.collect())
|
||||
}
|
||||
let maybe_mount = |m| Filesystem::from_mount(m, None).ok();
|
||||
|
||||
Ok(mounts
|
||||
.iter()
|
||||
.filter_map(maybe_mount)
|
||||
.filter(|fs| opt.show_all_fs || fs.usage.blocks > 0)
|
||||
.collect())
|
||||
}
|
||||
|
||||
/// For each path, get the filesystem that contains that path.
|
||||
|
||||
@@ -134,8 +134,7 @@ where
|
||||
// make code more testable
|
||||
.map(|m| (m, std::fs::canonicalize(&m.dev_name)))
|
||||
// Ignore non existing paths
|
||||
.filter(|m| m.1.is_ok())
|
||||
.map(|m| (m.0, m.1.ok().unwrap()))
|
||||
.filter_map(|m| m.1.ok().map(|m1| (m.0, m1)))
|
||||
// Try to find canonicalized device name corresponding to entered path
|
||||
.find(|m| m.1.eq(&path))
|
||||
.map(|m| m.0);
|
||||
@@ -156,20 +155,20 @@ impl Filesystem {
|
||||
let stat_path = if mount_info.mount_dir.is_empty() {
|
||||
#[cfg(unix)]
|
||||
{
|
||||
mount_info.dev_name.clone().into()
|
||||
mount_info.dev_name.as_ref()
|
||||
}
|
||||
#[cfg(windows)]
|
||||
{
|
||||
// On windows, we expect the volume id
|
||||
mount_info.dev_id.clone().into()
|
||||
mount_info.dev_id.as_ref()
|
||||
}
|
||||
} else {
|
||||
mount_info.mount_dir.clone()
|
||||
mount_info.mount_dir.as_os_str()
|
||||
};
|
||||
#[cfg(unix)]
|
||||
let usage = FsUsage::new(statfs(&stat_path).ok()?);
|
||||
let usage = FsUsage::new(statfs(stat_path).ok()?);
|
||||
#[cfg(windows)]
|
||||
let usage = FsUsage::new(Path::new(&stat_path)).ok()?;
|
||||
let usage = FsUsage::new(Path::new(stat_path)).ok()?;
|
||||
Some(Self {
|
||||
file,
|
||||
mount_info,
|
||||
@@ -234,12 +233,10 @@ impl Filesystem {
|
||||
where
|
||||
P: AsRef<Path>,
|
||||
{
|
||||
let file = path.as_ref().as_os_str().to_owned();
|
||||
let path = path.as_ref();
|
||||
let file = path.as_os_str().to_owned();
|
||||
|
||||
let canonical_path = path
|
||||
.as_ref()
|
||||
.canonicalize()
|
||||
.map_err(|_| FsError::InvalidPath)?;
|
||||
let canonical_path = path.canonicalize().map_err(|_| FsError::InvalidPath)?;
|
||||
|
||||
let stat_result = statfs(canonical_path.as_os_str()).map_err(|_| FsError::MountMissing)?;
|
||||
let mount_dir = find_mount_point(&canonical_path).map_err(|_| FsError::MountMissing)?;
|
||||
|
||||
@@ -1123,7 +1123,7 @@ mod tests {
|
||||
..Default::default()
|
||||
};
|
||||
|
||||
let table = Table::new(&options, filesystems.clone());
|
||||
let table = Table::new(&options, filesystems);
|
||||
let mut data: Vec<u8> = vec![];
|
||||
table.write_to(&mut data).expect("Write error.");
|
||||
assert_eq!(
|
||||
|
||||
Reference in New Issue
Block a user