@@ -18,33 +18,31 @@ use crate::util::{FileLock, Filesystem};
18
18
19
19
/// On-disk tracking for which package installed which binary.
20
20
///
21
- /// v1 is an older style, v2 is a new (experimental) style that tracks more
22
- /// information. The new style is only enabled with the `-Z install-upgrade`
23
- /// flag (which sets the `unstable_upgrade` flag). v1 is still considered the
24
- /// source of truth. When v2 is used, it will sync with any changes with v1,
25
- /// and will continue to update v1 .
21
+ /// v1 is an older style, v2 is a new style that tracks more information, and
22
+ /// is both backwards and forwards compatible. Cargo keeps both files in sync,
23
+ /// updating both v1 and v2 at the same time. Additionally, if it detects
24
+ /// changes in v1 that are not in v2 (such as when an older version of Cargo
25
+ /// is used), it will automatically propagate those changes to v2 .
26
26
///
27
27
/// This maintains a filesystem lock, preventing other instances of Cargo from
28
28
/// modifying at the same time. Drop the value to unlock.
29
29
///
30
- /// If/when v2 is stabilized, it is intended that v1 is retained for a while
31
- /// during a longish transition period, and then v1 can be removed.
30
+ /// It is intended that v1 should be retained for a while during a longish
31
+ /// transition period, and then v1 can be removed.
32
32
pub struct InstallTracker {
33
33
v1 : CrateListingV1 ,
34
34
v2 : CrateListingV2 ,
35
35
v1_lock : FileLock ,
36
- v2_lock : Option < FileLock > ,
37
- unstable_upgrade : bool ,
36
+ v2_lock : FileLock ,
38
37
}
39
38
40
39
/// Tracking information for the set of installed packages.
41
- ///
42
- /// This v2 format is unstable and requires the `-Z unstable-upgrade` option
43
- /// to enable.
44
40
#[ derive( Default , Deserialize , Serialize ) ]
45
41
struct CrateListingV2 {
42
+ /// Map of every installed package.
46
43
installs : BTreeMap < PackageId , InstallInfo > ,
47
- /// Forwards compatibility.
44
+ /// Forwards compatibility. Unknown keys from future versions of Cargo
45
+ /// will be stored here and retained when the file is saved.
48
46
#[ serde( flatten) ]
49
47
other : BTreeMap < String , serde_json:: Value > ,
50
48
}
@@ -56,7 +54,7 @@ struct CrateListingV2 {
56
54
/// determine if it needs to be rebuilt/reinstalled. If nothing has changed,
57
55
/// then Cargo will inform the user that it is "up to date".
58
56
///
59
- /// This is only used for the (unstable) v2 format.
57
+ /// This is only used for the v2 format.
60
58
#[ derive( Debug , Deserialize , Serialize ) ]
61
59
struct InstallInfo {
62
60
/// Version requested via `--version`.
@@ -87,19 +85,15 @@ struct InstallInfo {
87
85
/// Tracking information for the set of installed packages.
88
86
#[ derive( Default , Deserialize , Serialize ) ]
89
87
pub struct CrateListingV1 {
88
+ /// Map of installed package id to the set of binary names for that package.
90
89
v1 : BTreeMap < PackageId , BTreeSet < String > > ,
91
90
}
92
91
93
92
impl InstallTracker {
94
93
/// Create an InstallTracker from information on disk.
95
94
pub fn load ( config : & Config , root : & Filesystem ) -> CargoResult < InstallTracker > {
96
- let unstable_upgrade = config. cli_unstable ( ) . install_upgrade ;
97
95
let v1_lock = root. open_rw ( Path :: new ( ".crates.toml" ) , config, "crate metadata" ) ?;
98
- let v2_lock = if unstable_upgrade {
99
- Some ( root. open_rw ( Path :: new ( ".crates2.json" ) , config, "crate metadata" ) ?)
100
- } else {
101
- None
102
- } ;
96
+ let v2_lock = root. open_rw ( Path :: new ( ".crates2.json" ) , config, "crate metadata" ) ?;
103
97
104
98
let v1 = ( || -> CargoResult < _ > {
105
99
let mut contents = String :: new ( ) ;
@@ -119,26 +113,21 @@ impl InstallTracker {
119
113
} ) ?;
120
114
121
115
let v2 = ( || -> CargoResult < _ > {
122
- match & v2_lock {
123
- Some ( lock) => {
124
- let mut contents = String :: new ( ) ;
125
- lock. file ( ) . read_to_string ( & mut contents) ?;
126
- let mut v2 = if contents. is_empty ( ) {
127
- CrateListingV2 :: default ( )
128
- } else {
129
- serde_json:: from_str ( & contents)
130
- . chain_err ( || format_err ! ( "invalid JSON found for metadata" ) ) ?
131
- } ;
132
- v2. sync_v1 ( & v1) ?;
133
- Ok ( v2)
134
- }
135
- None => Ok ( CrateListingV2 :: default ( ) ) ,
136
- }
116
+ let mut contents = String :: new ( ) ;
117
+ v2_lock. file ( ) . read_to_string ( & mut contents) ?;
118
+ let mut v2 = if contents. is_empty ( ) {
119
+ CrateListingV2 :: default ( )
120
+ } else {
121
+ serde_json:: from_str ( & contents)
122
+ . chain_err ( || format_err ! ( "invalid JSON found for metadata" ) ) ?
123
+ } ;
124
+ v2. sync_v1 ( & v1) ?;
125
+ Ok ( v2)
137
126
} ) ( )
138
127
. chain_err ( || {
139
128
format_err ! (
140
129
"failed to parse crate metadata at `{}`" ,
141
- v2_lock. as_ref ( ) . unwrap ( ) . path( ) . to_string_lossy( )
130
+ v2_lock. path( ) . to_string_lossy( )
142
131
)
143
132
} ) ?;
144
133
@@ -147,7 +136,6 @@ impl InstallTracker {
147
136
v2,
148
137
v1_lock,
149
138
v2_lock,
150
- unstable_upgrade,
151
139
} )
152
140
}
153
141
@@ -204,7 +192,7 @@ impl InstallTracker {
204
192
205
193
// If both sets are the same length, that means all duplicates come
206
194
// from packages with the same name.
207
- if self . unstable_upgrade && matching_duplicates. len ( ) == duplicates. len ( ) {
195
+ if matching_duplicates. len ( ) == duplicates. len ( ) {
208
196
// Determine if it is dirty or fresh.
209
197
let source_id = pkg. package_id ( ) . source_id ( ) ;
210
198
if source_id. is_path ( ) {
@@ -265,11 +253,8 @@ impl InstallTracker {
265
253
. filter_map ( |name| {
266
254
if !dst. join ( & name) . exists ( ) {
267
255
None
268
- } else if self . unstable_upgrade {
269
- let p = self . v2 . package_for_bin ( name) ;
270
- Some ( ( name. clone ( ) , p) )
271
256
} else {
272
- let p = self . v1 . package_for_bin ( name) ;
257
+ let p = self . v2 . package_for_bin ( name) ;
273
258
Some ( ( name. clone ( ) , p) )
274
259
}
275
260
} )
@@ -286,10 +271,8 @@ impl InstallTracker {
286
271
target : & str ,
287
272
rustc : & str ,
288
273
) {
289
- if self . unstable_upgrade {
290
- self . v2
291
- . mark_installed ( package, bins, version_req, opts, target, rustc)
292
- }
274
+ self . v2
275
+ . mark_installed ( package, bins, version_req, opts, target, rustc) ;
293
276
self . v1 . mark_installed ( package, bins) ;
294
277
}
295
278
@@ -302,14 +285,12 @@ impl InstallTracker {
302
285
)
303
286
} ) ?;
304
287
305
- if self . unstable_upgrade {
306
- self . v2 . save ( self . v2_lock . as_ref ( ) . unwrap ( ) ) . chain_err ( || {
307
- format_err ! (
308
- "failed to write crate metadata at `{}`" ,
309
- self . v2_lock. as_ref( ) . unwrap( ) . path( ) . to_string_lossy( )
310
- )
311
- } ) ?;
312
- }
288
+ self . v2 . save ( & self . v2_lock ) . chain_err ( || {
289
+ format_err ! (
290
+ "failed to write crate metadata at `{}`" ,
291
+ self . v2_lock. path( ) . to_string_lossy( )
292
+ )
293
+ } ) ?;
313
294
Ok ( ( ) )
314
295
}
315
296
@@ -329,20 +310,11 @@ impl InstallTracker {
329
310
/// Remove a package from the tracker.
330
311
pub fn remove ( & mut self , pkg_id : PackageId , bins : & BTreeSet < String > ) {
331
312
self . v1 . remove ( pkg_id, bins) ;
332
- if self . unstable_upgrade {
333
- self . v2 . remove ( pkg_id, bins) ;
334
- }
313
+ self . v2 . remove ( pkg_id, bins) ;
335
314
}
336
315
}
337
316
338
317
impl CrateListingV1 {
339
- fn package_for_bin ( & self , bin_name : & str ) -> Option < PackageId > {
340
- self . v1
341
- . iter ( )
342
- . find ( |( _, bins) | bins. contains ( bin_name) )
343
- . map ( |( pkg_id, _) | * pkg_id)
344
- }
345
-
346
318
fn mark_installed ( & mut self , pkg : & Package , bins : & BTreeSet < String > ) {
347
319
// Remove bins from any other packages.
348
320
for other_bins in self . v1 . values_mut ( ) {
@@ -600,24 +572,11 @@ where
600
572
match v. to_semver ( ) {
601
573
Ok ( v) => Some ( format ! ( "={}" , v) ) ,
602
574
Err ( e) => {
603
- let mut msg = if config. cli_unstable ( ) . install_upgrade {
604
- format ! (
605
- "the `--vers` provided, `{}`, is \
606
- not a valid semver version: {}\n ",
607
- v, e
608
- )
609
- } else {
610
- format ! (
611
- "the `--vers` provided, `{}`, is \
612
- not a valid semver version\n \n \
613
- historically Cargo treated this \
614
- as a semver version requirement \
615
- accidentally\n and will continue \
616
- to do so, but this behavior \
617
- will be removed eventually",
618
- v
619
- )
620
- } ;
575
+ let mut msg = format ! (
576
+ "the `--vers` provided, `{}`, is \
577
+ not a valid semver version: {}\n ",
578
+ v, e
579
+ ) ;
621
580
622
581
// If it is not a valid version but it is a valid version
623
582
// requirement, add a note to the warning
@@ -628,12 +587,7 @@ where
628
587
v
629
588
) ) ;
630
589
}
631
- if config. cli_unstable ( ) . install_upgrade {
632
- bail ! ( msg) ;
633
- } else {
634
- config. shell ( ) . warn ( & msg) ?;
635
- }
636
- Some ( v. to_string ( ) )
590
+ bail ! ( msg) ;
637
591
}
638
592
}
639
593
}
0 commit comments