use crate::error::Error;
use async_trait::async_trait;
use std::path::PathBuf;
use std::sync::{atomic::AtomicU64, Arc};
use tokio::sync::Semaphore;
use super::{BlockRm, BlockRmError, Column, DataStore, RepoCid};
mod pinstore;
mod blocks;
pub use blocks::FsBlockStore;
mod paths;
use paths::{block_path, filestem_to_block_cid, filestem_to_pin_cid, pin_path};
#[derive(Debug)]
pub struct FsDataStore {
path: PathBuf,
lock: Arc<Semaphore>,
written_bytes: AtomicU64,
}
#[async_trait]
impl DataStore for FsDataStore {
fn new(mut root: PathBuf) -> Self {
root.push("pins");
FsDataStore {
path: root,
lock: Arc::new(Semaphore::new(1)),
written_bytes: Default::default(),
}
}
async fn init(&self) -> Result<(), Error> {
tokio::fs::create_dir_all(&self.path).await?;
Ok(())
}
async fn open(&self) -> Result<(), Error> {
Ok(())
}
async fn contains(&self, _col: Column, _key: &[u8]) -> Result<bool, Error> {
Err(anyhow::anyhow!("not implemented"))
}
async fn get(&self, _col: Column, _key: &[u8]) -> Result<Option<Vec<u8>>, Error> {
Err(anyhow::anyhow!("not implemented"))
}
async fn put(&self, _col: Column, _key: &[u8], _value: &[u8]) -> Result<(), Error> {
Err(anyhow::anyhow!("not implemented"))
}
async fn remove(&self, _col: Column, _key: &[u8]) -> Result<(), Error> {
Err(anyhow::anyhow!("not implemented"))
}
async fn wipe(&self) {
todo!()
}
}
#[cfg(test)]
crate::pinstore_interface_tests!(common_tests, crate::repo::fs::FsDataStore::new);