@@ -350,7 +350,7 @@ pub type FileSize = u64;
350
350
351
351
#[ derive( Clone ) ]
352
352
pub struct FileHash {
353
- kind : SourceFileHashAlgorithm ,
353
+ kind : FileHashAlgorithm ,
354
354
hash : String ,
355
355
}
356
356
@@ -763,7 +763,7 @@ impl LocalFingerprint {
763
763
pkg_root. join ( p) ,
764
764
0u64 ,
765
765
FileHash {
766
- kind : SourceFileHashAlgorithm :: Md5 ,
766
+ kind : FileHashAlgorithm :: Md5 ,
767
767
hash : String :: new ( ) ,
768
768
} ,
769
769
)
@@ -1800,7 +1800,7 @@ fn find_stale_file(
1800
1800
let mut reader = io:: BufReader :: new ( fs:: File :: open ( & path) . unwrap ( ) ) ; //FIXME
1801
1801
1802
1802
let hash = match reference_hash. kind {
1803
- SourceFileHashAlgorithm :: Md5 => {
1803
+ FileHashAlgorithm :: Md5 => {
1804
1804
let mut hasher = Md5 :: new ( ) ;
1805
1805
let mut buffer = [ 0 ; 1024 ] ;
1806
1806
loop {
@@ -1812,7 +1812,7 @@ fn find_stale_file(
1812
1812
}
1813
1813
format ! ( "{:?}" , hasher. result( ) )
1814
1814
}
1815
- SourceFileHashAlgorithm :: Sha1 => {
1815
+ FileHashAlgorithm :: Sha1 => {
1816
1816
let mut hasher = Sha1 :: new ( ) ;
1817
1817
let mut buffer = [ 0 ; 1024 ] ;
1818
1818
loop {
@@ -1824,6 +1824,9 @@ fn find_stale_file(
1824
1824
}
1825
1825
format ! ( "{:?}" , hasher. result( ) )
1826
1826
}
1827
+ FileHashAlgorithm :: Filename => {
1828
+ "0" . to_string ( )
1829
+ }
1827
1830
} ;
1828
1831
let cached = mtime_cache. get_mut ( & path. to_path_buf ( ) ) . unwrap ( ) ;
1829
1832
cached. 2 = Some ( FileHash {
@@ -1854,18 +1857,22 @@ fn find_stale_file(
1854
1857
}
1855
1858
1856
1859
#[ derive( Clone , Copy , Eq , PartialEq ) ]
1857
- pub enum SourceFileHashAlgorithm {
1860
+ pub enum FileHashAlgorithm {
1858
1861
Md5 ,
1859
1862
Sha1 ,
1863
+ /// If the hash is in the filename then as long as the file exists we can
1864
+ /// assume it is up to date.
1865
+ Filename ,
1860
1866
}
1861
1867
1862
- impl FromStr for SourceFileHashAlgorithm {
1868
+ impl FromStr for FileHashAlgorithm {
1863
1869
type Err = ( ) ;
1864
1870
1865
- fn from_str ( s : & str ) -> Result < SourceFileHashAlgorithm , ( ) > {
1871
+ fn from_str ( s : & str ) -> Result < FileHashAlgorithm , ( ) > {
1866
1872
match s {
1867
- "md5" => Ok ( SourceFileHashAlgorithm :: Md5 ) ,
1868
- "sha1" => Ok ( SourceFileHashAlgorithm :: Sha1 ) ,
1873
+ "md5" => Ok ( FileHashAlgorithm :: Md5 ) ,
1874
+ "sha1" => Ok ( FileHashAlgorithm :: Sha1 ) ,
1875
+ "hash_in_filename" => Ok ( FileHashAlgorithm :: Filename ) ,
1869
1876
_ => Err ( ( ) ) ,
1870
1877
}
1871
1878
}
@@ -2015,8 +2022,9 @@ impl EncodedDepInfo {
2015
2022
2016
2023
//debug!("read hash as {}", hash);
2017
2024
let kind = match read_u8 ( bytes) ? {
2018
- 0 => SourceFileHashAlgorithm :: Md5 ,
2019
- 1 => SourceFileHashAlgorithm :: Sha1 ,
2025
+ 0 => FileHashAlgorithm :: Md5 ,
2026
+ 1 => FileHashAlgorithm :: Sha1 ,
2027
+ 2 => FileHashAlgorithm :: Filename ,
2020
2028
_ => return None ,
2021
2029
} ;
2022
2030
let ty = match read_u8 ( bytes) ? {
@@ -2097,8 +2105,9 @@ impl EncodedDepInfo {
2097
2105
write_bytes ( dst, hash. hash . as_bytes ( ) ) ;
2098
2106
//write(dst, hash.hash);
2099
2107
match hash. kind {
2100
- SourceFileHashAlgorithm :: Md5 => dst. push ( 0 ) ,
2101
- SourceFileHashAlgorithm :: Sha1 => dst. push ( 1 ) ,
2108
+ FileHashAlgorithm :: Md5 => dst. push ( 0 ) ,
2109
+ FileHashAlgorithm :: Sha1 => dst. push ( 1 ) ,
2110
+ FileHashAlgorithm :: Filename => dst. push ( 2 ) ,
2102
2111
}
2103
2112
match ty {
2104
2113
DepInfoPathType :: PackageRootRelative => dst. push ( 0 ) ,
@@ -2179,7 +2188,7 @@ pub fn parse_rustc_dep_info(rustc_dep_info: &Path) -> CargoResult<RustcDepInfo>
2179
2188
let kind_hash: Vec < _ > = parts[ 1 ] . split ( ":" ) . collect ( ) ;
2180
2189
let hash = kind_hash[ 1 ] ;
2181
2190
ret. files [ i] . 2 = FileHash {
2182
- kind : SourceFileHashAlgorithm :: from_str ( kind_hash[ 0 ] )
2191
+ kind : FileHashAlgorithm :: from_str ( kind_hash[ 0 ] )
2183
2192
. expect ( "unknown hashing algo" ) ,
2184
2193
hash : hash. to_string ( ) ,
2185
2194
} ;
@@ -2208,7 +2217,7 @@ pub fn parse_rustc_dep_info(rustc_dep_info: &Path) -> CargoResult<RustcDepInfo>
2208
2217
file. into ( ) ,
2209
2218
0 ,
2210
2219
FileHash {
2211
- kind : SourceFileHashAlgorithm :: Md5 ,
2220
+ kind : FileHashAlgorithm :: Md5 ,
2212
2221
hash : String :: new ( ) ,
2213
2222
} ,
2214
2223
) ) ;
0 commit comments