From 1984dff295437b392d2b679176419eee60051b11 Mon Sep 17 00:00:00 2001 From: Jason Jean Date: Thu, 7 Dec 2023 19:01:37 -0500 Subject: [PATCH] fix(core): hash files properly by reading the whole file (#20652) --- packages/nx/src/native/hasher.rs | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) diff --git a/packages/nx/src/native/hasher.rs b/packages/nx/src/native/hasher.rs index 6cbcf2bd36a6f..715a9f78ace53 100644 --- a/packages/nx/src/native/hasher.rs +++ b/packages/nx/src/native/hasher.rs @@ -1,6 +1,6 @@ -use std::fs::File; -use std::io::{BufRead, BufReader}; +use std::io::BufRead; use std::path::Path; + use tracing::trace; use xxhash_rust::xxh3; @@ -23,23 +23,17 @@ pub fn hash_file(file: String) -> Option { #[inline] pub fn hash_file_path>(path: P) -> Option { let path = path.as_ref(); - let Ok(file) = File::open(path) else { - trace!("could not open file: {path:?}"); - return None; - }; - - let mut buffer = BufReader::new(file); - let Ok(content) = buffer.fill_buf() else { - trace!("could not read file: {path:?}"); + let Ok(content) = std::fs::read(path) else { + trace!("Failed to read file: {:?}", path); return None; }; - Some(hash(content)) + Some(hash(&content)) } #[cfg(test)] mod tests { - use super::*; + use crate::native::hasher::hash_file; use assert_fs::prelude::*; use assert_fs::TempDir;