Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 9 additions & 17 deletions src/uu/df/src/df.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
21 changes: 9 additions & 12 deletions src/uu/df/src/filesystem.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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,
Expand Down Expand Up @@ -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)?;
Expand Down
2 changes: 1 addition & 1 deletion src/uu/df/src/table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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!(
Expand Down
Loading