2021-09-21 19:23:22 +08:00
|
|
|
#[macro_use]
|
|
|
|
pub mod error;
|
|
|
|
pub mod options;
|
|
|
|
|
|
|
|
pub mod index;
|
|
|
|
pub mod index_controller;
|
|
|
|
|
2021-09-22 17:52:29 +08:00
|
|
|
pub use index_controller::{IndexController as MeiliSearch, updates::RegisterUpdate};
|
2021-09-21 19:23:22 +08:00
|
|
|
|
2021-09-27 22:48:03 +08:00
|
|
|
mod compression;
|
|
|
|
|
2021-09-21 19:23:22 +08:00
|
|
|
use walkdir::WalkDir;
|
|
|
|
|
|
|
|
pub trait EnvSizer {
|
|
|
|
fn size(&self) -> u64;
|
|
|
|
}
|
|
|
|
|
|
|
|
impl EnvSizer for heed::Env {
|
|
|
|
fn size(&self) -> u64 {
|
|
|
|
WalkDir::new(self.path())
|
|
|
|
.into_iter()
|
|
|
|
.filter_map(|entry| entry.ok())
|
|
|
|
.filter_map(|entry| entry.metadata().ok())
|
|
|
|
.filter(|metadata| metadata.is_file())
|
|
|
|
.fold(0, |acc, m| acc + m.len())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
use std::fs::{create_dir_all, File};
|
|
|
|
use std::io::Write;
|
|
|
|
use std::path::Path;
|
|
|
|
|
|
|
|
use flate2::{read::GzDecoder, write::GzEncoder, Compression};
|
|
|
|
use tar::{Archive, Builder};
|
|
|
|
|
|
|
|
pub fn to_tar_gz(src: impl AsRef<Path>, dest: impl AsRef<Path>) -> anyhow::Result<()> {
|
|
|
|
let mut f = File::create(dest)?;
|
|
|
|
let gz_encoder = GzEncoder::new(&mut f, Compression::default());
|
|
|
|
let mut tar_encoder = Builder::new(gz_encoder);
|
|
|
|
tar_encoder.append_dir_all(".", src)?;
|
|
|
|
let gz_encoder = tar_encoder.into_inner()?;
|
|
|
|
gz_encoder.finish()?;
|
|
|
|
f.flush()?;
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn from_tar_gz(src: impl AsRef<Path>, dest: impl AsRef<Path>) -> anyhow::Result<()> {
|
|
|
|
let f = File::open(&src)?;
|
|
|
|
let gz = GzDecoder::new(f);
|
|
|
|
let mut ar = Archive::new(gz);
|
|
|
|
create_dir_all(&dest)?;
|
|
|
|
ar.unpack(&dest)?;
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
|