@@ -102,23 +102,31 @@ pub(crate) struct ComponentBuilder<'a> {
102
102
103
103
impl < ' a > ComponentBuilder < ' a > {
104
104
pub ( crate ) fn copy_file ( & mut self , path : PathBuf , src : & Path ) -> Result < ( ) > {
105
- self . parts
106
- . push ( ComponentPart ( "file" . to_owned ( ) , path. clone ( ) ) ) ;
105
+ self . parts . push ( ComponentPart {
106
+ kind : "file" . to_owned ( ) ,
107
+ path : path. clone ( ) ,
108
+ } ) ;
107
109
self . tx . copy_file ( & self . name , path, src)
108
110
}
109
111
pub ( crate ) fn copy_dir ( & mut self , path : PathBuf , src : & Path ) -> Result < ( ) > {
110
- self . parts
111
- . push ( ComponentPart ( "dir" . to_owned ( ) , path. clone ( ) ) ) ;
112
+ self . parts . push ( ComponentPart {
113
+ kind : "dir" . to_owned ( ) ,
114
+ path : path. clone ( ) ,
115
+ } ) ;
112
116
self . tx . copy_dir ( & self . name , path, src)
113
117
}
114
118
pub ( crate ) fn move_file ( & mut self , path : PathBuf , src : & Path ) -> Result < ( ) > {
115
- self . parts
116
- . push ( ComponentPart ( "file" . to_owned ( ) , path. clone ( ) ) ) ;
119
+ self . parts . push ( ComponentPart {
120
+ kind : "file" . to_owned ( ) ,
121
+ path : path. clone ( ) ,
122
+ } ) ;
117
123
self . tx . move_file ( & self . name , path, src)
118
124
}
119
125
pub ( crate ) fn move_dir ( & mut self , path : PathBuf , src : & Path ) -> Result < ( ) > {
120
- self . parts
121
- . push ( ComponentPart ( "dir" . to_owned ( ) , path. clone ( ) ) ) ;
126
+ self . parts . push ( ComponentPart {
127
+ kind : "dir" . to_owned ( ) ,
128
+ path : path. clone ( ) ,
129
+ } ) ;
122
130
self . tx . move_dir ( & self . name , path, src)
123
131
}
124
132
pub ( crate ) fn finish ( mut self ) -> Result < Transaction < ' a > > {
@@ -146,7 +154,13 @@ impl<'a> ComponentBuilder<'a> {
146
154
}
147
155
148
156
#[ derive( Debug ) ]
149
- pub struct ComponentPart ( pub String , pub PathBuf ) ;
157
+ pub struct ComponentPart {
158
+ /// Kind of the [`ComponentPart`], such as `"file"` or `"dir"`.
159
+ pub kind : String ,
160
+ /// Relative path of the [`ComponentPart`],
161
+ /// with components separated by the system's main path separator.
162
+ pub path : PathBuf ,
163
+ }
150
164
151
165
impl ComponentPart {
152
166
const PATH_SEP_MANIFEST : & str = "/" ;
@@ -155,11 +169,11 @@ impl ComponentPart {
155
169
pub ( crate ) fn encode ( & self ) -> String {
156
170
// Lossy conversion is safe here because we assume that `path` comes from
157
171
// `ComponentPart::decode()`, i.e. from calling `Path::from()` on a `&str`.
158
- let mut path = self . 1 . to_string_lossy ( ) ;
172
+ let mut path = self . path . to_string_lossy ( ) ;
159
173
if Self :: PATH_SEP_MAIN != Self :: PATH_SEP_MANIFEST {
160
174
path = Cow :: Owned ( path. replace ( Self :: PATH_SEP_MAIN , Self :: PATH_SEP_MANIFEST ) ) ;
161
175
} ;
162
- format ! ( "{}:{path}" , self . 0 )
176
+ format ! ( "{}:{path}" , self . kind )
163
177
}
164
178
165
179
pub ( crate ) fn decode ( line : & str ) -> Option < Self > {
@@ -169,7 +183,10 @@ impl ComponentPart {
169
183
path_str =
170
184
Cow :: Owned ( path_str. replace ( Self :: PATH_SEP_MANIFEST , Self :: PATH_SEP_MAIN ) ) ;
171
185
} ;
172
- Self ( line[ 0 ..pos] . to_owned ( ) , PathBuf :: from ( path_str. as_ref ( ) ) )
186
+ Self {
187
+ kind : line[ 0 ..pos] . to_owned ( ) ,
188
+ path : PathBuf :: from ( path_str. as_ref ( ) ) ,
189
+ }
173
190
} )
174
191
}
175
192
}
@@ -322,12 +339,12 @@ impl Component {
322
339
prefix : self . components . prefix . abs_path ( "" ) ,
323
340
} ;
324
341
for part in self . parts ( ) ?. into_iter ( ) . rev ( ) {
325
- match & * part. 0 {
326
- "file" => tx. remove_file ( & self . name , part. 1 . clone ( ) ) ?,
327
- "dir" => tx. remove_dir ( & self . name , part. 1 . clone ( ) ) ?,
342
+ match & * part. kind {
343
+ "file" => tx. remove_file ( & self . name , part. path . clone ( ) ) ?,
344
+ "dir" => tx. remove_dir ( & self . name , part. path . clone ( ) ) ?,
328
345
_ => return Err ( RustupError :: CorruptComponent ( self . name . clone ( ) ) . into ( ) ) ,
329
346
}
330
- pset. seen ( part. 1 ) ;
347
+ pset. seen ( part. path ) ;
331
348
}
332
349
for empty_dir in pset {
333
350
tx. remove_dir ( & self . name , empty_dir) ?;
@@ -346,20 +363,20 @@ mod tests {
346
363
347
364
#[ test]
348
365
fn decode_component_part ( ) {
349
- let ComponentPart ( kind , path ) = ComponentPart :: decode ( "dir:share/doc/rust/html" ) . unwrap ( ) ;
350
- assert_eq ! ( kind, "dir" ) ;
366
+ let part = ComponentPart :: decode ( "dir:share/doc/rust/html" ) . unwrap ( ) ;
367
+ assert_eq ! ( part . kind, "dir" ) ;
351
368
assert_eq ! (
352
- path,
369
+ part . path,
353
370
Path :: new( & "share/doc/rust/html" . replace( "/" , ComponentPart :: PATH_SEP_MAIN ) )
354
371
) ;
355
372
}
356
373
357
374
#[ test]
358
375
fn encode_component_part ( ) {
359
- let part = ComponentPart (
360
- "dir" . to_owned ( ) ,
361
- [ "share" , "doc" , "rust" , "html" ] . into_iter ( ) . collect ( ) ,
362
- ) ;
376
+ let part = ComponentPart {
377
+ kind : "dir" . to_owned ( ) ,
378
+ path : [ "share" , "doc" , "rust" , "html" ] . into_iter ( ) . collect ( ) ,
379
+ } ;
363
380
assert_eq ! ( part. encode( ) , "dir:share/doc/rust/html" ) ;
364
381
}
365
382
}
0 commit comments