From 2fac6743176a05ef75ffcfae8b36d3bafd437dc0 Mon Sep 17 00:00:00 2001 From: Jeffrey Finkelstein Date: Sat, 12 Mar 2022 17:06:03 -0500 Subject: [PATCH] df: move Filesystem to filesystem.rs Move the `Filesystem` struct into a new module `filesystem.rs`. --- src/uu/df/src/df.rs | 36 +++------------------------------ src/uu/df/src/filesystem.rs | 40 +++++++++++++++++++++++++++++++++++++ src/uu/df/src/table.rs | 3 ++- 3 files changed, 45 insertions(+), 34 deletions(-) create mode 100644 src/uu/df/src/filesystem.rs diff --git a/src/uu/df/src/df.rs b/src/uu/df/src/df.rs index 854bc2a48..b877faa72 100644 --- a/src/uu/df/src/df.rs +++ b/src/uu/df/src/df.rs @@ -8,13 +8,12 @@ // spell-checker:ignore itotal iused iavail ipcent pcent tmpfs squashfs lofs mod blocks; mod columns; +mod filesystem; mod table; use uucore::error::{UResult, USimpleError}; use uucore::format_usage; -#[cfg(unix)] -use uucore::fsext::statfs; -use uucore::fsext::{read_fs_list, FsUsage, MountInfo}; +use uucore::fsext::{read_fs_list, MountInfo}; 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::columns::Column; +use crate::filesystem::Filesystem; use crate::table::{DisplayRow, Header, Row}; 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 { - 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. fn is_included(mi: &MountInfo, opt: &Options) -> bool { // Don't show remote filesystems if `--local` has been given. diff --git a/src/uu/df/src/filesystem.rs b/src/uu/df/src/filesystem.rs new file mode 100644 index 000000000..fac85500c --- /dev/null +++ b/src/uu/df/src/filesystem.rs @@ -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 { + 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 }) + } +} diff --git a/src/uu/df/src/table.rs b/src/uu/df/src/table.rs index 1e59c4ad6..a126876dd 100644 --- a/src/uu/df/src/table.rs +++ b/src/uu/df/src/table.rs @@ -12,7 +12,8 @@ use number_prefix::NumberPrefix; use crate::columns::Column; -use crate::{BlockSize, Filesystem, Options}; +use crate::filesystem::Filesystem; +use crate::{BlockSize, Options}; use uucore::fsext::{FsUsage, MountInfo}; use std::fmt;