|
|
|
@ -1,6 +1,6 @@
|
|
|
|
|
use super::*;
|
|
|
|
|
use std::collections::HashMap;
|
|
|
|
|
use std::path::PathBuf;
|
|
|
|
|
use std::path::{Path,PathBuf};
|
|
|
|
|
use std::borrow::Borrow;
|
|
|
|
|
|
|
|
|
|
/// Contains a graph of all paths and inodes that were successfully stat'd
|
|
|
|
@ -88,6 +88,17 @@ enum NodeKind
|
|
|
|
|
File(u64),
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl NodeKind
|
|
|
|
|
{
|
|
|
|
|
pub fn len(&self) -> Option<u64>
|
|
|
|
|
{
|
|
|
|
|
match self {
|
|
|
|
|
Self::File(f) => Some(*f),
|
|
|
|
|
Self::Directory(_, o) => *o,
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[derive(Debug, Clone, PartialEq, Eq)]
|
|
|
|
|
struct HierarchicalNode
|
|
|
|
|
{
|
|
|
|
@ -95,6 +106,26 @@ struct HierarchicalNode
|
|
|
|
|
inode: INode,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl HierarchicalNode
|
|
|
|
|
{
|
|
|
|
|
#[inline(always)] pub fn len(&self) -> Option<u64>
|
|
|
|
|
{
|
|
|
|
|
self.kind.len()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub fn is_dir(&self) -> bool
|
|
|
|
|
{
|
|
|
|
|
match self.kind {
|
|
|
|
|
NodeKind::Directory(_, _) => true,
|
|
|
|
|
_ => false
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
#[inline] pub fn is_file(&self) -> bool
|
|
|
|
|
{
|
|
|
|
|
!self.is_dir()
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// A hierarchical graph of node sizes
|
|
|
|
|
#[derive(Debug, Clone, PartialEq, Eq)]
|
|
|
|
|
pub struct HierarchicalINodeGraph
|
|
|
|
@ -210,6 +241,25 @@ impl HierarchicalINodeGraph
|
|
|
|
|
|
|
|
|
|
new
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// Get the max size and the path with this size
|
|
|
|
|
pub fn path_max_size_for(&self, kind: FsObjKind) -> Option<(&Path, u64)>
|
|
|
|
|
{
|
|
|
|
|
self.table.iter().filter_map(|(path, hi)| {
|
|
|
|
|
match kind {
|
|
|
|
|
FsObjKind::File if hi.is_file() => hi.len().map(|x| (path.as_path(), x)),
|
|
|
|
|
FsObjKind::Directory if hi.is_dir() => hi.len().map(|x| (path.as_path(), x)),
|
|
|
|
|
_ => None
|
|
|
|
|
}
|
|
|
|
|
}).max_by_key(|x| x.1)
|
|
|
|
|
}
|
|
|
|
|
/// Get the max size and the path with this size, whether it's a `Directory` or a `File`.
|
|
|
|
|
pub fn path_max_size(&self) -> Option<(&Path, u64)>
|
|
|
|
|
{
|
|
|
|
|
self.table.iter().filter_map(|(path, hi)| {
|
|
|
|
|
hi.len().map(|x| (path.as_path(), x))
|
|
|
|
|
}).max_by_key(|x| x.1)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl From<INodeInfoGraph> for HierarchicalINodeGraph
|
|
|
|
@ -219,3 +269,11 @@ impl From<INodeInfoGraph> for HierarchicalINodeGraph
|
|
|
|
|
Self::create(from)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// A file or directory
|
|
|
|
|
#[derive(Debug, Clone, PartialEq, Eq, Hash, PartialOrd, Ord, Copy)]
|
|
|
|
|
pub enum FsObjKind
|
|
|
|
|
{
|
|
|
|
|
Directory,
|
|
|
|
|
File,
|
|
|
|
|
}
|
|
|
|
|