1- use std :: { ffi :: OsString , path :: PathBuf } ;
1+ use crate :: backend :: node :: { Metadata , Node , NodeType } ;
22
3- use crate :: {
4- backend:: node:: { Metadata , Node , NodeType } ,
5- blob:: tree:: comp_to_osstr,
6- } ;
3+ use typed_path:: { Component , UnixPathBuf } ;
74
85/// `TreeIterator` turns an Iterator yielding items with paths and Nodes into an
96/// Iterator which ensures that all subdirectories are visited and closed.
@@ -18,7 +15,7 @@ pub(crate) struct TreeIterator<T, I> {
1815 /// The original Iterator.
1916 iter : I ,
2017 /// The current path.
21- path : PathBuf ,
18+ path : UnixPathBuf ,
2219 /// The current item.
2320 item : Option < T > ,
2421}
3128 let item = iter. next ( ) ;
3229 Self {
3330 iter,
34- path : PathBuf :: new ( ) ,
31+ path : UnixPathBuf :: new ( ) ,
3532 item,
3633 }
3734 }
@@ -49,32 +46,25 @@ where
4946#[ derive( Debug ) ]
5047pub ( crate ) enum TreeType < T , U > {
5148 /// New tree to be inserted.
52- NewTree ( ( PathBuf , Node , U ) ) ,
49+ NewTree ( ( UnixPathBuf , Node , U ) ) ,
5350 /// A pseudo item which indicates that a tree is finished.
5451 EndTree ,
5552 /// Original item.
56- Other ( ( PathBuf , Node , T ) ) ,
53+ Other ( ( UnixPathBuf , Node , T ) ) ,
5754}
5855
59- impl < I , O > Iterator for TreeIterator < ( PathBuf , Node , O ) , I >
56+ impl < I , O > Iterator for TreeIterator < ( UnixPathBuf , Node , O ) , I >
6057where
61- I : Iterator < Item = ( PathBuf , Node , O ) > ,
58+ I : Iterator < Item = ( UnixPathBuf , Node , O ) > ,
6259{
63- type Item = TreeType < O , OsString > ;
60+ type Item = TreeType < O , Vec < u8 > > ;
6461 fn next ( & mut self ) -> Option < Self :: Item > {
6562 match & self . item {
6663 None => {
6764 if self . path . pop ( ) {
6865 Some ( TreeType :: EndTree )
6966 } else {
70- // Check if we still have a path prefix open...
71- match self . path . components ( ) . next ( ) {
72- Some ( std:: path:: Component :: Prefix ( ..) ) => {
73- self . path = PathBuf :: new ( ) ;
74- Some ( TreeType :: EndTree )
75- }
76- _ => None ,
77- }
67+ None
7868 }
7969 }
8070 Some ( ( path, node, _) ) => {
@@ -84,24 +74,25 @@ where
8474 Some ( TreeType :: EndTree )
8575 }
8676 Ok ( missing_dirs) => {
87- for comp in missing_dirs. components ( ) {
88- self . path . push ( comp) ;
89- // process next normal path component - other components are simply ignored
90- if let Some ( p) = comp_to_osstr ( comp) . ok ( ) . flatten ( ) {
91- if node. is_dir ( ) && path == & self . path {
92- let ( path, node, _) = self . item . take ( ) . unwrap ( ) ;
93- self . item = self . iter . next ( ) ;
94- let name = node. name ( ) ;
95- return Some ( TreeType :: NewTree ( ( path, node, name) ) ) ;
96- }
97- // Use mode 755 for missing dirs, so they can be accessed
98- let meta = Metadata {
99- mode : Some ( 0o755 ) ,
100- ..Default :: default ( )
101- } ;
102- let node = Node :: new_node ( & p, NodeType :: Dir , meta) ;
103- return Some ( TreeType :: NewTree ( ( self . path . clone ( ) , node, p) ) ) ;
77+ if let Some ( p) = missing_dirs. components ( ) . next ( ) {
78+ self . path . push ( p) ;
79+ if node. is_dir ( ) && path == & self . path {
80+ let ( path, node, _) = self . item . take ( ) . unwrap ( ) ;
81+ self . item = self . iter . next ( ) ;
82+ let name = node. name ( ) . to_vec ( ) ;
83+ return Some ( TreeType :: NewTree ( ( path, node, name) ) ) ;
10484 }
85+ // Use mode 755 for missing dirs, so they can be accessed
86+ let meta = Metadata {
87+ mode : Some ( 0o755 ) ,
88+ ..Default :: default ( )
89+ } ;
90+ let node = Node :: new_node ( p. as_bytes ( ) , NodeType :: Dir , meta) ;
91+ return Some ( TreeType :: NewTree ( (
92+ self . path . clone ( ) ,
93+ node,
94+ p. as_bytes ( ) . to_vec ( ) ,
95+ ) ) ) ;
10596 }
10697 // there wasn't any normal path component to process - return current item
10798 let item = self . item . take ( ) . unwrap ( ) ;
0 commit comments