From 47b5e97006e80f4c28d2aa7667488275fdbcf844 Mon Sep 17 00:00:00 2001 From: Avril Date: Tue, 9 Feb 2021 21:12:12 +0000 Subject: [PATCH] move INodeInfoGraph to data module --- src/data/graph.rs | 24 ++++++++++++++++++++++++ src/data/mod.rs | 3 +++ src/work.rs | 22 +++++----------------- 3 files changed, 32 insertions(+), 17 deletions(-) create mode 100644 src/data/graph.rs diff --git a/src/data/graph.rs b/src/data/graph.rs new file mode 100644 index 0000000..88f7b00 --- /dev/null +++ b/src/data/graph.rs @@ -0,0 +1,24 @@ +use super::*; +use std::collections::HashMap; +use std::path::PathBuf; + +/// Contains a graph of all paths and inodes that were successfully stat'd +#[derive(Debug, Clone, PartialEq, Eq)] +pub struct INodeInfoGraph +{ + inodes: HashMap, // FsInfo contains parent INode that can be used to look up again in this table + paths: HashMap, // map absolute paths to INodes to be looked up in `inodes` table. +} + +impl INodeInfoGraph +{ + /// Create a new graph from these linked `HashMap`s + #[inline] pub fn new(inodes: HashMap, paths: HashMap) -> Self + { + Self { + inodes, + paths + } + } + //TODO: Order by largest size, get and iter fns etc +} diff --git a/src/data/mod.rs b/src/data/mod.rs index d7e24d2..5a9cd7f 100644 --- a/src/data/mod.rs +++ b/src/data/mod.rs @@ -13,6 +13,7 @@ pub const CACHE_GATE_TIMEOUT: Duration = duration!(100 ms); pub const CACHE_GATED_LAG: Duration = duration!(10 ms); mod cache; pub use cache::Cache; +pub mod graph; pub use graph::INodeInfoGraph; /// A raw file or directory inode number /// @@ -60,6 +61,8 @@ impl From for u64 } } + + /// A valid file system info /// /// # Note diff --git a/src/work.rs b/src/work.rs index 977ae05..e3eb778 100644 --- a/src/work.rs +++ b/src/work.rs @@ -13,6 +13,7 @@ use tokio::fs; use data::INode; use data::FsInfo; use state::State; +use data::INodeInfoGraph; /// Join a root path onto this hashmap. fn join_root<'a>(root: impl AsRef + 'a, map: HashMap) -> impl Iterator + 'a @@ -35,19 +36,6 @@ async fn process_entry(entry: &tokio::fs::DirEntry, parent: INode) -> io::Result } } -/// Contains a graph of all paths and inodes that were successfully stat'd -#[derive(Debug, Clone, PartialEq, Eq)] -pub struct INodeInfoGraph -{ - inodes: HashMap, // FsInfo contains parent INode that can be used to look up again in this table - paths: HashMap, // map absolute paths to INodes to be looked up in `inodes` table. -} - -impl INodeInfoGraph -{ - //TODO: Order by largest size, get and iter fns etc -} - /// Walk on all paths in this state, then return a joined map of all /// /// # Panics @@ -94,10 +82,10 @@ pub async fn work_on_all(state: State) -> INodeInfoGraph } } - INodeInfoGraph { - inodes: ino_map, - paths: output, - } + INodeInfoGraph::new( + ino_map, + output, + ) } /// Walk this directory.