Skip to content

Commit

Permalink
fix(core): hash files properly by reading the whole file (nrwl#20652)
Browse files Browse the repository at this point in the history
  • Loading branch information
FrozenPandaz committed Dec 8, 2023
1 parent 429eb6a commit 1984dff
Showing 1 changed file with 6 additions and 12 deletions.
18 changes: 6 additions & 12 deletions packages/nx/src/native/hasher.rs
Original file line number Diff line number Diff line change
@@ -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;

Expand All @@ -23,23 +23,17 @@ pub fn hash_file(file: String) -> Option<String> {
#[inline]
pub fn hash_file_path<P: AsRef<Path>>(path: P) -> Option<String> {
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;

Expand Down

0 comments on commit 1984dff

Please sign in to comment.