Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 2 additions & 17 deletions crates/vite_task/src/session/execute/fingerprint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@
use std::{
collections::BTreeMap,
fs::File,
hash::Hasher as _,
io::{self, BufRead, Read},
io::{self, BufRead},
sync::Arc,
};

Expand Down Expand Up @@ -182,20 +181,6 @@ fn determine_folder_change_kind<'a>(
}
}

/// Hash file content using `xxHash3_64`
fn hash_content(mut stream: impl Read) -> io::Result<u64> {
let mut hasher = twox_hash::XxHash3_64::default();
let mut buf = [0u8; 8192];
loop {
let n = stream.read(&mut buf)?;
if n == 0 {
break;
}
hasher.write(&buf[..n]);
}
Ok(hasher.finish())
}

/// Check if a directory entry should be ignored in fingerprinting
fn should_ignore_entry(name: &[u8]) -> bool {
matches!(name, b"." | b".." | b".DS_Store") || name.eq_ignore_ascii_case(b"dist")
Expand Down Expand Up @@ -251,7 +236,7 @@ pub fn fingerprint_path(
return process_directory(std_path, path_read);
}
}
Ok(PathFingerprint::FileContentHash(hash_content(reader)?))
Ok(PathFingerprint::FileContentHash(super::hash::hash_content(reader)?))
}

/// Process a directory on Windows using `std::fs::read_dir`
Expand Down
21 changes: 2 additions & 19 deletions crates/vite_task/src/session/execute/glob_inputs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,7 @@
//!
//! All glob patterns are workspace-root-relative (resolved at task graph stage).

use std::{
collections::BTreeMap,
fs::File,
hash::Hasher as _,
io::{self, Read},
};
use std::{collections::BTreeMap, fs::File, io};

#[cfg(test)]
use vite_path::AbsolutePathBuf;
Expand Down Expand Up @@ -114,21 +109,9 @@ pub fn compute_globbed_inputs(
Ok(result)
}

/// Hash file content using `xxHash3_64`.
#[expect(clippy::disallowed_types, reason = "receives std::path::Path from wax glob walker")]
fn hash_file_content(path: &std::path::Path) -> io::Result<u64> {
let file = File::open(path)?;
let mut reader = io::BufReader::new(file);
let mut hasher = twox_hash::XxHash3_64::default();
let mut buf = [0u8; 8192];
loop {
let n = reader.read(&mut buf)?;
if n == 0 {
break;
}
hasher.write(&buf[..n]);
}
Ok(hasher.finish())
super::hash::hash_content(io::BufReader::new(File::open(path)?))
}

#[cfg(test)]
Expand Down
15 changes: 15 additions & 0 deletions crates/vite_task/src/session/execute/hash.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
use std::{hash::Hasher as _, io};

/// Hash content using 8 KiB buffered `xxHash3_64`.
pub(super) fn hash_content(mut stream: impl io::Read) -> io::Result<u64> {
let mut hasher = twox_hash::XxHash3_64::default();
let mut buf = [0u8; 8192];
loop {
let n = stream.read(&mut buf)?;
if n == 0 {
break;
}
hasher.write(&buf[..n]);
}
Ok(hasher.finish())
}
1 change: 1 addition & 0 deletions crates/vite_task/src/session/execute/mod.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
pub mod fingerprint;
pub mod glob_inputs;
mod hash;
pub mod spawn;

use std::{collections::BTreeMap, io::Write as _, process::Stdio, sync::Arc};
Expand Down
Loading