@@ -72,7 +72,8 @@ use crate::sources::registry::{RegistryData, RegistryPackage};
72
72
use crate :: util:: interning:: InternedString ;
73
73
use crate :: util:: paths;
74
74
use crate :: util:: { internal, CargoResult , Config , Filesystem , ToSemver } ;
75
- use log:: info;
75
+ use anyhow:: bail;
76
+ use log:: { debug, info} ;
76
77
use semver:: { Version , VersionReq } ;
77
78
use std:: collections:: { HashMap , HashSet } ;
78
79
use std:: fs;
@@ -233,6 +234,8 @@ enum MaybeIndexSummary {
233
234
pub struct IndexSummary {
234
235
pub summary : Summary ,
235
236
pub yanked : bool ,
237
+ /// Schema version, see [`RegistryPackage`].
238
+ v : u32 ,
236
239
}
237
240
238
241
/// A representation of the cache on disk that Cargo maintains of summaries.
@@ -305,6 +308,7 @@ impl<'cfg> RegistryIndex<'cfg> {
305
308
// minimize the amount of work being done here and parse as little as
306
309
// necessary.
307
310
let raw_data = & summaries. raw_data ;
311
+ let max_version = 1 ;
308
312
Ok ( summaries
309
313
. versions
310
314
. iter_mut ( )
@@ -318,6 +322,19 @@ impl<'cfg> RegistryIndex<'cfg> {
318
322
}
319
323
} ,
320
324
)
325
+ . filter ( move |is| {
326
+ if is. v > max_version {
327
+ debug ! (
328
+ "unsupported schema version {} ({} {})" ,
329
+ is. v,
330
+ is. summary. name( ) ,
331
+ is. summary. version( )
332
+ ) ;
333
+ false
334
+ } else {
335
+ true
336
+ }
337
+ } )
321
338
. filter ( move |is| {
322
339
is. summary
323
340
. unstable_gate ( namespaced_features, weak_dep_features)
@@ -578,7 +595,14 @@ impl Summaries {
578
595
// actually happens to verify that our cache is indeed fresh and
579
596
// computes exactly the same value as before.
580
597
if cfg ! ( debug_assertions) && cache_contents. is_some ( ) {
581
- assert_eq ! ( cache_bytes, cache_contents) ;
598
+ if cache_bytes != cache_contents {
599
+ panic ! (
600
+ "original cache contents:\n {:?}\n \
601
+ does not equal new cache contents:\n {:?}\n ",
602
+ cache_contents. as_ref( ) . map( |s| String :: from_utf8_lossy( s) ) ,
603
+ cache_bytes. as_ref( ) . map( |s| String :: from_utf8_lossy( s) ) ,
604
+ ) ;
605
+ }
582
606
}
583
607
584
608
// Once we have our `cache_bytes` which represents the `Summaries` we're
@@ -659,19 +683,19 @@ impl<'a> SummariesCache<'a> {
659
683
. split_first ( )
660
684
. ok_or_else ( || anyhow:: format_err!( "malformed cache" ) ) ?;
661
685
if * first_byte != CURRENT_CACHE_VERSION {
662
- anyhow :: bail!( "looks like a different Cargo's cache, bailing out" ) ;
686
+ bail ! ( "looks like a different Cargo's cache, bailing out" ) ;
663
687
}
664
688
let mut iter = split ( rest, 0 ) ;
665
689
if let Some ( update) = iter. next ( ) {
666
690
if update != last_index_update. as_bytes ( ) {
667
- anyhow :: bail!(
691
+ bail ! (
668
692
"cache out of date: current index ({}) != cache ({})" ,
669
693
last_index_update,
670
694
str :: from_utf8( update) ?,
671
695
)
672
696
}
673
697
} else {
674
- anyhow :: bail!( "malformed file" ) ;
698
+ bail ! ( "malformed file" ) ;
675
699
}
676
700
let mut ret = SummariesCache :: default ( ) ;
677
701
while let Some ( version) = iter. next ( ) {
@@ -749,7 +773,9 @@ impl IndexSummary {
749
773
features,
750
774
yanked,
751
775
links,
776
+ v,
752
777
} = serde_json:: from_slice ( line) ?;
778
+ let v = v. unwrap_or ( 1 ) ;
753
779
log:: trace!( "json parsed registry {}/{}" , name, vers) ;
754
780
let pkgid = PackageId :: new ( name, & vers, source_id) ?;
755
781
let deps = deps
@@ -761,6 +787,7 @@ impl IndexSummary {
761
787
Ok ( IndexSummary {
762
788
summary,
763
789
yanked : yanked. unwrap_or ( false ) ,
790
+ v,
764
791
} )
765
792
}
766
793
}
0 commit comments