Skip to content

Commit 0ac7aee

Browse files
committed
hash_u64_file now returns an Error instead of panicking.
1 parent c3997d6 commit 0ac7aee

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

src/cargo/ops/cargo_package.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -747,7 +747,7 @@ fn hash_all(path: &Path) -> CargoResult<HashMap<PathBuf, u64>> {
747747
let file_type = entry.file_type();
748748
if file_type.is_file() {
749749
let file = File::open(entry.path())?;
750-
let hash = util::hex::hash_u64_file(&file);
750+
let hash = util::hex::hash_u64_file(&file)?;
751751
result.insert(entry.path().to_path_buf(), hash);
752752
} else if file_type.is_symlink() {
753753
let hash = util::hex::hash_u64(&fs::read_link(entry.path())?);

src/cargo/util/hex.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,17 +23,17 @@ pub fn hash_u64<H: Hash>(hashable: H) -> u64 {
2323
hasher.finish()
2424
}
2525

26-
pub fn hash_u64_file(mut file: &File) -> u64 {
26+
pub fn hash_u64_file(mut file: &File) -> std::io::Result<u64> {
2727
let mut hasher = SipHasher::new_with_keys(0, 0);
2828
let mut buf = [0; 64 * 1024];
2929
loop {
30-
let n = file.read(&mut buf).unwrap();
30+
let n = file.read(&mut buf)?;
3131
if n == 0 {
3232
break;
3333
}
3434
hasher.write(&buf[..n]);
3535
}
36-
hasher.finish()
36+
Ok(hasher.finish())
3737
}
3838

3939
pub fn short_hash<H: Hash>(hashable: &H) -> String {

0 commit comments

Comments
 (0)