feat: add revision retrieving
This commit is contained in:
@@ -1,12 +1,21 @@
|
||||
pub mod fs;
|
||||
|
||||
use std::path::PathBuf;
|
||||
use std::{io::BufReader, path::PathBuf};
|
||||
|
||||
use flate2::read::GzDecoder;
|
||||
|
||||
use crate::{Data, error::Result};
|
||||
|
||||
pub trait StorageImpl {
|
||||
fn get_revision(&self, app_state: Data) -> Result<usize>;
|
||||
fn get_revision_metadata(&self, app_state: Data) -> Result<usize>;
|
||||
fn store_revision(&self, app_state: Data) -> Result<()>;
|
||||
fn retrieve_revision(
|
||||
&self,
|
||||
app_state: Data,
|
||||
revision: usize,
|
||||
) -> Result<tar::Archive<GzDecoder<BufReader<std::fs::File>>>>;
|
||||
fn unpack_revision(&self, app_state: Data, destination: PathBuf, revision: usize)
|
||||
-> Result<()>;
|
||||
}
|
||||
|
||||
pub enum Storage {
|
||||
@@ -16,9 +25,9 @@ pub enum Storage {
|
||||
pub const IGNORE_FILES: [&str; 6] = ["assets", "cache", "catpacks", "logs", "meta", "metacache"];
|
||||
|
||||
impl StorageImpl for Storage {
|
||||
fn get_revision(&self, app_state: Data) -> Result<usize> {
|
||||
fn get_revision_metadata(&self, app_state: Data) -> Result<usize> {
|
||||
match self {
|
||||
Self::FS(storage) => storage.get_revision(app_state),
|
||||
Self::FS(storage) => storage.get_revision_metadata(app_state),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -27,6 +36,27 @@ impl StorageImpl for Storage {
|
||||
Self::FS(storage) => storage.store_revision(app_state),
|
||||
}
|
||||
}
|
||||
|
||||
fn retrieve_revision(
|
||||
&self,
|
||||
app_state: Data,
|
||||
revision: usize,
|
||||
) -> Result<tar::Archive<GzDecoder<BufReader<std::fs::File>>>> {
|
||||
match self {
|
||||
Self::FS(storage) => storage.retrieve_revision(app_state, revision),
|
||||
}
|
||||
}
|
||||
|
||||
fn unpack_revision(
|
||||
&self,
|
||||
app_state: Data,
|
||||
destination: PathBuf,
|
||||
revision: usize,
|
||||
) -> Result<()> {
|
||||
match self {
|
||||
Self::FS(storage) => storage.unpack_revision(app_state, destination, revision),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn get_storage_from_env() -> Storage {
|
||||
|
||||
Reference in New Issue
Block a user