@@ -2,7 +2,8 @@ use crate::interactive::path_of;
22use dua:: traverse:: { EntryData , Tree , TreeIndex } ;
33use itertools:: Itertools ;
44use petgraph:: Direction ;
5- use std:: cmp:: Ordering ;
5+ use std:: path:: Path ;
6+ use std:: { cmp:: Ordering , path:: PathBuf } ;
67use unicode_segmentation:: UnicodeSegmentation ;
78
89#[ derive( Default , Debug , Copy , Clone , PartialOrd , PartialEq , Eq ) ]
@@ -50,9 +51,21 @@ pub struct EntryDataBundle {
5051 pub data : EntryData ,
5152 pub is_dir : bool ,
5253 pub exists : bool ,
54+ pub glob_name : Option < PathBuf > ,
5355}
5456
55- pub fn sorted_entries ( tree : & Tree , node_idx : TreeIndex , sorting : SortMode ) -> Vec < EntryDataBundle > {
57+ impl EntryDataBundle {
58+ pub fn name ( & self ) -> & Path {
59+ self . glob_name . as_deref ( ) . unwrap_or ( & self . data . name )
60+ }
61+ }
62+
63+ pub fn sorted_entries (
64+ tree : & Tree ,
65+ node_idx : TreeIndex ,
66+ sorting : SortMode ,
67+ glob_root : Option < TreeIndex > ,
68+ ) -> Vec < EntryDataBundle > {
5669 use SortMode :: * ;
5770 fn cmp_count ( l : & EntryDataBundle , r : & EntryDataBundle ) -> Ordering {
5871 l. data
@@ -63,13 +76,18 @@ pub fn sorted_entries(tree: &Tree, node_idx: TreeIndex, sorting: SortMode) -> Ve
6376 tree. neighbors_directed ( node_idx, Direction :: Outgoing )
6477 . filter_map ( |idx| {
6578 tree. node_weight ( idx) . map ( |w| {
66- let p = path_of ( tree, idx) ;
79+ let mut use_glob_path = false ;
80+ if let Some ( glob_root) = glob_root {
81+ use_glob_path = node_idx == glob_root;
82+ }
83+ let p = path_of ( tree, idx, glob_root) ;
6784 let pm = p. symlink_metadata ( ) ;
6885 EntryDataBundle {
6986 index : idx,
7087 data : w. clone ( ) ,
7188 exists : pm. is_ok ( ) ,
7289 is_dir : pm. ok ( ) . map_or ( false , |m| m. is_dir ( ) ) ,
90+ glob_name : if use_glob_path { Some ( p) } else { None } ,
7391 }
7492 } )
7593 } )
0 commit comments