@ -3,6 +3,7 @@
#[ macro_use ] extern crate pin_project ;
#[ macro_use ] extern crate lazy_static ;
#[ macro_use ] extern crate cfg_if ;
#[ cfg(feature= " inspect " ) ] use serde ::{ Serialize , Deserialize } ;
@ -28,6 +29,7 @@ use color_eyre::{
#[ macro_use ] mod ext ;
pub use ext ::prelude ::* ;
use std ::sync ::Arc ;
mod bytes ;
mod data ;
@ -38,39 +40,14 @@ mod work;
#[ cfg(feature= " inspect " ) ] mod serial ;
#[ cfg(feature= " defer-drop " ) ] mod defer_drop ;
async fn normal ( cfg : config ::Config ) -> eyre ::Result < ( ) >
#[ cfg(feature= " inspect " ) ]
async fn write_graph ( graph : Arc < data ::HierarchicalINodeGraph > ) -> eyre ::Result < ( ) >
{
let state = state ::State ::new ( cfg
. validate ( )
. wrap_err ( eyre ! ( "Invalid config" ) )
. with_suggestion ( | | "Try running `--help`" ) ? ) ;
let ( graph , cfg ) = tokio ::select ! {
x = work ::work_on_all ( state ) = > { x }
_ = tokio ::signal ::ctrl_c ( ) = > {
return Err ( eyre ! ( "Interrupt signalled, exiting" ) ) ;
}
} ;
let cfg = cfg . make_global ( ) ;
let graph = tokio ::task ::spawn_blocking ( move | | {
cfg_println ! ( Verbose ; cfg , "Computing hierarchy..." ) ;
let mut graph = graph . into_hierarchical ( ) ;
cfg_println ! ( Verbose ; cfg , "Computing sizes..." ) ;
graph . compute_recursive_sizes ( ) ;
graph
} ) . await . expect ( "Failed to compute hierarchy from graph" ) ;
#[ cfg(debug_assertions) ] cfg_eprintln ! ( Verbose ; cfg , "{:?}" , graph ) ;
cfg_println ! ( Quiet ; cfg , "Max size file: {:?}" , graph . path_max_size_for ( data ::FsKind ::File ) ) ;
cfg_println ! ( Quiet ; cfg , "Max size dir: {:?}" , graph . path_max_size_for ( data ::FsKind ::Directory ) ) ;
cfg_println ! ( Quiet ; cfg , "Max size all: {:?}" , graph . path_max_size ( ) ) ;
#[ cfg(feature= " inspect " ) ]
let cfg = config ::get_global ( ) ;
match cfg . serialise_output . as_ref ( ) . map ( | ser_out | {
type BoxedWrite = Box < dyn tokio ::io ::AsyncWrite + Unpin > ;
cfg_eprintln ! ( Verbose ; cfg , "Writing graph to stream..." ) ;
type BoxedWrite = Box < dyn tokio ::io ::AsyncWrite + Unpin + Send + Sync > ;
use futures ::FutureExt ;
use config ::OutputSerialisationMode ;
let should_comp = ser_out . should_compress ( ) ;
@ -105,7 +82,7 @@ async fn normal(cfg: config::Config) -> eyre::Result<()>
// `.2` indicates if we should compress while in normal write mode.
Some ( ( stream_fut , None , compress ) ) = > {
let stream = stream_fut . await ? ;
serial ::write_async ( stream , & graph , compress ) . await
serial ::write_async ( stream , graph . as_ref ( ) , compress ) . await
. wrap_err ( eyre ! ( "Failed to serialise graph to stream" ) ) ? ;
} ,
#[ cfg(feature= " prealloc " ) ] Some ( ( _task_fut , Some ( output_file ) , _ ) ) = > {
@ -120,7 +97,7 @@ async fn normal(cfg: config::Config) -> eyre::Result<()>
. with_section ( | | format! ( "{:?}" , output_file ) . header ( "File was" ) ) ? ;
let mut file = file . into_std ( ) . await ;
tokio ::task ::spawn_blocking ( move | | {
serial ::write_sync_map ( & mut file , & graph )
serial ::write_sync_map ( & mut file , graph . as_ref ( ) )
} ) . await . wrap_err ( eyre ! ( "Prealloc panicked while dumping" ) )
. with_section ( | | format! ( "{:?}" , output_file ) . header ( "File was" ) ) ?
. wrap_err ( eyre ! ( "Prealloc failed to dump graph to file" ) )
@ -128,6 +105,60 @@ async fn normal(cfg: config::Config) -> eyre::Result<()>
} ,
_ = > ( ) ,
}
Ok ( ( ) )
}
async fn normal ( cfg : config ::Config ) -> eyre ::Result < ( ) >
{
let state = state ::State ::new ( cfg
. validate ( )
. wrap_err ( eyre ! ( "Invalid config" ) )
. with_suggestion ( | | "Try running `--help`" ) ? ) ;
let ( graph , cfg ) = tokio ::select ! {
x = work ::work_on_all ( state ) = > { x }
_ = tokio ::signal ::ctrl_c ( ) = > {
return Err ( eyre ! ( "Interrupt signalled, exiting" ) ) ;
}
} ;
let cfg = cfg . make_global ( ) ;
let graph = tokio ::task ::spawn_blocking ( move | | {
cfg_println ! ( Verbose ; cfg , "Computing hierarchy..." ) ;
let mut graph = graph . into_hierarchical ( ) ;
cfg_println ! ( Verbose ; cfg , "Computing sizes..." ) ;
graph . compute_recursive_sizes ( ) ;
graph
} ) . await . expect ( "Failed to compute hierarchy from graph" ) ;
//#[cfg(debug_assertions)] cfg_eprintln!(Verbose; cfg, "{:?}", graph);
use futures ::future ::OptionFuture ;
let ( graph , writer ) = {
cfg_if ! {
if #[ cfg(feature= " inspect " ) ] {
let graph = Arc ::new ( graph ) ;
( Arc ::clone ( & graph ) , OptionFuture ::from ( Some ( tokio ::spawn ( write_graph ( graph ) ) ) ) )
} else {
( graph , OptionFuture ::from ( Option ::< futures ::future ::BoxFuture < ' static , ( ) > > ::None ) )
}
}
} ;
cfg_println ! ( Quiet ; cfg , "Max size file: {:?}" , graph . path_max_size_for ( data ::FsKind ::File ) ) ;
cfg_println ! ( Quiet ; cfg , "Max size dir: {:?}" , graph . path_max_size_for ( data ::FsKind ::Directory ) ) ;
cfg_println ! ( Quiet ; cfg , "Max size all: {:?}" , graph . path_max_size ( ) ) ;
#[ cfg(feature= " inspect " ) ]
match writer . await {
None = > ( ) ,
Some ( Ok ( Ok ( _ ) ) ) = > cfg_eprintln ! ( Verbose ; cfg , "Written successfully" ) ,
Some ( Ok ( error ) ) = > return error . wrap_err ( eyre ! ( "Failed to write graph to output stream" ) ) ,
Some ( Err ( _ ) ) = > cfg_eprintln ! ( Silent ; cfg , "Panic while writing graph to stream" ) ,
}
#[ cfg(not(feature= " inspect " )) ] drop ( writer ) ;
Ok ( ( ) )
}