diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml index d7c5ee71..d57fc7e4 100644 --- a/.github/workflows/benchmark.yml +++ b/.github/workflows/benchmark.yml @@ -9,11 +9,12 @@ jobs: run_benchmarks: name: Run Benchmarks runs-on: ubuntu-latest + steps: - - name: Checkout code - uses: actions/checkout@v4 + - uses: actions/checkout@v4 - - uses: boa-dev/criterion-compare-action@v3 + - name: Run Criterion + uses: boa-dev/criterion-compare-action@v3 with: branchName: ${{ github.base_ref }} token: ${{ secrets.GITHUB_TOKEN }} diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 1401fef1..3b052e43 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -1,6 +1,12 @@ name: Verify build -on: [push] +on: + push: + branches: + - main + pull_request: + branches: + - main env: CARGO_TERM_COLOR: always @@ -12,20 +18,26 @@ jobs: steps: - uses: actions/checkout@v4 + - name: Install Rust uses: dtolnay/rust-toolchain@stable with: components: rustfmt, clippy + - name: Check run: cargo check + - name: Format run: | cargo fmt --all -- --check cargo clippy + - name: Build Debug run: cargo build --verbose + - name: Run tests run: cargo test --verbose + - name: Build Release run: cargo build --verbose --release @@ -35,8 +47,10 @@ jobs: steps: - uses: actions/checkout@v4 + - name: Install Rust uses: dtolnay/rust-toolchain@stable + - name: Run tests run: cargo test --workspace --verbose @@ -46,7 +60,9 @@ jobs: steps: - uses: actions/checkout@v4 + - name: Install Rust uses: dtolnay/rust-toolchain@stable + - name: Run tests run: cargo test --workspace --verbose diff --git a/.github/workflows/main_branch.yml b/.github/workflows/weekly.yml similarity index 97% rename from .github/workflows/main_branch.yml rename to .github/workflows/weekly.yml index b7aa126b..f8cee97e 100644 --- a/.github/workflows/main_branch.yml +++ b/.github/workflows/weekly.yml @@ -1,4 +1,4 @@ -name: Main Branch Workflow +name: Weekly testing on: push: @@ -15,8 +15,10 @@ jobs: steps: - uses: actions/checkout@v4 + - name: Install Rust uses: dtolnay/rust-toolchain@stable + - name: Run tests run: cargo test --workspace --verbose --release @@ -26,8 +28,10 @@ jobs: steps: - uses: actions/checkout@v4 + - name: Install Rust uses: dtolnay/rust-toolchain@stable + - name: Run tests run: cargo test --workspace --verbose --release @@ -37,8 +41,10 @@ jobs: steps: - uses: actions/checkout@v4 + - name: Install Rust uses: dtolnay/rust-toolchain@stable + - name: Run tests run: cargo test --workspace --verbose --release @@ -48,7 +54,9 @@ jobs: steps: - uses: actions/checkout@v4 + - name: Install Rust uses: dtolnay/rust-toolchain@stable + - name: Run tests run: cargo test --workspace --verbose --release diff --git a/ark-cli/src/main.rs b/ark-cli/src/main.rs index 9aeba1f2..a31cbc71 100644 --- a/ark-cli/src/main.rs +++ b/ark-cli/src/main.rs @@ -10,7 +10,7 @@ use data_pdf::{render_preview_page, PDFQuality}; // Change this to use another type for the resource id if needed. // // We define it globally here so that it can be easily changed. -pub(crate) use dev_hash::Crc32ResourceId as ResourceId; +pub(crate) use dev_hash::Crc32 as ResourceId; use fs_atomic_versions::app_id; use fs_storage::ARK_FOLDER; diff --git a/data-link/src/lib.rs b/data-link/src/lib.rs index 777f2cf6..7e614a1d 100644 --- a/data-link/src/lib.rs +++ b/data-link/src/lib.rs @@ -1,5 +1,5 @@ use data_error::Result; -use data_resource::ResourceIdTrait; +use data_resource::ResourceId; use fs_atomic_versions::atomic::AtomicFile; use fs_metadata::store_metadata; use fs_properties::load_raw_properties; @@ -17,7 +17,7 @@ use std::{io::Write, path::PathBuf}; use url::Url; #[derive(Debug, Deserialize, Serialize)] -pub struct Link { +pub struct Link { pub url: Url, pub prop: Properties, // We need `_marker` to indicate that `Link` is generic over Id @@ -30,7 +30,7 @@ pub struct Properties { pub desc: Option, } -impl Link { +impl Link { pub fn new(url: Url, title: String, desc: Option) -> Self { Self { url, @@ -293,7 +293,7 @@ impl OpenGraphTag { async fn test_create_link_file() { fs_atomic_versions::initialize(); - use dev_hash::Crc32ResourceId as ResourceId; + use dev_hash::Crc32; use tempdir::TempDir; let dir = TempDir::new("arklib_test").unwrap(); @@ -301,7 +301,7 @@ async fn test_create_link_file() { let root: &Path = dir.path(); println!("temporary root: {}", root.display()); let url = Url::parse("https://kaydee.net/blog/open-graph-image/").unwrap(); - let link: Link = Link::new( + let link: Link = Link::new( url, String::from("test_title"), Some(String::from("test_desc")), @@ -317,12 +317,12 @@ async fn test_create_link_file() { Url::from_str(str::from_utf8(current_bytes.as_bytes()).unwrap()) .unwrap(); assert_eq!(url.as_str(), "https://kaydee.net/blog/open-graph-image/"); - let link: Link = Link::load(root, &path).unwrap(); + let link: Link = Link::load(root, &path).unwrap(); assert_eq!(link.url.as_str(), url.as_str()); assert_eq!(link.prop.desc.unwrap(), "test_desc"); assert_eq!(link.prop.title, "test_title"); - let id = ResourceId::from_bytes(current_bytes.as_bytes()).unwrap(); + let id = Crc32::from_bytes(current_bytes.as_bytes()).unwrap(); let path = Path::new(&root) .join(ARK_FOLDER) .join(PREVIEWS_STORAGE_FOLDER) diff --git a/data-resource/README.md b/data-resource/README.md index 23b12acd..d968139e 100644 --- a/data-resource/README.md +++ b/data-resource/README.md @@ -1,7 +1,7 @@ # `data-resource` -`data-resource` is a lightweight minimal dependency crate that defines the `ResourceIdTrait`. This trait specifies constraints for any type that represents a `ResourceId`. It is used by other `ark` crates to make the index generic over the resource ID type and hash function used. +`data-resource` is a lightweight minimal dependency crate that defines the `ResourceId` trait. This trait specifies constraints for any type that represents a `ResourceId`. It is used by other ARK crates to make the index generic over the resource ID type and hash function used. ## Example Implementations -To see example implementations of the `ResourceIdTrait`, please refer to the [`dev-hash`](../dev-hash) crate. +To see example implementations of the `ResourceId` trait, please refer to the [`dev-hash`](../dev-hash) crate. diff --git a/data-resource/src/lib.rs b/data-resource/src/lib.rs index 5aaf8614..049b4dbb 100644 --- a/data-resource/src/lib.rs +++ b/data-resource/src/lib.rs @@ -13,7 +13,7 @@ use std::{fmt::Debug, hash::Hash, path::Path}; /// The hash value is used to uniquely identify the resource. /// /// Implementors of this trait must provide a way to compute the hash value from the resource's data. -pub trait ResourceIdTrait: +pub trait ResourceId: Debug + Display + FromStr diff --git a/dev-hash/README.md b/dev-hash/README.md index 0be9c831..9de5d0a5 100644 --- a/dev-hash/README.md +++ b/dev-hash/README.md @@ -1,10 +1,10 @@ # `dev-hash` -`dev-hash` is a crate that provides example implementations of `ResourceIdTrait`. It can be extended to include additional hash function implementations. The crate also includes benchmarks for the defined `ResourceId` types. +`dev-hash` contains reference implementations of `ResourceId` trait and should be used only as an example, or as a dependency in test cases. It will be extended to include additional hash function implementations. The crate also includes benchmarks for the defined `ResourceId` types. ## Defined Types -| Type | Description | -| ------------------ | --------------------------------------------------- | -| `Blake3ResourceId` | Uses the Blake3 cryptographic hash function | -| `Crc32ResourceId` | Uses the CRC32 fast non-cryptographic hash function | +| Type | Description | +|----------|-----------------------------------------------------------------------------| +| `Blake3` | Impl of `ResourceId` that uses the Blake3 cryptographic hash function | +| `Crc32` | Impl of `ResourceId` that uses the CRC32 non-cryptographic hash function | diff --git a/dev-hash/benches/blake3.rs b/dev-hash/benches/blake3.rs index 5a56eac8..cf95233b 100644 --- a/dev-hash/benches/blake3.rs +++ b/dev-hash/benches/blake3.rs @@ -1,9 +1,9 @@ use criterion::{black_box, criterion_group, criterion_main, Criterion}; -use data_resource::ResourceIdTrait; +use data_resource::ResourceId; use rand::prelude::*; use std::path::Path; -use dev_hash::Blake3ResourceId as ResourceId; +use dev_hash::Blake3; // Add files to benchmark here const FILE_PATHS: [&str; 2] = @@ -36,7 +36,7 @@ fn bench_resource_id_creation(c: &mut Criterion) { let id = format!("compute_from_path:{}", file_path); group.bench_function(id, move |b| { b.iter(|| { - ResourceId::from_path(black_box(file_path)) + ::from_path(black_box(file_path)) .expect("from_path returned an error") }); }); @@ -51,7 +51,7 @@ fn bench_resource_id_creation(c: &mut Criterion) { let id = format!("compute_from_bytes:{}", name); group.bench_function(id, move |b| { b.iter(|| { - ResourceId::from_bytes(black_box(&input_data)) + ::from_bytes(black_box(&input_data)) .expect("from_bytes returned an error") }); }); diff --git a/dev-hash/benches/crc32.rs b/dev-hash/benches/crc32.rs index a8483702..b462035b 100644 --- a/dev-hash/benches/crc32.rs +++ b/dev-hash/benches/crc32.rs @@ -1,9 +1,9 @@ use criterion::{black_box, criterion_group, criterion_main, Criterion}; -use data_resource::ResourceIdTrait; +use data_resource::ResourceId; use rand::prelude::*; use std::path::Path; -use dev_hash::Crc32ResourceId as ResourceId; +use dev_hash::Crc32; // Add files to benchmark here const FILE_PATHS: [&str; 2] = @@ -36,7 +36,7 @@ fn bench_resource_id_creation(c: &mut Criterion) { let id = format!("compute_from_path:{}", file_path); group.bench_function(id, move |b| { b.iter(|| { - ResourceId::from_path(black_box(file_path)) + ::from_path(black_box(file_path)) .expect("from_path returned an error") }); }); @@ -51,7 +51,7 @@ fn bench_resource_id_creation(c: &mut Criterion) { let id = format!("compute_from_bytes:{}", name); group.bench_function(id, move |b| { b.iter(|| { - ResourceId::from_bytes(black_box(&input_data)) + ::from_bytes(black_box(&input_data)) .expect("from_bytes returned an error") }); }); diff --git a/dev-hash/src/blake3.rs b/dev-hash/src/blake3.rs index 8b112abf..76d6700f 100644 --- a/dev-hash/src/blake3.rs +++ b/dev-hash/src/blake3.rs @@ -10,7 +10,7 @@ use hex::encode; use serde::{Deserialize, Serialize}; use data_error::Result; -use data_resource::ResourceIdTrait; +use data_resource::ResourceId; /// Represents a resource identifier using the BLAKE3 algorithm. /// @@ -18,23 +18,23 @@ use data_resource::ResourceIdTrait; #[derive( Debug, Clone, PartialEq, Eq, Ord, PartialOrd, Hash, Serialize, Deserialize, )] -pub struct ResourceId(pub String); +pub struct Blake3(pub String); -impl FromStr for ResourceId { +impl FromStr for Blake3 { type Err = hex::FromHexError; fn from_str(s: &str) -> core::result::Result { - Ok(ResourceId(s.to_string())) + Ok(Blake3(s.to_string())) } } -impl Display for ResourceId { +impl Display for Blake3 { fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { write!(f, "{}", self.0) } } -impl ResourceIdTrait for ResourceId { +impl ResourceId for Blake3 { fn from_path>(file_path: P) -> Result { log::debug!("Computing BLAKE3 hash for file: {:?}", file_path.as_ref()); @@ -51,7 +51,7 @@ impl ResourceIdTrait for ResourceId { buffer.clear(); } let hash = hasher.finalize(); - Ok(ResourceId(encode(hash.as_bytes()))) + Ok(Blake3(encode(hash.as_bytes()))) } fn from_bytes(bytes: &[u8]) -> Result { @@ -60,7 +60,7 @@ impl ResourceIdTrait for ResourceId { let mut hasher = Hasher::new(); hasher.update(bytes); let hash = hasher.finalize(); - Ok(ResourceId(encode(hash.as_bytes()))) + Ok(Blake3(encode(hash.as_bytes()))) } } @@ -71,19 +71,19 @@ mod tests { #[test] fn sanity_check() { let file_path = Path::new("../test-assets/lena.jpg"); - let id = ResourceId::from_path(file_path) + let id = Blake3::from_path(file_path) .expect("Failed to compute resource identifier"); assert_eq!( id, - ResourceId("172b4bf148e858b13dde0fc6613413bcb7552e5c4e5c45195ac6c80f20eb5ff5".to_string()) + Blake3("172b4bf148e858b13dde0fc6613413bcb7552e5c4e5c45195ac6c80f20eb5ff5".to_string()) ); let raw_bytes = fs::read(file_path).expect("Failed to read file"); - let id = ResourceId::from_bytes(&raw_bytes) + let id = ::from_bytes(&raw_bytes) .expect("Failed to compute resource identifier"); assert_eq!( id, - ResourceId("172b4bf148e858b13dde0fc6613413bcb7552e5c4e5c45195ac6c80f20eb5ff5".to_string()) + Blake3("172b4bf148e858b13dde0fc6613413bcb7552e5c4e5c45195ac6c80f20eb5ff5".to_string()) ); } } diff --git a/dev-hash/src/crc32.rs b/dev-hash/src/crc32.rs index e2abab38..47535cc4 100644 --- a/dev-hash/src/crc32.rs +++ b/dev-hash/src/crc32.rs @@ -9,7 +9,7 @@ use crc32fast::Hasher; use serde::{Deserialize, Serialize}; use data_error::Result; -use data_resource::ResourceIdTrait; +use data_resource::ResourceId; /// Represents a resource identifier using the CRC32 algorithm. /// @@ -17,23 +17,23 @@ use data_resource::ResourceIdTrait; #[derive( Debug, Clone, PartialEq, Eq, Ord, PartialOrd, Hash, Serialize, Deserialize, )] -pub struct ResourceId(pub u32); +pub struct Crc32(pub u32); -impl FromStr for ResourceId { +impl FromStr for Crc32 { type Err = std::num::ParseIntError; fn from_str(s: &str) -> core::result::Result { - Ok(ResourceId(u32::from_str(s)?)) + Ok(Crc32(u32::from_str(s)?)) } } -impl Display for ResourceId { +impl Display for Crc32 { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { write!(f, "{}", self.0) } } -impl ResourceIdTrait for ResourceId { +impl ResourceId for Crc32 { fn from_path>(file_path: P) -> Result { log::debug!("Computing CRC32 hash for file: {:?}", file_path.as_ref()); @@ -49,7 +49,7 @@ impl ResourceIdTrait for ResourceId { hasher.update(&buffer); buffer.clear(); } - Ok(ResourceId(hasher.finalize())) + Ok(Crc32(hasher.finalize())) } fn from_bytes(bytes: &[u8]) -> Result { @@ -57,7 +57,7 @@ impl ResourceIdTrait for ResourceId { let mut hasher = Hasher::new(); hasher.update(bytes); - Ok(ResourceId(hasher.finalize())) + Ok(Crc32(hasher.finalize())) } } @@ -68,13 +68,13 @@ mod tests { #[test] fn sanity_check() { let file_path = Path::new("../test-assets/lena.jpg"); - let id = ResourceId::from_path(file_path) + let id = Crc32::from_path(file_path) .expect("Failed to compute resource identifier"); - assert_eq!(id, ResourceId(875183434)); + assert_eq!(id, Crc32(875183434)); let raw_bytes = fs::read(file_path).expect("Failed to read file"); - let id = ResourceId::from_bytes(&raw_bytes) + let id = ::from_bytes(&raw_bytes) .expect("Failed to compute resource identifier"); - assert_eq!(id, ResourceId(875183434)); + assert_eq!(id, Crc32(875183434)); } } diff --git a/dev-hash/src/lib.rs b/dev-hash/src/lib.rs index affa2eae..208c125c 100644 --- a/dev-hash/src/lib.rs +++ b/dev-hash/src/lib.rs @@ -1,5 +1,5 @@ mod blake3; mod crc32; -pub use blake3::ResourceId as Blake3ResourceId; -pub use crc32::ResourceId as Crc32ResourceId; +pub use blake3::Blake3; +pub use crc32::Crc32; diff --git a/fs-index/benches/index_build_benchmark.rs b/fs-index/benches/index_build_benchmark.rs index c3cae393..1de0ef3f 100644 --- a/fs-index/benches/index_build_benchmark.rs +++ b/fs-index/benches/index_build_benchmark.rs @@ -1,7 +1,7 @@ use criterion::{ black_box, criterion_group, criterion_main, BenchmarkId, Criterion, }; -use dev_hash::Crc32ResourceId as ResourceId; +use dev_hash::Crc32; use fs_index::index::ResourceIndex; const DIR_PATH: &str = "../test-assets/"; // Set the path to the directory containing the resources here @@ -24,7 +24,7 @@ fn index_build_benchmark(c: &mut Criterion) { &DIR_PATH, |b, path| { b.iter(|| { - let index: ResourceIndex = + let index: ResourceIndex = ResourceIndex::build(black_box(path.to_string())); collisions_size = index.collisions.len(); }); diff --git a/fs-index/src/index.rs b/fs-index/src/index.rs index 8188b369..6aa21d43 100644 --- a/fs-index/src/index.rs +++ b/fs-index/src/index.rs @@ -12,17 +12,17 @@ use walkdir::{DirEntry, WalkDir}; use log; use data_error::{ArklibError, Result}; -use data_resource::ResourceIdTrait; +use data_resource::ResourceId; use fs_storage::{ARK_FOLDER, INDEX_PATH}; #[derive(Eq, Ord, PartialEq, PartialOrd, Hash, Clone, Debug)] -pub struct IndexEntry { +pub struct IndexEntry { pub modified: SystemTime, pub id: Id, } #[derive(PartialEq, Clone, Debug)] -pub struct ResourceIndex { +pub struct ResourceIndex { pub id2path: HashMap, pub path2id: HashMap>, @@ -31,7 +31,7 @@ pub struct ResourceIndex { } #[derive(PartialEq, Debug)] -pub struct IndexUpdate { +pub struct IndexUpdate { pub deleted: HashSet, pub added: HashMap, } @@ -40,7 +40,7 @@ pub const RESOURCE_UPDATED_THRESHOLD: Duration = Duration::from_millis(1); pub type Paths = HashSet; -impl ResourceIndex { +impl ResourceIndex { pub fn size(&self) -> usize { //the actual size is lower in presence of collisions self.path2id.len() @@ -621,7 +621,7 @@ fn scan_entry( metadata: Metadata, ) -> Result> where - Id: ResourceIdTrait, + Id: ResourceId, { if metadata.is_dir() { return Err(ArklibError::Path("Path is expected to be a file".into())); @@ -645,7 +645,7 @@ fn scan_entries( entries: HashMap, ) -> HashMap> where - Id: ResourceIdTrait, + Id: ResourceId, { entries .into_iter() @@ -682,7 +682,7 @@ mod tests { use crate::index::{discover_paths, IndexEntry}; use crate::ResourceIndex; use canonical_path::CanonicalPathBuf; - use dev_hash::Crc32ResourceId as ResourceId; + use dev_hash::Crc32; use fs_atomic_versions::initialize; use std::fs::File; #[cfg(target_os = "linux")] @@ -701,8 +701,8 @@ mod tests { const FILE_NAME_2: &str = "test2.txt"; const FILE_NAME_3: &str = "test3.txt"; - const CRC32_1: ResourceId = ResourceId(3817498742); - const CRC32_2: ResourceId = ResourceId(1804055020); + const CRC32_1: Crc32 = Crc32(3817498742); + const CRC32_2: Crc32 = Crc32(1804055020); fn get_temp_dir() -> PathBuf { create_dir_at(std::env::temp_dir()) @@ -755,7 +755,7 @@ mod tests { run_test_and_clean_up(|path| { create_file_at(path.clone(), Some(FILE_SIZE_1), None); - let actual: ResourceIndex = + let actual: ResourceIndex = ResourceIndex::build(path.clone()); assert_eq!(actual.root, path.clone()); @@ -773,7 +773,7 @@ mod tests { create_file_at(path.clone(), Some(FILE_SIZE_1), None); create_file_at(path.clone(), Some(FILE_SIZE_1), None); - let actual: ResourceIndex = + let actual: ResourceIndex = ResourceIndex::build(path.clone()); assert_eq!(actual.root, path.clone()); @@ -793,7 +793,7 @@ mod tests { create_file_at(path.clone(), Some(FILE_SIZE_1), Some(FILE_NAME_1)); create_file_at(path.clone(), Some(FILE_SIZE_2), Some(FILE_NAME_2)); - let mut actual: ResourceIndex = + let mut actual: ResourceIndex = ResourceIndex::build(path.clone()); assert_eq!(actual.collisions.len(), 0); @@ -823,7 +823,7 @@ mod tests { run_test_and_clean_up(|path| { create_file_at(path.clone(), Some(FILE_SIZE_1), None); - let mut actual: ResourceIndex = + let mut actual: ResourceIndex = ResourceIndex::build(path.clone()); let (_, expected_path) = @@ -861,7 +861,7 @@ mod tests { fn index_new_should_index_new_file_successfully() { run_test_and_clean_up(|path| { create_file_at(path.clone(), Some(FILE_SIZE_1), None); - let mut index: ResourceIndex = + let mut index: ResourceIndex = ResourceIndex::build(path.clone()); let (_, new_path) = @@ -947,7 +947,7 @@ mod tests { Some(FILE_NAME_2), ); - let mut actual: ResourceIndex = + let mut actual: ResourceIndex = ResourceIndex::build(path.clone()); assert_eq!(actual.collisions.len(), 0); @@ -975,14 +975,14 @@ mod tests { let mut missing_path = path.clone(); missing_path.push("missing/directory"); let mut actual = ResourceIndex::build(path.clone()); - let old_id = ResourceId(2); + let old_id = Crc32(2); let result = actual .update_one(&missing_path, old_id.clone()) .map(|i| i.deleted.clone().take(&old_id)) .ok() .flatten(); - assert_eq!(result, Some(ResourceId(2))); + assert_eq!(result, Some(Crc32(2))); }) } @@ -992,14 +992,14 @@ mod tests { let mut missing_path = path.clone(); missing_path.push("missing/directory"); let mut actual = ResourceIndex::build(path.clone()); - let old_id = ResourceId(2); + let old_id = Crc32(2); let result = actual .update_one(&missing_path, old_id.clone()) .map(|i| i.deleted.clone().take(&old_id)) .ok() .flatten(); - assert_eq!(result, Some(ResourceId(2))); + assert_eq!(result, Some(Crc32(2))); }) } @@ -1007,7 +1007,7 @@ mod tests { fn should_not_index_empty_file() { run_test_and_clean_up(|path| { create_file_at(path.clone(), Some(0), None); - let actual: ResourceIndex = + let actual: ResourceIndex = ResourceIndex::build(path.clone()); assert_eq!(actual.root, path.clone()); @@ -1021,7 +1021,7 @@ mod tests { fn should_not_index_hidden_file() { run_test_and_clean_up(|path| { create_file_at(path.clone(), Some(FILE_SIZE_1), Some(".hidden")); - let actual: ResourceIndex = + let actual: ResourceIndex = ResourceIndex::build(path.clone()); assert_eq!(actual.root, path.clone()); @@ -1036,7 +1036,7 @@ mod tests { run_test_and_clean_up(|path| { create_dir_at(path.clone()); - let actual: ResourceIndex = + let actual: ResourceIndex = ResourceIndex::build(path.clone()); assert_eq!(actual.root, path.clone()); @@ -1059,20 +1059,20 @@ mod tests { #[test] fn index_entry_order() { let old1 = IndexEntry { - id: ResourceId(2), + id: Crc32(2), modified: SystemTime::UNIX_EPOCH, }; let old2 = IndexEntry { - id: ResourceId(1), + id: Crc32(1), modified: SystemTime::UNIX_EPOCH, }; let new1 = IndexEntry { - id: ResourceId(1), + id: Crc32(1), modified: SystemTime::now(), }; let new2 = IndexEntry { - id: ResourceId(2), + id: Crc32(2), modified: SystemTime::now(), }; @@ -1108,7 +1108,7 @@ mod tests { ); let start_time = Instant::now(); - let index: ResourceIndex = + let index: ResourceIndex = ResourceIndex::build(path.to_string()); let elapsed_time = start_time.elapsed(); diff --git a/fs-metadata/src/lib.rs b/fs-metadata/src/lib.rs index 73eff5ae..df258ae5 100644 --- a/fs-metadata/src/lib.rs +++ b/fs-metadata/src/lib.rs @@ -5,7 +5,7 @@ use std::fmt::Debug; use std::io::Read; use std::path::Path; -use data_resource::ResourceIdTrait; +use data_resource::ResourceId; use fs_storage::ARK_FOLDER; pub const METADATA_STORAGE_FOLDER: &str = "cache/metadata"; @@ -13,7 +13,7 @@ pub const METADATA_STORAGE_FOLDER: &str = "cache/metadata"; pub fn store_metadata< S: Serialize + DeserializeOwned + Clone + Debug, P: AsRef, - Id: ResourceIdTrait, + Id: ResourceId, >( root: P, id: Id, @@ -43,7 +43,7 @@ pub fn store_metadata< /// The file must exist if this method is called #[allow(dead_code)] -pub fn load_raw_metadata, Id: ResourceIdTrait>( +pub fn load_raw_metadata, Id: ResourceId>( root: P, id: Id, ) -> Result> { @@ -73,7 +73,7 @@ mod tests { use super::*; use tempdir::TempDir; - use dev_hash::Crc32ResourceId; + use dev_hash::Crc32; use std::collections::HashMap; type TestMetadata = HashMap; @@ -86,7 +86,7 @@ mod tests { let root = dir.path(); log::debug!("temporary root: {}", root.display()); - let id = Crc32ResourceId(0x342a3d4a); + let id = Crc32(0x342a3d4a); let mut meta = TestMetadata::new(); meta.insert("abc".to_string(), "def".to_string()); diff --git a/fs-properties/src/lib.rs b/fs-properties/src/lib.rs index de2f3e0e..81b5b04f 100644 --- a/fs-properties/src/lib.rs +++ b/fs-properties/src/lib.rs @@ -6,7 +6,7 @@ use std::path::Path; use data_error::Result; use data_json::merge; -use data_resource::ResourceIdTrait; +use data_resource::ResourceId; use fs_atomic_versions::atomic::{modify_json, AtomicFile}; use fs_storage::ARK_FOLDER; @@ -15,7 +15,7 @@ pub const PROPERTIES_STORAGE_FOLDER: &str = "user/properties"; pub fn store_properties< S: Serialize + DeserializeOwned + Clone + Debug, P: AsRef, - Id: ResourceIdTrait, + Id: ResourceId, >( root: P, id: Id, @@ -43,7 +43,7 @@ pub fn store_properties< } /// The file must exist if this method is called -pub fn load_raw_properties, Id: ResourceIdTrait>( +pub fn load_raw_properties, Id: ResourceId>( root: P, id: Id, ) -> Result> { @@ -76,7 +76,7 @@ mod tests { use std::collections::HashMap; type TestProperties = HashMap; - use dev_hash::Crc32ResourceId; + use dev_hash::Crc32; #[test] fn test_store_and_load() { @@ -86,7 +86,7 @@ mod tests { let root = dir.path(); log::debug!("temporary root: {}", root.display()); - let id = Crc32ResourceId(0x342a3d4a); + let id = Crc32(0x342a3d4a); let mut prop = TestProperties::new(); prop.insert("abc".to_string(), "def".to_string());