refactor/du ~ polish spelling (comments, names, and exceptions)

This commit is contained in:
Roy Ivy III 2021-05-29 22:23:11 -05:00
parent dfe594e918
commit 6e1bd6027a
2 changed files with 25 additions and 28 deletions

View file

@ -6,9 +6,6 @@
// For the full copyright and license information, please view the LICENSE file
// that was distributed with this source code.
// spell-checker:ignore (ToDO) mountinfo BLOCKSIZE fobj mptr noatime Iused overmounted
// spell-checker:ignore (libc/fs) asyncreads asyncwrites autofs bavail bfree bsize charspare cifs debugfs devfs devpts ffree frsize fsid fstypename fusectl inode inodes iosize kernfs mntbufp mntfromname mntonname mqueue namemax pipefs smbfs statvfs subfs syncreads syncwrites sysfs wcslen
#[macro_use]
extern crate uucore;
#[cfg(unix)]
@ -78,7 +75,7 @@ struct Options {
#[derive(Debug, Clone)]
struct Filesystem {
mountinfo: MountInfo,
mount_info: MountInfo,
usage: FsUsage,
}
@ -131,19 +128,19 @@ impl Options {
}
impl Filesystem {
// TODO: resolve uuid in `mountinfo.dev_name` if exists
fn new(mountinfo: MountInfo) -> Option<Filesystem> {
let _stat_path = if !mountinfo.mount_dir.is_empty() {
mountinfo.mount_dir.clone()
// TODO: resolve uuid in `mount_info.dev_name` if exists
fn new(mount_info: MountInfo) -> Option<Filesystem> {
let _stat_path = if !mount_info.mount_dir.is_empty() {
mount_info.mount_dir.clone()
} else {
#[cfg(unix)]
{
mountinfo.dev_name.clone()
mount_info.dev_name.clone()
}
#[cfg(windows)]
{
// On windows, we expect the volume id
mountinfo.dev_id.clone()
mount_info.dev_id.clone()
}
};
#[cfg(unix)]
@ -154,14 +151,14 @@ impl Filesystem {
None
} else {
Some(Filesystem {
mountinfo,
mount_info,
usage: FsUsage::new(statvfs),
})
}
}
#[cfg(windows)]
Some(Filesystem {
mountinfo,
mount_info,
usage: FsUsage::new(Path::new(&_stat_path)),
})
}
@ -205,7 +202,7 @@ fn filter_mount_list(vmi: Vec<MountInfo>, paths: &[String], opt: &Options) -> Ve
if (!mi.dev_name.starts_with('/') || seen.dev_name.starts_with('/'))
// let points towards the root of the device win.
&& (!target_nearer_root || source_below_root)
// let an entry overmounted on a new device win...
// let an entry over-mounted on a new device win...
&& (seen.dev_name == mi.dev_name
/* ... but only when matching an existing mnt point,
to avoid problematic replacement when given
@ -431,6 +428,7 @@ pub fn uumain(args: impl uucore::Args) -> i32 {
header.push("Type");
}
header.extend_from_slice(&if opt.show_inode_instead {
// spell-checker:disable-next-line
["Inodes", "Iused", "IFree", "IUses%"]
} else {
[
@ -462,9 +460,9 @@ pub fn uumain(args: impl uucore::Args) -> i32 {
}
println!();
for fs in fs_list.iter() {
print!("{0: <16} ", fs.mountinfo.dev_name);
print!("{0: <16} ", fs.mount_info.dev_name);
if opt.show_fs_type {
print!("{0: <5} ", fs.mountinfo.fs_type);
print!("{0: <5} ", fs.mount_info.fs_type);
}
if opt.show_inode_instead {
print!(
@ -508,7 +506,7 @@ pub fn uumain(args: impl uucore::Args) -> i32 {
}
print!("{0: >5} ", use_size(free_size, total_size));
}
print!("{0: <16}", fs.mountinfo.mount_dir);
print!("{0: <16}", fs.mount_info.mount_dir);
println!();
}

View file

@ -60,14 +60,13 @@ const VERSION: &str = env!("CARGO_PKG_VERSION");
const NAME: &str = "du";
const SUMMARY: &str = "estimate file space usage";
const LONG_HELP: &str = "
Display values are in units of the first available SIZE from
--block-size, and the DU_BLOCK_SIZE, BLOCK_SIZE and BLOCKSIZE environ
ment variables. Otherwise, units default to 1024 bytes (or 512 if
POSIXLY_CORRECT is set).
Display values are in units of the first available SIZE from --block-size,
and the DU_BLOCK_SIZE, BLOCK_SIZE and BLOCKSIZE environment variables.
Otherwise, units default to 1024 bytes (or 512 if POSIXLY_CORRECT is set).
SIZE is an integer and optional unit (example: 10M is 10*1024*1024).
Units are K, M, G, T, P, E, Z, Y (powers of 1024) or KB, MB, ... (pow
ers of 1000).
SIZE is an integer and optional unit (example: 10M is 10*1024*1024).
Units are K, M, G, T, P, E, Z, Y (powers of 1024) or KB, MB,... (powers
of 1000).
";
// TODO: Support Z & Y (currently limited by size of u64)
@ -586,7 +585,7 @@ pub fn uumain(args: impl uucore::Args) -> i32 {
separate_dirs: matches.is_present(options::SEPARATE_DIRS),
};
let strs = match matches.value_of(options::FILE) {
let files = match matches.value_of(options::FILE) {
Some(_) => matches.values_of(options::FILE).unwrap().collect(),
None => {
vec!["./"] // TODO: gnu `du` doesn't use trailing "/" here
@ -644,8 +643,8 @@ Try '{} --help' for more information.",
};
let mut grand_total = 0;
for path_str in strs {
let path = PathBuf::from(&path_str);
for path_string in files {
let path = PathBuf::from(&path_string);
match Stat::new(path) {
Ok(stat) => {
let mut inodes: HashSet<FileInfo> = HashSet::new();
@ -707,13 +706,13 @@ Try '{} --help' for more information.",
}
if options.total && index == (len - 1) {
// The last element will be the total size of the the path under
// path_str. We add it to the grand total.
// path_string. We add it to the grand total.
grand_total += size;
}
}
}
Err(_) => {
show_error!("{}: {}", path_str, "No such file or directory");
show_error!("{}: {}", path_string, "No such file or directory");
}
}
}