@@ -722,7 +722,7 @@ impl LocalFingerprint {
722
722
fn find_stale_item (
723
723
& self ,
724
724
config : & Config ,
725
- mtime_cache : & mut HashMap < PathBuf , ( FileTime , FileSize , FileHash ) > ,
725
+ mtime_cache : & mut HashMap < PathBuf , ( FileTime , FileSize , Option < FileHash > ) > ,
726
726
pkg_root : & Path ,
727
727
target_root : & Path ,
728
728
) -> CargoResult < Option < StaleItem > > {
@@ -991,7 +991,7 @@ impl Fingerprint {
991
991
fn check_filesystem (
992
992
& mut self ,
993
993
config : & Config ,
994
- mtime_cache : & mut HashMap < PathBuf , ( FileTime , FileSize , FileHash ) > ,
994
+ mtime_cache : & mut HashMap < PathBuf , ( FileTime , FileSize , Option < FileHash > ) > ,
995
995
pkg_root : & Path ,
996
996
target_root : & Path ,
997
997
) -> CargoResult < ( ) > {
@@ -1720,7 +1720,7 @@ fn pkg_fingerprint(bcx: &BuildContext<'_, '_>, pkg: &Package) -> CargoResult<Str
1720
1720
//type It = ;
1721
1721
fn find_stale_file (
1722
1722
config : & Config ,
1723
- mtime_cache : & mut HashMap < PathBuf , ( FileTime , FileSize , FileHash ) > ,
1723
+ mtime_cache : & mut HashMap < PathBuf , ( FileTime , FileSize , Option < FileHash > ) > ,
1724
1724
reference : & Path ,
1725
1725
paths : & [ ( PathBuf , FileSize , FileHash ) ] ,
1726
1726
) -> Option < StaleItem > {
@@ -1747,15 +1747,7 @@ fn find_stale_file(
1747
1747
} else {
1748
1748
0
1749
1749
} ;
1750
- v. insert ( (
1751
- mtime,
1752
- current_size,
1753
- FileHash {
1754
- kind : SourceFileHashAlgorithm :: Md5 ,
1755
- hash : String :: new ( ) ,
1756
- } ,
1757
- ) )
1758
- . clone ( ) // Hash calculated only if needed later.
1750
+ v. insert ( ( mtime, current_size, None ) ) . clone ( ) // Hash calculated only if needed later.
1759
1751
}
1760
1752
} ;
1761
1753
@@ -1797,37 +1789,48 @@ fn find_stale_file(
1797
1789
1798
1790
// Same size but mtime is different. Probably there's no change...
1799
1791
// compute hash and compare to prevent change cascade...
1800
- if config. cli_unstable ( ) . hash_tracking && reference_hash. hash . len ( ) > 0 {
1801
- // FIXME? We could fail a little faster by seeing if any size discrepencies on _any_ file before checking hashes.
1802
- // but not sure it's worth the additional complexity.
1803
- //FIXME put the result in the mtime_cache rather than hashing each time!
1804
- let mut reader = io:: BufReader :: new ( fs:: File :: open ( & path) . unwrap ( ) ) ; //FIXME
1805
-
1806
- let hash = match reference_hash. kind {
1807
- SourceFileHashAlgorithm :: Md5 => {
1808
- let mut hasher = Md5 :: new ( ) ;
1809
- let mut buffer = [ 0 ; 1024 ] ;
1810
- loop {
1811
- let count = reader. read ( & mut buffer) . unwrap ( ) ; //FIXME
1812
- if count == 0 {
1813
- break ;
1792
+ if config. cli_unstable ( ) . hash_tracking && !reference_hash. hash . is_empty ( ) {
1793
+ let hash = if let Some ( path_hash) = path_hash {
1794
+ //FIXME use unwrap_or
1795
+ path_hash. hash
1796
+ } else {
1797
+ // FIXME? We could fail a little faster by seeing if any size discrepencies on _any_ file before checking hashes.
1798
+ // but not sure it's worth the additional complexity.
1799
+ //FIXME put the result in the mtime_cache rather than hashing each time!
1800
+ let mut reader = io:: BufReader :: new ( fs:: File :: open ( & path) . unwrap ( ) ) ; //FIXME
1801
+
1802
+ let hash = match reference_hash. kind {
1803
+ SourceFileHashAlgorithm :: Md5 => {
1804
+ let mut hasher = Md5 :: new ( ) ;
1805
+ let mut buffer = [ 0 ; 1024 ] ;
1806
+ loop {
1807
+ let count = reader. read ( & mut buffer) . unwrap ( ) ; //FIXME
1808
+ if count == 0 {
1809
+ break ;
1810
+ }
1811
+ hasher. input ( & buffer[ ..count] ) ;
1814
1812
}
1815
- hasher. input ( & buffer [ ..count ] ) ;
1813
+ format ! ( "{:?}" , hasher. result ( ) )
1816
1814
}
1817
- format ! ( "{:?}" , hasher . result ( ) )
1818
- }
1819
- SourceFileHashAlgorithm :: Sha1 => {
1820
- let mut hasher = Sha1 :: new ( ) ;
1821
- let mut buffer = [ 0 ; 1024 ] ;
1822
- loop {
1823
- let count = reader . read ( & mut buffer ) . unwrap ( ) ; //FIXME
1824
- if count == 0 {
1825
- break ;
1815
+ SourceFileHashAlgorithm :: Sha1 => {
1816
+ let mut hasher = Sha1 :: new ( ) ;
1817
+ let mut buffer = [ 0 ; 1024 ] ;
1818
+ loop {
1819
+ let count = reader . read ( & mut buffer ) . unwrap ( ) ; //FIXME
1820
+ if count == 0 {
1821
+ break ;
1822
+ }
1823
+ hasher . input ( & buffer [ ..count ] ) ;
1826
1824
}
1827
- hasher. input ( & buffer [ ..count ] ) ;
1825
+ format ! ( "{:?}" , hasher. result ( ) )
1828
1826
}
1829
- format ! ( "{:?}" , hasher. result( ) )
1830
- }
1827
+ } ;
1828
+ let cached = mtime_cache. get_mut ( & path. to_path_buf ( ) ) . unwrap ( ) ;
1829
+ cached. 2 = Some ( FileHash {
1830
+ kind : reference_hash. kind ,
1831
+ hash : hash. clone ( ) ,
1832
+ } ) ;
1833
+ hash
1831
1834
} ;
1832
1835
1833
1836
if hash == reference_hash. hash {
0 commit comments