Skip to content

Commit

Permalink
define a crate for resourceId
Browse files Browse the repository at this point in the history
Signed-off-by: Tarek <[email protected]>
  • Loading branch information
tareknaser committed Feb 23, 2024
1 parent 4193994 commit f109433
Show file tree
Hide file tree
Showing 12 changed files with 52 additions and 22 deletions.
9 changes: 7 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
[workspace]
members = ["fs-atomic-versions", "fs-index", "fs-utils"]
default-members = ["fs-atomic-versions", "fs-index", "fs-utils"]
members = ["data-resource", "fs-atomic-versions", "fs-index", "fs-utils"]
default-members = [
"data-resource",
"fs-atomic-versions",
"fs-index",
"fs-utils",
]

resolver = "2"
13 changes: 7 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,12 @@ The purpose of the library is to manage _resource index_ of folders with various

<div align="center">

| Package | Description |
| -------------------- | ----------------------------------------- |
| `fs-index` | Resource Index construction and updating |
| `fs-atomic-versions` | Version-based preventing of dirty writes |
| `fs-utils` | Utility functions and common code |
| Package | Description |
| -------------------- | ---------------------------------------- |
| `fs-index` | Resource Index construction and updating |
| `data-resource` | Resource hashing and ID construction |
| `fs-atomic-versions` | Version-based preventing of dirty writes |
| `fs-utils` | Utility functions and common code |

</div>

Expand Down Expand Up @@ -58,7 +59,7 @@ cargo bench index_build

### Benchmarking Local Files

Our benchmark suite includes tests on local files and directories. These benchmarks are located in the [`benches/`](/benches) directory. Each benchmark sets a time limit using `group.measurement_time()`, which you can adjust manually based on your requirements.
Our benchmark suite includes tests on local files and directories. These benchmarks are located in the `benches/` directory of some crates. Each benchmark sets a time limit using `group.measurement_time()`, which you can adjust manually based on your requirements.

You have the flexibility to benchmark specific files or folders by modifying the variables within the benchmark files. By default, the benchmarks operate on the [`testdata/`](../testdata/) directory and its contents. You can change the directory/files by setting the `DIR_PATH` and `FILE_PATHS` variables to the desired values.

Expand Down
27 changes: 27 additions & 0 deletions data-resource/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
[package]
name = "data-resource"
version = "0.1.0"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
fs-utils = { path = "../fs-utils" }
fs-atomic-versions = { path = "../fs-atomic-versions" }

log = { version = "0.4.17", features = ["release_max_level_off"] }
serde = { version = "1.0.138", features = ["derive"] }
crc32fast = "1.3.2"
anyhow = "1"


[dev-dependencies]
# benchmarking
criterion = { version = "0.5", features = ["html_reports"] }
pprof = { version = "0.13", features = ["criterion", "flamegraph"] }
rand = "0.8"

[[bench]]
name = "compute_bytes_benchmark"
harness = false
path = "benches/compute_bytes_benchmark.rs"
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use criterion::{black_box, criterion_group, criterion_main, Criterion};
use fs_index::id::ResourceId;
use data_resource::ResourceId;
use pprof::criterion::{Output, PProfProfiler};
use rand::prelude::*;
use std::fs;
Expand Down
2 changes: 1 addition & 1 deletion fs-index/src/id.rs → data-resource/src/id.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use std::io::{BufRead, BufReader};
use std::path::Path;
use std::str::FromStr;

use crate::{ArklibError, Result};
use fs_utils::errors::{ArklibError, Result};

#[derive(
Eq,
Expand Down
3 changes: 3 additions & 0 deletions data-resource/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
mod id;

pub use id::ResourceId;
7 changes: 1 addition & 6 deletions fs-index/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ bench = false
[dependencies]
fs-utils = { path = "../fs-utils" }
fs-atomic-versions = { path = "../fs-atomic-versions" }
data-resource = { path = "../data-resource" }

log = { version = "0.4.17", features = ["release_max_level_off"] }
crc32fast = "1.3.2"
walkdir = "2.3.2"
anyhow = "1.0.58"
lazy_static = "1.4.0"
Expand Down Expand Up @@ -51,11 +51,6 @@ target-lexicon = "0.12.4"
ureq = "2.4.0"
ring = "=0.17.5"

[[bench]]
name = "compute_bytes_benchmark"
harness = false
path = "benches/compute_bytes_benchmark.rs"

[[bench]]
name = "index_build_benchmark"
harness = false
Expand Down
4 changes: 2 additions & 2 deletions fs-index/src/index.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ use walkdir::{DirEntry, WalkDir};

use log;

use crate::id::ResourceId;
use crate::{ArklibError, Result, ARK_FOLDER, INDEX_PATH};
use data_resource::ResourceId;

#[derive(Eq, Ord, PartialEq, PartialOrd, Hash, Clone, Debug)]
pub struct IndexEntry {
Expand Down Expand Up @@ -666,10 +666,10 @@ fn is_hidden(entry: &DirEntry) -> bool {

#[cfg(test)]
mod tests {
use crate::id::ResourceId;
use crate::index::{discover_paths, IndexEntry};
use crate::ResourceIndex;
use canonical_path::CanonicalPathBuf;
use data_resource::ResourceId;
use fs_atomic_versions::initialize;
use std::fs::File;
#[cfg(target_os = "linux")]
Expand Down
1 change: 0 additions & 1 deletion fs-index/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ extern crate canonical_path;

use fs_utils::errors::{ArklibError, Result};

pub mod id;
pub mod index;
pub mod link;
pub mod pdf;
Expand Down
2 changes: 1 addition & 1 deletion fs-index/src/link.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
use crate::id::ResourceId;
use crate::storage::meta::store_metadata;
use crate::storage::prop::store_properties;
use crate::{
storage::prop::load_raw_properties, AtomicFile, Result, ARK_FOLDER,
PREVIEWS_STORAGE_FOLDER, PROPERTIES_STORAGE_FOLDER,
};
use data_resource::ResourceId;
use reqwest::header::HeaderValue;
use scraper::{Html, Selector};
use serde::{Deserialize, Serialize};
Expand Down
2 changes: 1 addition & 1 deletion fs-index/src/storage/meta.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ use std::fmt::Debug;
use std::io::Read;
use std::path::Path;

use crate::id::ResourceId;
use crate::{Result, ARK_FOLDER, METADATA_STORAGE_FOLDER};
use data_resource::ResourceId;

pub fn store_metadata<
S: Serialize + DeserializeOwned + Clone + Debug,
Expand Down
2 changes: 1 addition & 1 deletion fs-index/src/storage/prop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ use std::fmt::Debug;
use std::io::Read;
use std::path::Path;

use crate::id::ResourceId;
use crate::{Result, ARK_FOLDER, PROPERTIES_STORAGE_FOLDER};
use data_resource::ResourceId;

pub fn store_properties<
S: Serialize + DeserializeOwned + Clone + Debug,
Expand Down

0 comments on commit f109433

Please sign in to comment.