@@ -72,7 +72,8 @@ use crate::sources::registry::{RegistryData, RegistryPackage};
7272use crate :: util:: interning:: InternedString ;
7373use crate :: util:: paths;
7474use crate :: util:: { internal, CargoResult , Config , Filesystem , ToSemver } ;
75- use log:: info;
75+ use anyhow:: bail;
76+ use log:: { debug, info} ;
7677use semver:: { Version , VersionReq } ;
7778use std:: collections:: { HashMap , HashSet } ;
7879use std:: fs;
@@ -233,6 +234,8 @@ enum MaybeIndexSummary {
233234pub struct IndexSummary {
234235 pub summary : Summary ,
235236 pub yanked : bool ,
237+ /// Schema version, see [`RegistryPackage`].
238+ v : u32 ,
236239}
237240
238241/// A representation of the cache on disk that Cargo maintains of summaries.
@@ -305,6 +308,7 @@ impl<'cfg> RegistryIndex<'cfg> {
305308 // minimize the amount of work being done here and parse as little as
306309 // necessary.
307310 let raw_data = & summaries. raw_data ;
311+ let max_version = 1 ;
308312 Ok ( summaries
309313 . versions
310314 . iter_mut ( )
@@ -318,6 +322,19 @@ impl<'cfg> RegistryIndex<'cfg> {
318322 }
319323 } ,
320324 )
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+ } )
321338 . filter ( move |is| {
322339 is. summary
323340 . unstable_gate ( namespaced_features, weak_dep_features)
@@ -578,7 +595,14 @@ impl Summaries {
578595 // actually happens to verify that our cache is indeed fresh and
579596 // computes exactly the same value as before.
580597 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+ }
582606 }
583607
584608 // Once we have our `cache_bytes` which represents the `Summaries` we're
@@ -659,19 +683,19 @@ impl<'a> SummariesCache<'a> {
659683 . split_first ( )
660684 . ok_or_else ( || anyhow:: format_err!( "malformed cache" ) ) ?;
661685 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" ) ;
663687 }
664688 let mut iter = split ( rest, 0 ) ;
665689 if let Some ( update) = iter. next ( ) {
666690 if update != last_index_update. as_bytes ( ) {
667- anyhow :: bail!(
691+ bail ! (
668692 "cache out of date: current index ({}) != cache ({})" ,
669693 last_index_update,
670694 str :: from_utf8( update) ?,
671695 )
672696 }
673697 } else {
674- anyhow :: bail!( "malformed file" ) ;
698+ bail ! ( "malformed file" ) ;
675699 }
676700 let mut ret = SummariesCache :: default ( ) ;
677701 while let Some ( version) = iter. next ( ) {
@@ -749,7 +773,9 @@ impl IndexSummary {
749773 features,
750774 yanked,
751775 links,
776+ v,
752777 } = serde_json:: from_slice ( line) ?;
778+ let v = v. unwrap_or ( 1 ) ;
753779 log:: trace!( "json parsed registry {}/{}" , name, vers) ;
754780 let pkgid = PackageId :: new ( name, & vers, source_id) ?;
755781 let deps = deps
@@ -761,6 +787,7 @@ impl IndexSummary {
761787 Ok ( IndexSummary {
762788 summary,
763789 yanked : yanked. unwrap_or ( false ) ,
790+ v,
764791 } )
765792 }
766793}
0 commit comments