@@ -456,9 +456,9 @@ impl Summaries {
456
456
/// for `relative` from the underlying index (aka typically libgit2 with
457
457
/// crates.io) and then parse everything in there.
458
458
///
459
- /// * `last_index_update ` - this is a file modification time where if any cache
460
- /// file is older than this the cache should be considered out of date and
461
- /// needs to be rebuilt .
459
+ /// * `index_version ` - a version string to describe the current state of
460
+ /// the index which for remote registries is the current git sha and
461
+ /// for local registries is not available .
462
462
/// * `root` - this is the root argument passed to `load`
463
463
/// * `cache_root` - this is the root on the filesystem itself of where to
464
464
/// store cache files.
@@ -481,12 +481,17 @@ impl Summaries {
481
481
// of reasons, but consider all of them non-fatal and just log their
482
482
// occurrence in case anyone is debugging anything.
483
483
let cache_path = cache_root. join ( relative) ;
484
+ let mut cache_contents = None ;
484
485
if let Some ( index_version) = index_version {
485
486
match fs:: read ( & cache_path) {
486
487
Ok ( contents) => match Summaries :: parse_cache ( contents, index_version) {
487
488
Ok ( s) => {
488
489
log:: debug!( "fast path for registry cache of {:?}" , relative) ;
489
- return Ok ( Some ( s) )
490
+ if cfg ! ( debug_assertions) {
491
+ cache_contents = Some ( s. raw_data ) ;
492
+ } else {
493
+ return Ok ( Some ( s) )
494
+ }
490
495
}
491
496
Err ( e) => {
492
497
log:: debug!( "failed to parse {:?} cache: {}" , relative, e) ;
@@ -537,10 +542,19 @@ impl Summaries {
537
542
// or we haven't updated the registry yet. If we actually ran the
538
543
// closure though then we care about those errors.
539
544
if !hit_closure {
545
+ debug_assert ! ( cache_contents. is_none( ) ) ;
540
546
return Ok ( None ) ;
541
547
}
542
548
err?;
543
549
550
+ // If we've got debug assertions enabled and the cache was previously
551
+ // present and considered fresh this is where the debug assertions
552
+ // actually happens to verify that our cache is indeed fresh and
553
+ // computes exactly the same value as before.
554
+ if cfg ! ( debug_assertions) && cache_contents. is_some ( ) {
555
+ assert_eq ! ( cache_bytes, cache_contents) ;
556
+ }
557
+
544
558
// Once we have our `cache_bytes` which represents the `Summaries` we're
545
559
// about to return, write that back out to disk so future Cargo
546
560
// invocations can use it.
@@ -556,6 +570,7 @@ impl Summaries {
556
570
}
557
571
}
558
572
}
573
+
559
574
Ok ( Some ( ret) )
560
575
}
561
576
@@ -589,17 +604,25 @@ impl Summaries {
589
604
// Implementation of serializing/deserializing the cache of summaries on disk.
590
605
// Currently the format looks like:
591
606
//
592
- // +--------------+----------------+---+----------------+---+
593
- // | version byte | version string | 0 | JSON blob ... | 0 | ...
594
- // +--------------+----------------+---+----------------+---+
607
+ // +--------------+-------------+---+
608
+ // | version byte | git sha rev | 0 |
609
+ // +--------------+-------------+---+
610
+ //
611
+ // followed by...
612
+ //
613
+ // +----------------+---+------------+---+
614
+ // | semver version | 0 | JSON blob | 0 | ...
615
+ // +----------------+---+------------+---+
595
616
//
596
617
// The idea is that this is a very easy file for Cargo to parse in future
597
618
// invocations. The read from disk should be quite fast and then afterwards all
598
619
// we need to know is what versions correspond to which JSON blob.
599
620
//
600
621
// The leading version byte is intended to ensure that there's some level of
601
622
// future compatibility against changes to this cache format so if different
602
- // versions of Cargo share the same cache they don't get too confused.
623
+ // versions of Cargo share the same cache they don't get too confused. The git
624
+ // sha lets us know when the file needs to be regenerated (it needs regeneration
625
+ // whenever the index itself updates).
603
626
604
627
const CURRENT_CACHE_VERSION : u8 = 1 ;
605
628
0 commit comments