mirror of https://github.com/zkat/cacache-rs.git
misc: clippy fixes
This commit is contained in:
parent
dca57e1100
commit
2767a6a671
|
|
@ -43,7 +43,7 @@ fn baseline_read_many_sync(c: &mut Criterion) {
|
|||
let tmp = tempfile::tempdir().unwrap();
|
||||
let paths: Vec<_> = (0..)
|
||||
.take(NUM_REPEATS)
|
||||
.map(|i| tmp.path().join(format!("test_file_{}", i)))
|
||||
.map(|i| tmp.path().join(format!("test_file_{i}")))
|
||||
.collect();
|
||||
let data = b"hello world";
|
||||
for path in paths.iter() {
|
||||
|
|
@ -76,7 +76,7 @@ fn baseline_read_many_async(c: &mut Criterion) {
|
|||
let tmp = tempfile::tempdir().unwrap();
|
||||
let paths: Vec<_> = (0..)
|
||||
.take(NUM_REPEATS)
|
||||
.map(|i| tmp.path().join(format!("test_file_{}", i)))
|
||||
.map(|i| tmp.path().join(format!("test_file_{i}")))
|
||||
.collect();
|
||||
let data = b"hello world";
|
||||
for path in paths.iter() {
|
||||
|
|
@ -107,7 +107,7 @@ fn read_hash_many_sync(c: &mut Criterion) {
|
|||
let cache = tmp.path().to_owned();
|
||||
let data: Vec<_> = (0..)
|
||||
.take(NUM_REPEATS)
|
||||
.map(|i| format!("test_file_{}", i))
|
||||
.map(|i| format!("test_file_{i}"))
|
||||
.collect();
|
||||
let sris: Vec<_> = data
|
||||
.iter()
|
||||
|
|
@ -147,7 +147,7 @@ fn read_hash_many_async(c: &mut Criterion) {
|
|||
let cache = tmp.path().to_owned();
|
||||
let data: Vec<_> = (0..)
|
||||
.take(NUM_REPEATS)
|
||||
.map(|i| format!("test_file_{}", i))
|
||||
.map(|i| format!("test_file_{i}"))
|
||||
.collect();
|
||||
let sris: Vec<_> = data
|
||||
.iter()
|
||||
|
|
@ -200,7 +200,7 @@ fn write_hash_async(c: &mut Criterion) {
|
|||
b.iter_custom(|iters| {
|
||||
let start = std::time::Instant::now();
|
||||
for i in 0..iters {
|
||||
block_on(cacache::write_hash(&cache, format!("hello world{}", i))).unwrap();
|
||||
block_on(cacache::write_hash(&cache, format!("hello world{i}"))).unwrap();
|
||||
}
|
||||
start.elapsed()
|
||||
})
|
||||
|
|
|
|||
|
|
@ -1,42 +1,42 @@
|
|||
use ssri::Integrity;
|
||||
use std::path::{Path, PathBuf};
|
||||
|
||||
const CONTENT_VERSION: &str = "2";
|
||||
|
||||
// Current format of content file path:
|
||||
//
|
||||
// sha512-BaSE64Hex= ->
|
||||
// ~/.my-cache/content-v2/sha512/ba/da/55deadbeefc0ffee
|
||||
//
|
||||
pub fn content_path(cache: &Path, sri: &Integrity) -> PathBuf {
|
||||
let mut path = PathBuf::new();
|
||||
let (algo, hex) = sri.to_hex();
|
||||
path.push(cache);
|
||||
path.push(format!("content-v{}", CONTENT_VERSION));
|
||||
path.push(algo.to_string());
|
||||
path.push(&hex[0..2]);
|
||||
path.push(&hex[2..4]);
|
||||
path.push(&hex[4..]);
|
||||
path
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use ssri::Integrity;
|
||||
use std::path::Path;
|
||||
|
||||
#[test]
|
||||
fn basic_test() {
|
||||
let sri = Integrity::from(b"hello world");
|
||||
let cpath = content_path(Path::new("~/.my-cache"), &sri);
|
||||
let mut wanted = PathBuf::new();
|
||||
wanted.push("~/.my-cache");
|
||||
wanted.push(format!("content-v{}", CONTENT_VERSION));
|
||||
wanted.push("sha256");
|
||||
wanted.push("b9");
|
||||
wanted.push("4d");
|
||||
wanted.push("27b9934d3e08a52e52d7da7dabfac484efe37a5380ee9088f7ace2efcde9");
|
||||
assert_eq!(cpath.to_str().unwrap(), wanted.to_str().unwrap());
|
||||
}
|
||||
}
|
||||
use ssri::Integrity;
|
||||
use std::path::{Path, PathBuf};
|
||||
|
||||
const CONTENT_VERSION: &str = "2";
|
||||
|
||||
// Current format of content file path:
|
||||
//
|
||||
// sha512-BaSE64Hex= ->
|
||||
// ~/.my-cache/content-v2/sha512/ba/da/55deadbeefc0ffee
|
||||
//
|
||||
pub fn content_path(cache: &Path, sri: &Integrity) -> PathBuf {
|
||||
let mut path = PathBuf::new();
|
||||
let (algo, hex) = sri.to_hex();
|
||||
path.push(cache);
|
||||
path.push(format!("content-v{CONTENT_VERSION}"));
|
||||
path.push(algo.to_string());
|
||||
path.push(&hex[0..2]);
|
||||
path.push(&hex[2..4]);
|
||||
path.push(&hex[4..]);
|
||||
path
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use ssri::Integrity;
|
||||
use std::path::Path;
|
||||
|
||||
#[test]
|
||||
fn basic_test() {
|
||||
let sri = Integrity::from(b"hello world");
|
||||
let cpath = content_path(Path::new("~/.my-cache"), &sri);
|
||||
let mut wanted = PathBuf::new();
|
||||
wanted.push("~/.my-cache");
|
||||
wanted.push(format!("content-v{CONTENT_VERSION}"));
|
||||
wanted.push("sha256");
|
||||
wanted.push("b9");
|
||||
wanted.push("4d");
|
||||
wanted.push("27b9934d3e08a52e52d7da7dabfac484efe37a5380ee9088f7ace2efcde9");
|
||||
assert_eq!(cpath.to_str().unwrap(), wanted.to_str().unwrap());
|
||||
}
|
||||
}
|
||||
|
|
|
|||
24
src/index.rs
24
src/index.rs
|
|
@ -74,19 +74,19 @@ pub fn insert(cache: &Path, key: &str, opts: WriteOpts) -> Result<Integrity> {
|
|||
size: opts.size.unwrap_or(0),
|
||||
metadata: opts.metadata.unwrap_or(serde_json::Value::Null),
|
||||
})
|
||||
.with_context(|| format!("Failed to serialize entry with key `{}`", key))?;
|
||||
.with_context(|| format!("Failed to serialize entry with key `{key}`"))?;
|
||||
|
||||
let mut buck = OpenOptions::new()
|
||||
.create(true)
|
||||
.append(true)
|
||||
.open(&bucket)
|
||||
.with_context(|| format!("Failed to create or open index bucket at {:?}", bucket))?;
|
||||
.with_context(|| format!("Failed to create or open index bucket at {bucket:?}"))?;
|
||||
|
||||
let out = format!("\n{}\t{}", hash_entry(&stringified), stringified);
|
||||
buck.write_all(out.as_bytes())
|
||||
.with_context(|| format!("Failed to write to index bucket at {:?}", bucket))?;
|
||||
.with_context(|| format!("Failed to write to index bucket at {bucket:?}"))?;
|
||||
buck.flush()
|
||||
.with_context(|| format!("Failed to flush bucket at {:?}", bucket))?;
|
||||
.with_context(|| format!("Failed to flush bucket at {bucket:?}"))?;
|
||||
Ok(opts
|
||||
.sri
|
||||
.or_else(|| "sha1-deadbeef".parse::<Integrity>().ok())
|
||||
|
|
@ -110,22 +110,22 @@ pub async fn insert_async<'a>(cache: &'a Path, key: &'a str, opts: WriteOpts) ->
|
|||
size: opts.size.unwrap_or(0),
|
||||
metadata: opts.metadata.unwrap_or(serde_json::Value::Null),
|
||||
})
|
||||
.with_context(|| format!("Failed to serialize entry with key `{}`", key))?;
|
||||
.with_context(|| format!("Failed to serialize entry with key `{key}`"))?;
|
||||
|
||||
let mut buck = crate::async_lib::OpenOptions::new()
|
||||
.create(true)
|
||||
.append(true)
|
||||
.open(&bucket)
|
||||
.await
|
||||
.with_context(|| format!("Failed to create or open index bucket at {:?}", bucket))?;
|
||||
.with_context(|| format!("Failed to create or open index bucket at {bucket:?}"))?;
|
||||
|
||||
let out = format!("\n{}\t{}", hash_entry(&stringified), stringified);
|
||||
buck.write_all(out.as_bytes())
|
||||
.await
|
||||
.with_context(|| format!("Failed to write to index bucket at {:?}", bucket))?;
|
||||
.with_context(|| format!("Failed to write to index bucket at {bucket:?}"))?;
|
||||
buck.flush()
|
||||
.await
|
||||
.with_context(|| format!("Failed to flush bucket at {:?}", bucket))?;
|
||||
.with_context(|| format!("Failed to flush bucket at {bucket:?}"))?;
|
||||
Ok(opts
|
||||
.sri
|
||||
.or_else(|| "sha1-deadbeef".parse::<Integrity>().ok())
|
||||
|
|
@ -135,7 +135,7 @@ pub async fn insert_async<'a>(cache: &'a Path, key: &'a str, opts: WriteOpts) ->
|
|||
pub fn find(cache: &Path, key: &str) -> Result<Option<Metadata>> {
|
||||
let bucket = bucket_path(cache, key);
|
||||
Ok(bucket_entries(&bucket)
|
||||
.with_context(|| format!("Failed to read index bucket entries from {:?}", bucket))?
|
||||
.with_context(|| format!("Failed to read index bucket entries from {bucket:?}"))?
|
||||
.into_iter()
|
||||
.fold(None, |acc, entry| {
|
||||
if entry.key == key {
|
||||
|
|
@ -164,7 +164,7 @@ pub async fn find_async(cache: &Path, key: &str) -> Result<Option<Metadata>> {
|
|||
let bucket = bucket_path(cache, key);
|
||||
Ok(bucket_entries_async(&bucket)
|
||||
.await
|
||||
.with_context(|| format!("Failed to read index bucket entries from {:?}", bucket))?
|
||||
.with_context(|| format!("Failed to read index bucket entries from {bucket:?}"))?
|
||||
.into_iter()
|
||||
.fold(None, |acc, entry| {
|
||||
if entry.key == key {
|
||||
|
|
@ -220,7 +220,7 @@ pub async fn delete_async(cache: &Path, key: &str) -> Result<()> {
|
|||
}
|
||||
|
||||
pub fn ls(cache: &Path) -> impl Iterator<Item = Result<Metadata>> {
|
||||
WalkDir::new(cache.join(format!("index-v{}", INDEX_VERSION)))
|
||||
WalkDir::new(cache.join(format!("index-v{INDEX_VERSION}")))
|
||||
.into_iter()
|
||||
.map(|bucket| {
|
||||
let bucket = bucket.to_internal()?;
|
||||
|
|
@ -257,7 +257,7 @@ pub fn ls(cache: &Path) -> impl Iterator<Item = Result<Metadata>> {
|
|||
fn bucket_path(cache: &Path, key: &str) -> PathBuf {
|
||||
let hashed = hash_key(key);
|
||||
cache
|
||||
.join(format!("index-v{}", INDEX_VERSION))
|
||||
.join(format!("index-v{INDEX_VERSION}"))
|
||||
.join(&hashed[0..2])
|
||||
.join(&hashed[2..4])
|
||||
.join(&hashed[4..])
|
||||
|
|
|
|||
Loading…
Reference in New Issue