mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-07-29 12:07:46 +00:00
Merge pull request #3253 from jfinkels/df-filesystem-module-3
df: move Filesystem to filesystem.rs
This commit is contained in:
commit
8f97283cf3
3 changed files with 60 additions and 34 deletions
|
@ -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<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.
|
||||
fn is_included(mi: &MountInfo, opt: &Options) -> bool {
|
||||
// Don't show remote filesystems if `--local` has been given.
|
||||
|
|
55
src/uu/df/src/filesystem.rs
Normal file
55
src/uu/df/src/filesystem.rs
Normal file
|
@ -0,0 +1,55 @@
|
|||
// * 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.
|
||||
//! Provides a summary representation of a filesystem.
|
||||
//!
|
||||
//! A [`Filesystem`] struct represents a device containing a
|
||||
//! filesystem mounted at a particular directory. It also includes
|
||||
//! information on amount of space available and amount of space used.
|
||||
#[cfg(windows)]
|
||||
use std::path::Path;
|
||||
|
||||
#[cfg(unix)]
|
||||
use uucore::fsext::statfs;
|
||||
use uucore::fsext::{FsUsage, MountInfo};
|
||||
|
||||
/// Summary representation of a filesystem.
|
||||
///
|
||||
/// A [`Filesystem`] struct represents a device containing a
|
||||
/// filesystem mounted at a particular directory. The
|
||||
/// [`Filesystem::mount_info`] field exposes that information. The
|
||||
/// [`Filesystem::usage`] field provides information on the amount of
|
||||
/// space available on the filesystem and the amount of space used.
|
||||
#[derive(Debug, Clone)]
|
||||
pub(crate) struct Filesystem {
|
||||
/// Information about the mounted device, mount directory, and related options.
|
||||
pub mount_info: MountInfo,
|
||||
|
||||
/// Information about the amount of space used on the filesystem.
|
||||
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 })
|
||||
}
|
||||
}
|
|
@ -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;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue