Skip to content

Commit

Permalink
fix(core): rename struct
Browse files Browse the repository at this point in the history
  • Loading branch information
Cammisuli committed Nov 30, 2023
1 parent da1215b commit 8c819cd
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 19 deletions.
6 changes: 3 additions & 3 deletions packages/nx/src/native/workspace/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,13 @@ impl FilesWorker {
let (lock, cvar) = &*files_lock_clone;
let mut workspace_files = lock.lock();
let now = std::time::Instant::now();
let new_archived_files = if let Some(archived_files) = archived_files {
let file_hashes = if let Some(archived_files) = archived_files {
selective_files_hash(&workspace_root, archived_files)
} else {
full_files_hash(&workspace_root)
};

let mut files = new_archived_files
let mut files = file_hashes
.iter()
.map(|(path, file_hashed)| (PathBuf::from(path), file_hashed.0.to_owned()))
.collect::<Vec<_>>();
Expand All @@ -72,7 +72,7 @@ impl FilesWorker {

cvar.notify_all();

write_files_archive(&cache_dir, new_archived_files);
write_files_archive(&cache_dir, file_hashes);
});

FilesWorker(Some(files_lock))
Expand Down
20 changes: 10 additions & 10 deletions packages/nx/src/native/workspace/files_archive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,31 +14,31 @@ pub struct NxFileHashed(pub String, pub i64);

#[derive(Archive, Deserialize, Serialize, Debug, PartialEq)]
#[archive(check_bytes)]
pub struct NxFilesArchive(HashMap<String, NxFileHashed>);
pub struct NxFileHashes(HashMap<String, NxFileHashed>);

impl Deref for NxFilesArchive {
impl Deref for NxFileHashes {
type Target = HashMap<String, NxFileHashed>;

fn deref(&self) -> &Self::Target {
&self.0
}
}

impl DerefMut for NxFilesArchive {
impl DerefMut for NxFileHashes {
fn deref_mut(&mut self) -> &mut Self::Target {
&mut self.0
}
}

impl FromIterator<(String, NxFileHashed)> for NxFilesArchive {
fn from_iter<T: IntoIterator<Item = (String, NxFileHashed)>>(iter: T) -> NxFilesArchive {
impl FromIterator<(String, NxFileHashed)> for NxFileHashes {
fn from_iter<T: IntoIterator<Item = (String, NxFileHashed)>>(iter: T) -> NxFileHashes {
let mut map = HashMap::with_hasher(Default::default());
map.extend(iter);
NxFilesArchive(map)
NxFileHashes(map)
}
}

pub fn read_files_archive<P: AsRef<Path>>(cache_dir: P) -> Option<NxFilesArchive> {
pub fn read_files_archive<P: AsRef<Path>>(cache_dir: P) -> Option<NxFileHashes> {
let now = std::time::Instant::now();
let archive_path = cache_dir.as_ref().join(NX_FILES_ARCHIVE);
if !archive_path.exists() {
Expand All @@ -49,9 +49,9 @@ pub fn read_files_archive<P: AsRef<Path>>(cache_dir: P) -> Option<NxFilesArchive
.map_err(anyhow::Error::from)
.and_then(|bytes| {
// let archived = unsafe { rkyv::archived_root::<NxFilesArchive>(&bytes) };
let archived = rkyv::check_archived_root::<NxFilesArchive>(&bytes)
let archived = rkyv::check_archived_root::<NxFileHashes>(&bytes)
.map_err(|_| anyhow!("invalid archive file"))?;
<ArchivedNxFilesArchive as Deserialize<NxFilesArchive, Infallible>>::deserialize(
<ArchivedNxFileHashes as Deserialize<NxFileHashes, Infallible>>::deserialize(
archived,
&mut rkyv::Infallible,
)
Expand All @@ -70,7 +70,7 @@ pub fn read_files_archive<P: AsRef<Path>>(cache_dir: P) -> Option<NxFilesArchive
}
}

pub fn write_files_archive<P: AsRef<Path>>(cache_dir: P, files: NxFilesArchive) {
pub fn write_files_archive<P: AsRef<Path>>(cache_dir: P, files: NxFileHashes) {
let now = std::time::Instant::now();
let archive_path = cache_dir.as_ref().join(NX_FILES_ARCHIVE);
let result = rkyv::to_bytes::<_, 2048>(&files)
Expand Down
12 changes: 6 additions & 6 deletions packages/nx/src/native/workspace/files_hashing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,17 @@ use tracing::trace;

use crate::native::hasher::hash_file_path;
use crate::native::walker::{nx_walker, NxFile};
use crate::native::workspace::files_archive::{NxFileHashed, NxFilesArchive};
use crate::native::workspace::files_archive::{NxFileHashed, NxFileHashes};

pub fn full_files_hash(workspace_root: &Path) -> NxFilesArchive {
pub fn full_files_hash(workspace_root: &Path) -> NxFileHashes {
let files = nx_walker(workspace_root).collect::<Vec<_>>();
hash_files(files).into_iter().collect()
}

pub fn selective_files_hash(
workspace_root: &Path,
mut archived_files: NxFilesArchive,
) -> NxFilesArchive {
mut archived_files: NxFileHashes,
) -> NxFileHashes {
let files = nx_walker(workspace_root).collect::<Vec<_>>();
let mut archived = vec![];
let mut not_archived = vec![];
Expand Down Expand Up @@ -84,7 +84,7 @@ mod tests {
use assert_fs::TempDir;

use crate::native::utils::get_mod_time;
use crate::native::workspace::files_archive::{NxFileHashed, NxFilesArchive};
use crate::native::workspace::files_archive::{NxFileHashed, NxFileHashes};

fn setup_fs() -> TempDir {
let temp = TempDir::new().unwrap();
Expand Down Expand Up @@ -140,7 +140,7 @@ mod tests {
),
]
.into_iter()
.collect::<NxFilesArchive>();
.collect::<NxFileHashes>();

let hashed_files = super::selective_files_hash(temp.path(), archived_files);
let mut hashed_files = hashed_files
Expand Down

0 comments on commit 8c819cd

Please sign in to comment.