df: move Filesystem to filesystem.rs

Move the `Filesystem` struct into a new module `filesystem.rs`.
This commit is contained in:
Jeffrey Finkelstein 2022-03-12 17:06:03 -05:00
parent d6dad9f412
commit 2fac674317
3 changed files with 45 additions and 34 deletions

View file

@ -8,13 +8,12 @@
// spell-checker:ignore itotal iused iavail ipcent pcent tmpfs squashfs lofs // spell-checker:ignore itotal iused iavail ipcent pcent tmpfs squashfs lofs
mod blocks; mod blocks;
mod columns; mod columns;
mod filesystem;
mod table; mod table;
use uucore::error::{UResult, USimpleError}; use uucore::error::{UResult, USimpleError};
use uucore::format_usage; use uucore::format_usage;
#[cfg(unix)] use uucore::fsext::{read_fs_list, MountInfo};
use uucore::fsext::statfs;
use uucore::fsext::{read_fs_list, FsUsage, MountInfo};
use clap::{crate_version, App, AppSettings, Arg, ArgMatches}; use clap::{crate_version, App, AppSettings, Arg, ArgMatches};
@ -23,6 +22,7 @@ use std::path::Path;
use crate::blocks::{block_size_from_matches, BlockSize}; use crate::blocks::{block_size_from_matches, BlockSize};
use crate::columns::Column; use crate::columns::Column;
use crate::filesystem::Filesystem;
use crate::table::{DisplayRow, Header, Row}; use crate::table::{DisplayRow, Header, Row};
static ABOUT: &str = "Show information about the file system on which each FILE resides,\n\ static ABOUT: &str = "Show information about the file system on which each FILE resides,\n\
@ -136,36 +136,6 @@ impl Options {
} }
} }
#[derive(Debug, Clone)]
struct Filesystem {
mount_info: MountInfo,
usage: FsUsage,
}
impl Filesystem {
// TODO: resolve uuid in `mount_info.dev_name` if exists
fn new(mount_info: MountInfo) -> Option<Self> {
let _stat_path = if !mount_info.mount_dir.is_empty() {
mount_info.mount_dir.clone()
} else {
#[cfg(unix)]
{
mount_info.dev_name.clone()
}
#[cfg(windows)]
{
// On windows, we expect the volume id
mount_info.dev_id.clone()
}
};
#[cfg(unix)]
let usage = FsUsage::new(statfs(_stat_path).ok()?);
#[cfg(windows)]
let usage = FsUsage::new(Path::new(&_stat_path));
Some(Self { mount_info, usage })
}
}
/// Whether to display the mount info given the inclusion settings. /// Whether to display the mount info given the inclusion settings.
fn is_included(mi: &MountInfo, opt: &Options) -> bool { fn is_included(mi: &MountInfo, opt: &Options) -> bool {
// Don't show remote filesystems if `--local` has been given. // Don't show remote filesystems if `--local` has been given.

View file

@ -0,0 +1,40 @@
// * This file is part of the uutils coreutils package.
// *
// * For the full copyright and license information, please view the LICENSE
// * file that was distributed with this source code.
#[cfg(windows)]
use std::path::Path;
#[cfg(unix)]
use uucore::fsext::statfs;
use uucore::fsext::{FsUsage, MountInfo};
#[derive(Debug, Clone)]
pub(crate) struct Filesystem {
pub mount_info: MountInfo,
pub usage: FsUsage,
}
impl Filesystem {
// TODO: resolve uuid in `mount_info.dev_name` if exists
pub(crate) fn new(mount_info: MountInfo) -> Option<Self> {
let _stat_path = if !mount_info.mount_dir.is_empty() {
mount_info.mount_dir.clone()
} else {
#[cfg(unix)]
{
mount_info.dev_name.clone()
}
#[cfg(windows)]
{
// On windows, we expect the volume id
mount_info.dev_id.clone()
}
};
#[cfg(unix)]
let usage = FsUsage::new(statfs(_stat_path).ok()?);
#[cfg(windows)]
let usage = FsUsage::new(Path::new(&_stat_path));
Some(Self { mount_info, usage })
}
}

View file

@ -12,7 +12,8 @@
use number_prefix::NumberPrefix; use number_prefix::NumberPrefix;
use crate::columns::Column; use crate::columns::Column;
use crate::{BlockSize, Filesystem, Options}; use crate::filesystem::Filesystem;
use crate::{BlockSize, Options};
use uucore::fsext::{FsUsage, MountInfo}; use uucore::fsext::{FsUsage, MountInfo};
use std::fmt; use std::fmt;