1
- use std:: { ffi:: OsString , path:: PathBuf } ;
2
-
3
1
use crate :: {
4
2
backend:: node:: { Metadata , Node , NodeType } ,
5
3
blob:: tree:: comp_to_osstr,
6
4
} ;
7
5
6
+ use typed_path:: UnixPathBuf ;
7
+
8
8
/// `TreeIterator` turns an Iterator yielding items with paths and Nodes into an
9
9
/// Iterator which ensures that all subdirectories are visited and closed.
10
10
/// The resulting Iterator yielss a `TreeType` which either contains the original
@@ -18,7 +18,7 @@ pub(crate) struct TreeIterator<T, I> {
18
18
/// The original Iterator.
19
19
iter : I ,
20
20
/// The current path.
21
- path : PathBuf ,
21
+ path : UnixPathBuf ,
22
22
/// The current item.
23
23
item : Option < T > ,
24
24
}
31
31
let item = iter. next ( ) ;
32
32
Self {
33
33
iter,
34
- path : PathBuf :: new ( ) ,
34
+ path : UnixPathBuf :: new ( ) ,
35
35
item,
36
36
}
37
37
}
@@ -49,32 +49,25 @@ where
49
49
#[ derive( Debug ) ]
50
50
pub ( crate ) enum TreeType < T , U > {
51
51
/// New tree to be inserted.
52
- NewTree ( ( PathBuf , Node , U ) ) ,
52
+ NewTree ( ( UnixPathBuf , Node , U ) ) ,
53
53
/// A pseudo item which indicates that a tree is finished.
54
54
EndTree ,
55
55
/// Original item.
56
- Other ( ( PathBuf , Node , T ) ) ,
56
+ Other ( ( UnixPathBuf , Node , T ) ) ,
57
57
}
58
58
59
- impl < I , O > Iterator for TreeIterator < ( PathBuf , Node , O ) , I >
59
+ impl < I , O > Iterator for TreeIterator < ( UnixPathBuf , Node , O ) , I >
60
60
where
61
- I : Iterator < Item = ( PathBuf , Node , O ) > ,
61
+ I : Iterator < Item = ( UnixPathBuf , Node , O ) > ,
62
62
{
63
- type Item = TreeType < O , OsString > ;
63
+ type Item = TreeType < O , Vec < u8 > > ;
64
64
fn next ( & mut self ) -> Option < Self :: Item > {
65
65
match & self . item {
66
66
None => {
67
67
if self . path . pop ( ) {
68
68
Some ( TreeType :: EndTree )
69
69
} 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
- }
70
+ None
78
71
}
79
72
}
80
73
Some ( ( path, node, _) ) => {
@@ -91,16 +84,20 @@ where
91
84
if node. is_dir ( ) && path == & self . path {
92
85
let ( path, node, _) = self . item . take ( ) . unwrap ( ) ;
93
86
self . item = self . iter . next ( ) ;
94
- let name = node. name ( ) ;
87
+ let name = node. name ( ) . to_vec ( ) ;
95
88
return Some ( TreeType :: NewTree ( ( path, node, name) ) ) ;
96
89
}
97
90
// Use mode 755 for missing dirs, so they can be accessed
98
91
let meta = Metadata {
99
92
mode : Some ( 0o755 ) ,
100
93
..Default :: default ( )
101
94
} ;
102
- let node = Node :: new_node ( & p, NodeType :: Dir , meta) ;
103
- return Some ( TreeType :: NewTree ( ( self . path . clone ( ) , node, p) ) ) ;
95
+ let node = Node :: new_node ( p, NodeType :: Dir , meta) ;
96
+ return Some ( TreeType :: NewTree ( (
97
+ self . path . clone ( ) ,
98
+ node,
99
+ p. to_vec ( ) ,
100
+ ) ) ) ;
104
101
}
105
102
}
106
103
// there wasn't any normal path component to process - return current item
0 commit comments