@@ -27,6 +27,7 @@ use rustup_dist::manifestation::{Manifestation, UpdateStatus, Changes};
27
27
use rustup_dist:: manifest:: { Manifest , Component } ;
28
28
use url:: Url ;
29
29
use std:: cell:: Cell ;
30
+ use std:: collections:: HashMap ;
30
31
use std:: fs;
31
32
use std:: path:: Path ;
32
33
use std:: sync:: Arc ;
@@ -41,7 +42,7 @@ pub fn create_mock_dist_server(path: &Path,
41
42
channels : vec ! [
42
43
create_mock_channel( "nightly" , "2016-02-01" , edit) ,
43
44
create_mock_channel( "nightly" , "2016-02-02" , edit) ,
44
- ]
45
+ ]
45
46
}
46
47
}
47
48
@@ -183,26 +184,7 @@ pub fn create_mock_channel(channel: &str, date: &str,
183
184
184
185
// An extra package that can be used as a component of the other packages
185
186
// for various tests
186
- let bonus_pkg = MockPackage {
187
- name : "bonus" ,
188
- version : "1.0.0" ,
189
- targets : vec ! [
190
- MockTargetedPackage {
191
- target: "x86_64-apple-darwin" . to_string( ) ,
192
- available: true ,
193
- components: vec![ ] ,
194
- extensions: vec![ ] ,
195
- installer: MockInstallerBuilder {
196
- components: vec![ MockComponentBuilder {
197
- name: "bonus-x86_64-apple-darwin" . to_string( ) ,
198
- files: vec![
199
- MockFile :: new_arc( "bin/bonus" , contents. clone( ) ) ,
200
- ] ,
201
- } ] ,
202
- }
203
- } ,
204
- ]
205
- } ;
187
+ let bonus_pkg = bonus_component ( "bonus" , contents. clone ( ) ) ;
206
188
207
189
let mut rust_pkg = rust_pkg;
208
190
if let Some ( edit) = edit {
@@ -217,7 +199,31 @@ pub fn create_mock_channel(channel: &str, date: &str,
217
199
rustc_pkg,
218
200
std_pkg,
219
201
bonus_pkg,
220
- ]
202
+ ] ,
203
+ renames : HashMap :: new ( ) ,
204
+ }
205
+ }
206
+
207
+ fn bonus_component ( name : & ' static str , contents : Arc < Vec < u8 > > ) -> MockPackage {
208
+ MockPackage {
209
+ name : name,
210
+ version : "1.0.0" ,
211
+ targets : vec ! [
212
+ MockTargetedPackage {
213
+ target: "x86_64-apple-darwin" . to_string( ) ,
214
+ available: true ,
215
+ components: vec![ ] ,
216
+ extensions: vec![ ] ,
217
+ installer: MockInstallerBuilder {
218
+ components: vec![ MockComponentBuilder {
219
+ name: format!( "{}-x86_64-apple-darwin" , name) ,
220
+ files: vec![
221
+ MockFile :: new_arc( & * format!( "bin/{}" , name) , contents) ,
222
+ ] ,
223
+ } ] ,
224
+ }
225
+ } ,
226
+ ]
221
227
}
222
228
}
223
229
@@ -240,6 +246,134 @@ fn mock_dist_server_smoke_test() {
240
246
assert ! ( utils:: path_exists( path. join( "dist/channel-rust-nightly.toml.sha256" ) ) ) ;
241
247
}
242
248
249
+ // Test that a standard rename works - the component is installed with the old name, then renamed
250
+ // the next day to the new name.
251
+ #[ test]
252
+ fn rename_component ( ) {
253
+ let dist_tempdir = TempDir :: new ( "rustup" ) . unwrap ( ) ;
254
+ let ref url = Url :: parse ( & format ! ( "file://{}" , dist_tempdir. path( ) . to_string_lossy( ) ) ) . unwrap ( ) ;
255
+
256
+ let edit_1 = & |_: & str , pkg : & mut MockPackage | {
257
+ let tpkg = pkg. targets . iter_mut ( ) . find ( |p| p. target == "x86_64-apple-darwin" ) . unwrap ( ) ;
258
+ tpkg. components . push ( MockComponent {
259
+ name : "bonus" . to_string ( ) ,
260
+ target : "x86_64-apple-darwin" . to_string ( ) ,
261
+ } ) ;
262
+ } ;
263
+ let edit_2 = & |_: & str , pkg : & mut MockPackage | {
264
+ let tpkg = pkg. targets . iter_mut ( ) . find ( |p| p. target == "x86_64-apple-darwin" ) . unwrap ( ) ;
265
+ tpkg. components . push ( MockComponent {
266
+ name : "bobo" . to_string ( ) ,
267
+ target : "x86_64-apple-darwin" . to_string ( ) ,
268
+ } ) ;
269
+ } ;
270
+
271
+ let date_2 = "2016-02-02" ;
272
+ let mut channel_2 = create_mock_channel ( "nightly" , date_2, Some ( edit_2) ) ;
273
+ channel_2. packages [ 3 ] = bonus_component ( "bobo" , Arc :: new ( date_2. as_bytes ( ) . to_vec ( ) ) ) ;
274
+ channel_2. renames . insert ( "bonus" . to_owned ( ) , "bobo" . to_owned ( ) ) ;
275
+ let mock_dist_server = MockDistServer {
276
+ path : dist_tempdir. path ( ) . to_owned ( ) ,
277
+ channels : vec ! [
278
+ create_mock_channel( "nightly" , "2016-02-01" , Some ( edit_1) ) ,
279
+ channel_2,
280
+ ]
281
+ } ;
282
+
283
+ setup_from_dist_server ( mock_dist_server, url, false ,
284
+ & |url, toolchain, prefix, download_cfg, temp_cfg| {
285
+ change_channel_date ( url, "nightly" , "2016-02-01" ) ;
286
+ update_from_dist ( url, toolchain, prefix, & [ ] , & [ ] , download_cfg, temp_cfg) . unwrap ( ) ;
287
+ assert ! ( utils:: path_exists( & prefix. path( ) . join( "bin/bonus" ) ) ) ;
288
+ assert ! ( !utils:: path_exists( & prefix. path( ) . join( "bin/bobo" ) ) ) ;
289
+ change_channel_date ( url, "nightly" , "2016-02-02" ) ;
290
+ update_from_dist ( url, toolchain, prefix, & [ ] , & [ ] , download_cfg, temp_cfg) . unwrap ( ) ;
291
+ assert ! ( !utils:: path_exists( & prefix. path( ) . join( "bin/bonus" ) ) ) ;
292
+ assert ! ( utils:: path_exists( & prefix. path( ) . join( "bin/bobo" ) ) ) ;
293
+ } ) ;
294
+ }
295
+
296
+ // Test that a rename is ignored if the component with the new name is already installed.
297
+ #[ test]
298
+ fn rename_component_ignore ( ) {
299
+ let dist_tempdir = TempDir :: new ( "rustup" ) . unwrap ( ) ;
300
+ let ref url = Url :: parse ( & format ! ( "file://{}" , dist_tempdir. path( ) . to_string_lossy( ) ) ) . unwrap ( ) ;
301
+
302
+ let edit = & |_: & str , pkg : & mut MockPackage | {
303
+ let tpkg = pkg. targets . iter_mut ( ) . find ( |p| p. target == "x86_64-apple-darwin" ) . unwrap ( ) ;
304
+ tpkg. components . push ( MockComponent {
305
+ name : "bobo" . to_string ( ) ,
306
+ target : "x86_64-apple-darwin" . to_string ( ) ,
307
+ } ) ;
308
+ } ;
309
+
310
+ let date_1 = "2016-02-01" ;
311
+ let mut channel_1 = create_mock_channel ( "nightly" , date_1, Some ( edit) ) ;
312
+ channel_1. packages [ 3 ] = bonus_component ( "bobo" , Arc :: new ( date_1. as_bytes ( ) . to_vec ( ) ) ) ;
313
+ let date_2 = "2016-02-02" ;
314
+ let mut channel_2 = create_mock_channel ( "nightly" , date_2, Some ( edit) ) ;
315
+ channel_2. packages [ 3 ] = bonus_component ( "bobo" , Arc :: new ( date_2. as_bytes ( ) . to_vec ( ) ) ) ;
316
+ channel_2. renames . insert ( "bonus" . to_owned ( ) , "bobo" . to_owned ( ) ) ;
317
+ let mock_dist_server = MockDistServer {
318
+ path : dist_tempdir. path ( ) . to_owned ( ) ,
319
+ channels : vec ! [
320
+ channel_1,
321
+ channel_2,
322
+ ]
323
+ } ;
324
+
325
+ setup_from_dist_server ( mock_dist_server, url, false ,
326
+ & |url, toolchain, prefix, download_cfg, temp_cfg| {
327
+ change_channel_date ( url, "nightly" , "2016-02-01" ) ;
328
+ update_from_dist ( url, toolchain, prefix, & [ ] , & [ ] , download_cfg, temp_cfg) . unwrap ( ) ;
329
+ assert ! ( !utils:: path_exists( & prefix. path( ) . join( "bin/bonus" ) ) ) ;
330
+ assert ! ( utils:: path_exists( & prefix. path( ) . join( "bin/bobo" ) ) ) ;
331
+ change_channel_date ( url, "nightly" , "2016-02-02" ) ;
332
+ update_from_dist ( url, toolchain, prefix, & [ ] , & [ ] , download_cfg, temp_cfg) . unwrap ( ) ;
333
+ assert ! ( !utils:: path_exists( & prefix. path( ) . join( "bin/bonus" ) ) ) ;
334
+ assert ! ( utils:: path_exists( & prefix. path( ) . join( "bin/bobo" ) ) ) ;
335
+ } ) ;
336
+ }
337
+
338
+ // Test that a rename is ignored if the component with the old name was never installed.
339
+ #[ test]
340
+ fn rename_component_new ( ) {
341
+ let dist_tempdir = TempDir :: new ( "rustup" ) . unwrap ( ) ;
342
+ let ref url = Url :: parse ( & format ! ( "file://{}" , dist_tempdir. path( ) . to_string_lossy( ) ) ) . unwrap ( ) ;
343
+
344
+ let edit_2 = & |_: & str , pkg : & mut MockPackage | {
345
+ let tpkg = pkg. targets . iter_mut ( ) . find ( |p| p. target == "x86_64-apple-darwin" ) . unwrap ( ) ;
346
+ tpkg. components . push ( MockComponent {
347
+ name : "bobo" . to_string ( ) ,
348
+ target : "x86_64-apple-darwin" . to_string ( ) ,
349
+ } ) ;
350
+ } ;
351
+
352
+ let date_2 = "2016-02-02" ;
353
+ let mut channel_2 = create_mock_channel ( "nightly" , date_2, Some ( edit_2) ) ;
354
+ channel_2. packages [ 3 ] = bonus_component ( "bobo" , Arc :: new ( date_2. as_bytes ( ) . to_vec ( ) ) ) ;
355
+ channel_2. renames . insert ( "bonus" . to_owned ( ) , "bobo" . to_owned ( ) ) ;
356
+ let mock_dist_server = MockDistServer {
357
+ path : dist_tempdir. path ( ) . to_owned ( ) ,
358
+ channels : vec ! [
359
+ create_mock_channel( "nightly" , "2016-02-01" , None ) ,
360
+ channel_2,
361
+ ]
362
+ } ;
363
+
364
+ setup_from_dist_server ( mock_dist_server, url, false ,
365
+ & |url, toolchain, prefix, download_cfg, temp_cfg| {
366
+ change_channel_date ( url, "nightly" , "2016-02-01" ) ;
367
+ update_from_dist ( url, toolchain, prefix, & [ ] , & [ ] , download_cfg, temp_cfg) . unwrap ( ) ;
368
+ assert ! ( !utils:: path_exists( & prefix. path( ) . join( "bin/bonus" ) ) ) ;
369
+ assert ! ( !utils:: path_exists( & prefix. path( ) . join( "bin/bobo" ) ) ) ;
370
+ change_channel_date ( url, "nightly" , "2016-02-02" ) ;
371
+ update_from_dist ( url, toolchain, prefix, & [ ] , & [ ] , download_cfg, temp_cfg) . unwrap ( ) ;
372
+ assert ! ( !utils:: path_exists( & prefix. path( ) . join( "bin/bonus" ) ) ) ;
373
+ assert ! ( utils:: path_exists( & prefix. path( ) . join( "bin/bobo" ) ) ) ;
374
+ } ) ;
375
+ }
376
+
243
377
// Installs or updates a toolchain from a dist server. If an initial
244
378
// install then it will be installed with the default components. If
245
379
// an upgrade then all the existing components will be upgraded.
@@ -290,7 +424,15 @@ fn uninstall(toolchain: &ToolchainDesc, prefix: &InstallPrefix, temp_cfg: &temp:
290
424
fn setup ( edit : Option < & Fn ( & str , & mut MockPackage ) > , enable_xz : bool ,
291
425
f : & Fn ( & Url , & ToolchainDesc , & InstallPrefix , & DownloadCfg , & temp:: Cfg ) ) {
292
426
let dist_tempdir = TempDir :: new ( "rustup" ) . unwrap ( ) ;
293
- create_mock_dist_server ( dist_tempdir. path ( ) , edit) . write ( & [ ManifestVersion :: V2 ] , enable_xz) ;
427
+ let mock_dist_server = create_mock_dist_server ( dist_tempdir. path ( ) , edit) ;
428
+ let ref url = Url :: parse ( & format ! ( "file://{}" , dist_tempdir. path( ) . to_string_lossy( ) ) ) . unwrap ( ) ;
429
+ setup_from_dist_server ( mock_dist_server, url, enable_xz, f) ;
430
+ }
431
+
432
+
433
+ fn setup_from_dist_server ( server : MockDistServer , url : & Url , enable_xz : bool ,
434
+ f : & Fn ( & Url , & ToolchainDesc , & InstallPrefix , & DownloadCfg , & temp:: Cfg ) ) {
435
+ server. write ( & [ ManifestVersion :: V2 ] , enable_xz) ;
294
436
295
437
let prefix_tempdir = TempDir :: new ( "rustup" ) . unwrap ( ) ;
296
438
@@ -299,7 +441,6 @@ fn setup(edit: Option<&Fn(&str, &mut MockPackage)>, enable_xz: bool,
299
441
DEFAULT_DIST_SERVER ,
300
442
Box :: new ( |_| ( ) ) ) ;
301
443
302
- let ref url = Url :: parse ( & format ! ( "file://{}" , dist_tempdir. path( ) . to_string_lossy( ) ) ) . unwrap ( ) ;
303
444
let ref toolchain = ToolchainDesc :: from_str ( "nightly-x86_64-apple-darwin" ) . unwrap ( ) ;
304
445
let ref prefix = InstallPrefix :: from ( prefix_tempdir. path ( ) . to_owned ( ) ) ;
305
446
let ref download_cfg = DownloadCfg {
0 commit comments