Removed needless pub fn, use different api for units (see d97f397a)

main
nick 2024-07-21 20:24:26 -04:00
parent d97f397afc
commit b68556ae7f
1 changed files with 5 additions and 9 deletions

View File

@ -21,11 +21,6 @@ impl Directory {
self.size
}
#[inline]
pub fn path(&self) -> &Path {
self.name.as_ref()
}
pub fn new< P: AsRef<Path> >(path: P, args: &Args) -> Result<Option<Self>> {
let path = path.as_ref();
// NOTE: I go back and forth on canonicalize()ing all the time.
@ -46,6 +41,7 @@ impl Directory {
// symlink_metadata() is the same as metadata() but it doesn't
// traverse symlinks, so that we can exclude them if necessary
// note: sizeof(Metadata) == 176
let meta = match path.symlink_metadata() {
Ok(md) => md,
Err(_) if args.persistant() => return Ok(None),
@ -66,7 +62,7 @@ impl Directory {
return Ok(Some(
Self {
name,
size: meta.len(),
size: args.len(&meta),
children: Vec::new()
}
))
@ -85,7 +81,7 @@ impl Directory {
(Err(e), false) => return Err(e),
};
size += dir.size;
if args.tree() && args.should_print(dir.path()) {
if args.tree() && args.should_print(&dir.name) {
// since size was increased, this just prevents
// the directory from appearing in printing
children.push(dir);
@ -144,7 +140,7 @@ impl Directory {
pub fn tree(self, unit: Unit) -> String {
// since self.size is definitionally the greatest value, the tab length
// is just the length of self.len, plus two for a tab width
let tab_size = unit.convert(self.size).len() + 2;
let tab_size = unit.convert_with_units(self.size).len() + 2;
self.vectorise(unit)
.iter()
.map(|e| e.stringify_tabbed(tab_size))
@ -209,7 +205,7 @@ impl TreeEntry {
}
fn stringify_tabbed(&self, tab_size: usize) -> String {
let mut result = format!("{:<tab_size$}", self.unit.convert(self.size));
let mut result = format!("{:<tab_size$}", self.unit.convert_with_units(self.size));
for part in self.parts.iter().rev() {
result += part.display();