Skip to content

Commit

Permalink
Merge 03849c9 into a59e7ed
Browse files Browse the repository at this point in the history
  • Loading branch information
tareknaser authored Jun 30, 2024
2 parents a59e7ed + 03849c9 commit aee18b1
Show file tree
Hide file tree
Showing 40 changed files with 1,537 additions and 1,245 deletions.
1 change: 1 addition & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ jobs:
- name: Install Rust
uses: dtolnay/rust-toolchain@stable
with:
toolchain: nightly # nightly is required for fmt
components: rustfmt, clippy

- name: Check
Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ cargo bench
This command runs all benchmarks and generates a report in HTML format located at `target/criterion/report`. If you wish to run a specific benchmark, you can specify its name as an argument as in:

```bash
cargo bench index_build
cargo bench resource_index
```

### Benchmarking Local Files
Expand All @@ -97,10 +97,10 @@ To install `flamegraph`, run:
cargo install flamegraph
```

To generate a flame graph for `index_build_benchmark`, use the following command:
To generate a flame graph for `resource_index_benchmark`, use the following command:

```bash
cargo flamegraph --bench index_build_benchmark -o index_build_benchmark.svg -- --bench
cargo flamegraph --bench resource_index_benchmark -o resource_index_benchmark.svg -- --bench
```

> [!NOTE]
Expand Down
3 changes: 1 addition & 2 deletions ark-cli/src/commands/backup.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use std::io::Write;
use std::path::PathBuf;
use std::{io::Write, path::PathBuf};

use crate::{
create_dir_all, dir, discover_roots, home_dir, storages_exists, timestamp,
Expand Down
7 changes: 3 additions & 4 deletions ark-cli/src/commands/file/append.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
use std::path::PathBuf;
use std::str::FromStr;
use std::{path::PathBuf, str::FromStr};

use crate::{
models::storage::Storage, models::storage::StorageType, translate_storage,
AppError, Format, ResourceId,
models::storage::{Storage, StorageType},
translate_storage, AppError, Format, ResourceId,
};

use data_error::ArklibError;
Expand Down
7 changes: 3 additions & 4 deletions ark-cli/src/commands/file/insert.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
use std::path::PathBuf;
use std::str::FromStr;
use std::{path::PathBuf, str::FromStr};

use crate::{
models::storage::Storage, models::storage::StorageType, translate_storage,
AppError, Format, ResourceId,
models::storage::{Storage, StorageType},
translate_storage, AppError, Format, ResourceId,
};

use data_error::ArklibError;
Expand Down
7 changes: 3 additions & 4 deletions ark-cli/src/commands/file/read.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
use std::path::PathBuf;
use std::str::FromStr;
use std::{path::PathBuf, str::FromStr};

use crate::{
models::storage::Storage, models::storage::StorageType, translate_storage,
AppError, ResourceId,
models::storage::{Storage, StorageType},
translate_storage, AppError, ResourceId,
};

use data_error::ArklibError;
Expand Down
7 changes: 4 additions & 3 deletions ark-cli/src/commands/file/utils.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use crate::error::AppError;
use crate::models::key_value_to_str;
use crate::models::Format;
use crate::{
error::AppError,
models::{key_value_to_str, Format},
};
use data_error::Result as ArklibResult;
use fs_atomic_versions::atomic::{modify, modify_json, AtomicFile};

Expand Down
3 changes: 1 addition & 2 deletions ark-cli/src/commands/link/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@ use data_link::Link;
use std::path::PathBuf;
use url::Url;

use crate::error::AppError;
use crate::util::provide_index; // Import your custom AppError type
use crate::{error::AppError, util::provide_index}; // Import your custom AppError type

pub async fn create_link(
root: &PathBuf,
Expand Down
6 changes: 3 additions & 3 deletions ark-cli/src/commands/list.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use std::io::Read;
use std::path::PathBuf;
use std::{io::Read, path::PathBuf};

use crate::{
provide_index, provide_root, read_storage_value, AppError, DateTime,
Expand Down Expand Up @@ -137,7 +136,8 @@ impl List {
let mut contents = String::new();
match file.read_to_string(&mut contents) {
Ok(_) => {
// Check if the content of the file is a valid url
// Check if the content of the file is a
// valid url
let url = contents.trim();
let url = url::Url::parse(url);
match url {
Expand Down
3 changes: 2 additions & 1 deletion ark-cli/src/commands/render.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ impl Render {
let dest_path = filepath.with_file_name(
filepath
.file_stem()
// SAFETY: we know that the file stem is valid UTF-8 because it is a file name
// SAFETY: we know that the file stem is valid UTF-8 because it
// is a file name
.unwrap()
.to_str()
.unwrap()
Expand Down
4 changes: 2 additions & 2 deletions ark-cli/src/commands/storage/list.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use std::path::PathBuf;

use crate::{
models::storage::Storage, models::storage::StorageType, translate_storage,
AppError,
models::storage::{Storage, StorageType},
translate_storage, AppError,
};

#[derive(Clone, Debug, clap::Args)]
Expand Down
8 changes: 5 additions & 3 deletions ark-cli/src/index_registrar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@ extern crate canonical_path;
use data_error::{ArklibError, Result};
use fs_index::ResourceIndex;

use std::collections::HashMap;
use std::path::Path;
use std::sync::{Arc, RwLock};
use std::{
collections::HashMap,
path::Path,
sync::{Arc, RwLock},
};

use crate::ResourceId;

Expand Down
30 changes: 15 additions & 15 deletions ark-cli/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
use std::fs::{create_dir_all, File};
use std::path::PathBuf;
use std::{
fs::{create_dir_all, File},
path::PathBuf,
};

use crate::index_registrar::provide_index;
use data_pdf::{render_preview_page, PDFQuality};
Expand All @@ -15,25 +17,23 @@ use fs_storage::ARK_FOLDER;

use anyhow::Result;

use chrono::prelude::DateTime;
use chrono::Utc;
use chrono::{prelude::DateTime, Utc};

use clap::CommandFactory;
use clap::FromArgMatches;
use clap::{CommandFactory, FromArgMatches};

use fs_extra::dir::{self, CopyOptions};

use home::home_dir;

use crate::cli::Cli;
use crate::commands::file::File::{Append, Insert, Read};
use crate::commands::link::Link::{Create, Load};
use crate::commands::Commands::Link;
use crate::commands::Commands::Storage;
use crate::commands::Commands::*;
use crate::models::EntryOutput;
use crate::models::Format;
use crate::models::Sort;
use crate::{
cli::Cli,
commands::{
file::File::{Append, Insert, Read},
link::Link::{Create, Load},
Commands::{Link, Storage, *},
},
models::{EntryOutput, Format, Sort},
};

use crate::error::AppError;

Expand Down
3 changes: 1 addition & 2 deletions ark-cli/src/models/storage.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use crate::ResourceId;
use fs_atomic_versions::atomic::AtomicFile;
use std::fmt::Write;
use std::path::PathBuf;
use std::{fmt::Write, path::PathBuf};

use crate::{
commands::{file_append, file_insert, format_file, format_line},
Expand Down
26 changes: 14 additions & 12 deletions ark-cli/src/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,21 @@ use fs_storage::{
ARK_FOLDER, PREVIEWS_STORAGE_FOLDER, SCORE_STORAGE_FILE, STATS_FOLDER,
TAG_STORAGE_FILE, THUMBNAILS_STORAGE_FOLDER,
};
use std::env::current_dir;
use std::fs::{canonicalize, metadata};
use std::io::BufRead;
use std::io::BufReader;
use std::path::Path;
use std::str::FromStr;
use std::thread;
use std::time::{Duration, Instant, SystemTime, UNIX_EPOCH};
use std::{fs::File, path::PathBuf};
use std::{
env::current_dir,
fs::{canonicalize, metadata, File},
io::{BufRead, BufReader},
path::{Path, PathBuf},
str::FromStr,
thread,
time::{Duration, Instant, SystemTime, UNIX_EPOCH},
};

use crate::error::AppError;
use crate::models::storage::{Storage, StorageType};
use crate::ARK_CONFIG;
use crate::{
error::AppError,
models::storage::{Storage, StorageType},
ARK_CONFIG,
};

pub fn discover_roots(
roots_cfg: &Option<PathBuf>,
Expand Down
5 changes: 1 addition & 4 deletions data-json/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
use serde_json::json;
use serde_json::map::Entry;
use serde_json::Map;
use serde_json::Value;
use serde_json::{json, map::Entry, Map, Value};

pub fn merge(origin: Value, new_data: Value) -> Value {
match (origin, new_data) {
Expand Down
18 changes: 10 additions & 8 deletions data-link/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,20 @@ use data_error::Result;
use data_resource::ResourceId;
use fs_atomic_versions::atomic::AtomicFile;
use fs_metadata::store_metadata;
use fs_properties::load_raw_properties;
use fs_properties::store_properties;
use fs_properties::PROPERTIES_STORAGE_FOLDER;
use fs_properties::{
load_raw_properties, store_properties, PROPERTIES_STORAGE_FOLDER,
};
use fs_storage::{ARK_FOLDER, PREVIEWS_STORAGE_FOLDER};
use reqwest::header::HeaderValue;
use scraper::{Html, Selector};
use serde::{Deserialize, Serialize};
use std::fmt;
use std::marker::PhantomData;
use std::path::Path;
use std::str::{self, FromStr};
use std::{io::Write, path::PathBuf};
use std::{
fmt,
io::Write,
marker::PhantomData,
path::{Path, PathBuf},
str::{self, FromStr},
};
use url::Url;

#[derive(Debug, Deserialize, Serialize)]
Expand Down
10 changes: 5 additions & 5 deletions data-resource/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,16 @@
//! `data-resource` is a crate for managing resource identifiers.
use core::{fmt::Display, str::FromStr};
use data_error::Result;
use serde::de::DeserializeOwned;
use serde::Serialize;
use serde::{de::DeserializeOwned, Serialize};
use std::{fmt::Debug, hash::Hash, path::Path};

/// This trait defines a generic type representing a resource identifier.
///
/// Resources are identified by a hash value, which is computed from the resource's data.
/// The hash value is used to uniquely identify the resource.
/// Resources are identified by a hash value, which is computed from the
/// resource's data. 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.
/// Implementors of this trait must provide a way to compute the hash value from
/// the resource's data.
pub trait ResourceId:
Debug
+ Display
Expand Down
3 changes: 2 additions & 1 deletion dev-hash/benches/blake3.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ fn generate_random_data(size: usize) -> Vec<u8> {
(0..size).map(|_| rng.gen()).collect()
}

/// Benchmarks the performance of resource ID creation from file paths and random data.
/// Benchmarks the performance of resource ID creation from file paths and
/// random data.
///
/// - Measures the time taken to create a resource ID from file paths.
/// - Measures the time taken to create a resource ID from random data.
Expand Down
3 changes: 2 additions & 1 deletion dev-hash/benches/crc32.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ fn generate_random_data(size: usize) -> Vec<u8> {
(0..size).map(|_| rng.gen()).collect()
}

/// Benchmarks the performance of resource ID creation from file paths and random data.
/// Benchmarks the performance of resource ID creation from file paths and
/// random data.
///
/// - Measures the time taken to create a resource ID from file paths.
/// - Measures the time taken to create a resource ID from random data.
Expand Down
5 changes: 1 addition & 4 deletions fs-atomic-light/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
use data_error::Result;

use std::env;
use std::fs;
use std::path::Path;
use std::str;
use std::{env, fs, path::Path, str};

/// Write data to a tempory file and move that written file to destination
///
Expand Down
14 changes: 8 additions & 6 deletions fs-atomic-versions/src/atomic/file.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
use std::fs::{self, File};
use std::io::{Error, ErrorKind, Read, Result};
#[cfg(target_os = "unix")]
#[cfg(target_family = "unix")]
use std::os::unix::fs::MetadataExt;
use std::path::{Path, PathBuf};
use std::{
fs::{self, File},
io::{Error, ErrorKind, Read, Result},
path::{Path, PathBuf},
};

use crate::app_id;

Expand Down Expand Up @@ -229,7 +231,7 @@ impl AtomicFile {
// May return `EEXIST`.
let res = std::fs::hard_link(&new.path, new_path);
if let Err(err) = res {
#[cfg(target_os = "unix")]
#[cfg(target_family = "unix")]
// From open(2) manual page:
//
// "[...] create a unique file on the same filesystem (e.g.,
Expand All @@ -241,7 +243,7 @@ impl AtomicFile {
if new.path.metadata()?.nlink() != 2 {
Err(err)?;
}
#[cfg(not(target_os = "unix"))]
#[cfg(not(target_family = "unix"))]
Err(err)?;
}

Expand Down
7 changes: 4 additions & 3 deletions fs-atomic-versions/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
use lazy_static::lazy_static;
use std::path::PathBuf;
use std::sync::Once;
use std::sync::RwLock;
use std::{
path::PathBuf,
sync::{Once, RwLock},
};

pub mod app_id;
pub mod atomic;
Expand Down
Loading

0 comments on commit aee18b1

Please sign in to comment.