Skip to content

Commit

Permalink
refactor: remove unused items
Browse files Browse the repository at this point in the history
  • Loading branch information
KSXGitHub committed Oct 30, 2023
1 parent 90da00b commit 6d43bce
Showing 1 changed file with 2 additions and 55 deletions.
57 changes: 2 additions & 55 deletions crates/cafs/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,8 @@
#![allow(unused)]

use std::{
fs,
path::{Path, PathBuf},
};

use derive_more::{Display, Error, From};
use miette::Diagnostic;
use pacquet_store_dir::StoreDir;
use ssri::{Algorithm, IntegrityOpts};
use std::{fs, path::PathBuf};

#[derive(Debug, Display, Error, From, Diagnostic)]
#[non_exhaustive]
Expand All @@ -17,27 +11,6 @@ pub enum CafsError {
Io(std::io::Error), // TODO: remove derive(From), split this variant
}

enum FileType {
Exec,
NonExec,
Index,
}

impl FileType {
fn file_name_suffix(&self) -> &'static str {
match self {
FileType::Exec => "-exec",
FileType::NonExec => "",
FileType::Index => "-index.json",
}
}
}

fn content_path_from_hex(file_type: FileType, hex: &str) -> PathBuf {
let file_name = format!("{}{}", &hex[2..], file_type.file_name_suffix());
Path::new(&hex[..2]).join(file_name)
}

pub fn write_sync(store_dir: &StoreDir, buffer: &[u8]) -> Result<PathBuf, CafsError> {
let integrity = IntegrityOpts::new().algorithm(Algorithm::Sha512).chain(buffer).result();
let file_path = store_dir.file_path_by_content_address(&integrity, None);
Expand All @@ -51,33 +24,7 @@ pub fn write_sync(store_dir: &StoreDir, buffer: &[u8]) -> Result<PathBuf, CafsEr
Ok(file_path)
}

pub fn prune_sync(store_dir: &StoreDir) -> Result<(), CafsError> {
pub fn prune_sync(_store_dir: &StoreDir) -> Result<(), CafsError> {

Check warning on line 27 in crates/cafs/src/lib.rs

View check run for this annotation

Codecov / codecov/patch

crates/cafs/src/lib.rs#L27

Added line #L27 was not covered by tests
// Ref: https://pnpm.io/cli/store#prune
todo!("remove orphaned files")

Check warning on line 29 in crates/cafs/src/lib.rs

View check run for this annotation

Codecov / codecov/patch

crates/cafs/src/lib.rs#L29

Added line #L29 was not covered by tests
}

#[cfg(test)]
mod tests {
use std::{env, str::FromStr};

use pretty_assertions::assert_eq;
use tempfile::tempdir;

use super::*;

#[test]
fn create_content_path_from_hex() {
assert_eq!(
content_path_from_hex(FileType::NonExec, "1234567890abcdef1234567890abcdef12345678"),
PathBuf::from("12/34567890abcdef1234567890abcdef12345678")
);
assert_eq!(
content_path_from_hex(FileType::Exec, "1234567890abcdef1234567890abcdef12345678"),
PathBuf::from("12/34567890abcdef1234567890abcdef12345678-exec")
);
assert_eq!(
content_path_from_hex(FileType::Index, "1234567890abcdef1234567890abcdef12345678"),
PathBuf::from("12/34567890abcdef1234567890abcdef12345678-index.json")
);
}
}

0 comments on commit 6d43bce

Please sign in to comment.