@@ -59,12 +59,11 @@ pub fn install(
59
59
vers,
60
60
opts,
61
61
force,
62
+ no_track,
62
63
true ,
63
64
) ?;
64
65
if let Some ( pkg) = pkg {
65
- install_one (
66
- config, & root, source_id, from_cwd, vers, opts, force, no_track, pkg,
67
- ) ?;
66
+ install_one ( config, & root, source_id, vers, opts, force, no_track, pkg) ?;
68
67
}
69
68
( true , false )
70
69
} else {
@@ -86,6 +85,7 @@ pub fn install(
86
85
vers,
87
86
opts,
88
87
force,
88
+ no_track,
89
89
!did_update,
90
90
) {
91
91
Ok ( Some ( pkg) ) => {
@@ -105,9 +105,7 @@ pub fn install(
105
105
continue ;
106
106
}
107
107
} ;
108
- match install_one (
109
- config, & root, source_id, from_cwd, vers, opts, force, no_track, pkg,
110
- ) {
108
+ match install_one ( config, & root, source_id, vers, opts, force, no_track, pkg) {
111
109
Ok ( ( ) ) => {
112
110
succeeded. push ( krate) ;
113
111
}
@@ -169,6 +167,7 @@ fn determine_package(
169
167
vers : Option < & str > ,
170
168
opts : & ops:: CompileOptions ,
171
169
force : bool ,
170
+ no_track : bool ,
172
171
needs_update_if_source_is_index : bool ,
173
172
) -> CargoResult < Option < Package > > {
174
173
if let Some ( name) = krate {
@@ -266,23 +265,8 @@ fn determine_package(
266
265
)
267
266
}
268
267
} ;
269
- Ok ( Some ( pkg) )
270
- }
271
268
272
- fn install_one (
273
- config : & Config ,
274
- root : & Filesystem ,
275
- source_id : SourceId ,
276
- from_cwd : bool ,
277
- vers : Option < & str > ,
278
- opts : & ops:: CompileOptions ,
279
- force : bool ,
280
- no_track : bool ,
281
- pkg : Package ,
282
- ) -> CargoResult < ( ) > {
283
- let dst = root. join ( "bin" ) . into_path_unlocked ( ) ;
284
-
285
- let ( mut ws, rustc, target) = make_ws_rustc_target ( config, opts, & source_id, pkg. clone ( ) ) ?;
269
+ let ( ws, rustc, target) = make_ws_rustc_target ( config, opts, & source_id, pkg. clone ( ) ) ?;
286
270
// If we're installing in --locked mode and there's no `Cargo.lock` published
287
271
// ie. the bin was published before https://github.com/rust-lang/cargo/pull/7026
288
272
if config. locked ( ) && !ws. root ( ) . join ( "Cargo.lock" ) . exists ( ) {
@@ -299,22 +283,6 @@ fn install_one(
299
283
ws. current ( ) ?. clone ( )
300
284
} ;
301
285
302
- let mut td_opt = None ;
303
- let mut needs_cleanup = false ;
304
- if !source_id. is_path ( ) {
305
- let target_dir = if let Some ( dir) = config. target_dir ( ) ? {
306
- dir
307
- } else if let Ok ( td) = TempFileBuilder :: new ( ) . prefix ( "cargo-install" ) . tempdir ( ) {
308
- let p = td. path ( ) . to_owned ( ) ;
309
- td_opt = Some ( td) ;
310
- Filesystem :: new ( p)
311
- } else {
312
- needs_cleanup = true ;
313
- Filesystem :: new ( config. cwd ( ) . join ( "target-install" ) )
314
- } ;
315
- ws. set_target_dir ( target_dir) ;
316
- }
317
-
318
286
if from_cwd {
319
287
if pkg. manifest ( ) . edition ( ) == Edition :: Edition2015 {
320
288
config. shell ( ) . warn (
@@ -345,40 +313,77 @@ fn install_one(
345
313
) ;
346
314
}
347
315
348
- // Helper for --no-track flag to make sure it doesn't overwrite anything.
349
- let no_track_duplicates = || -> CargoResult < BTreeMap < String , Option < PackageId > > > {
350
- let duplicates: BTreeMap < String , Option < PackageId > > = exe_names ( & pkg, & opts. filter )
351
- . into_iter ( )
352
- . filter ( |name| dst. join ( name) . exists ( ) )
353
- . map ( |name| ( name, None ) )
354
- . collect ( ) ;
355
- if !force && !duplicates. is_empty ( ) {
356
- let mut msg: Vec < String > = duplicates
357
- . iter ( )
358
- . map ( |( name, _) | format ! ( "binary `{}` already exists in destination" , name) )
359
- . collect ( ) ;
360
- msg. push ( "Add --force to overwrite" . to_string ( ) ) ;
361
- bail ! ( "{}" , msg. join( "\n " ) ) ;
362
- }
363
- Ok ( duplicates)
364
- } ;
365
-
366
316
// WARNING: no_track does not perform locking, so there is no protection
367
317
// of concurrent installs.
368
318
if no_track {
369
319
// Check for conflicts.
370
- no_track_duplicates ( ) ?;
320
+ no_track_duplicates ( & pkg , opts , & dst , force ) ?;
371
321
} else if is_installed ( & pkg, config, opts, & rustc, & target, root, & dst, force) ? {
372
322
let msg = format ! (
373
323
"package `{}` is already installed, use --force to override" ,
374
324
pkg
375
325
) ;
376
326
config. shell ( ) . status ( "Ignored" , & msg) ?;
377
- return Ok ( ( ) ) ;
327
+ return Ok ( None ) ;
378
328
}
379
329
330
+ Ok ( Some ( pkg) )
331
+ }
332
+
333
+ fn no_track_duplicates (
334
+ pkg : & Package ,
335
+ opts : & ops:: CompileOptions ,
336
+ dst : & Path ,
337
+ force : bool ,
338
+ ) -> CargoResult < BTreeMap < String , Option < PackageId > > > {
339
+ // Helper for --no-track flag to make sure it doesn't overwrite anything.
340
+ let duplicates: BTreeMap < String , Option < PackageId > > = exe_names ( & pkg, & opts. filter )
341
+ . into_iter ( )
342
+ . filter ( |name| dst. join ( name) . exists ( ) )
343
+ . map ( |name| ( name, None ) )
344
+ . collect ( ) ;
345
+ if !force && !duplicates. is_empty ( ) {
346
+ let mut msg: Vec < String > = duplicates
347
+ . iter ( )
348
+ . map ( |( name, _) | format ! ( "binary `{}` already exists in destination" , name) )
349
+ . collect ( ) ;
350
+ msg. push ( "Add --force to overwrite" . to_string ( ) ) ;
351
+ bail ! ( "{}" , msg. join( "\n " ) ) ;
352
+ }
353
+ Ok ( duplicates)
354
+ }
355
+
356
+ fn install_one < ' cfg > (
357
+ config : & Config ,
358
+ root : & Filesystem ,
359
+ source_id : SourceId ,
360
+ vers : Option < & str > ,
361
+ opts : & ops:: CompileOptions ,
362
+ force : bool ,
363
+ no_track : bool ,
364
+ pkg : Package ,
365
+ ) -> CargoResult < ( ) > {
380
366
config. shell ( ) . status ( "Installing" , & pkg) ?;
381
367
368
+ let dst = root. join ( "bin" ) . into_path_unlocked ( ) ;
369
+ let ( mut ws, rustc, target) = make_ws_rustc_target ( config, opts, & source_id, pkg. clone ( ) ) ?;
370
+
371
+ let mut td_opt = None ;
372
+ let mut needs_cleanup = false ;
373
+ if !source_id. is_path ( ) {
374
+ let target_dir = if let Some ( dir) = config. target_dir ( ) ? {
375
+ dir
376
+ } else if let Ok ( td) = TempFileBuilder :: new ( ) . prefix ( "cargo-install" ) . tempdir ( ) {
377
+ let p = td. path ( ) . to_owned ( ) ;
378
+ td_opt = Some ( td) ;
379
+ Filesystem :: new ( p)
380
+ } else {
381
+ needs_cleanup = true ;
382
+ Filesystem :: new ( config. cwd ( ) . join ( "target-install" ) )
383
+ } ;
384
+ ws. set_target_dir ( target_dir) ;
385
+ }
386
+
382
387
check_yanked_install ( & ws) ?;
383
388
384
389
let exec: Arc < dyn Executor > = Arc :: new ( DefaultExecutor ) ;
@@ -414,7 +419,7 @@ fn install_one(
414
419
binaries. sort_unstable ( ) ;
415
420
416
421
let ( tracker, duplicates) = if no_track {
417
- ( None , no_track_duplicates ( ) ?)
422
+ ( None , no_track_duplicates ( & pkg , opts , & dst , force ) ?)
418
423
} else {
419
424
let tracker = InstallTracker :: load ( config, root) ?;
420
425
let ( _freshness, duplicates) =
0 commit comments