2022-10-03 18:50:06 +02:00
|
|
|
use std::io::Read;
|
2022-10-03 13:57:18 +02:00
|
|
|
use std::{fs::File, io::BufReader};
|
|
|
|
|
2022-10-05 20:11:07 +02:00
|
|
|
use flate2::bufread::GzDecoder;
|
2022-10-09 17:30:34 +02:00
|
|
|
|
2022-10-05 20:11:07 +02:00
|
|
|
use serde::Deserialize;
|
2022-10-03 13:57:18 +02:00
|
|
|
|
|
|
|
use tempfile::TempDir;
|
|
|
|
|
2022-10-10 18:57:27 +02:00
|
|
|
use crate::{Result, Version};
|
2022-10-03 13:57:18 +02:00
|
|
|
|
2022-10-06 19:44:50 +02:00
|
|
|
use self::compat::Compat;
|
|
|
|
|
2022-10-06 14:41:21 +02:00
|
|
|
mod compat;
|
2022-10-10 18:57:27 +02:00
|
|
|
|
|
|
|
// pub(self) mod v1;
|
2022-10-09 23:47:56 +02:00
|
|
|
pub(self) mod v2;
|
2022-10-07 16:43:05 +02:00
|
|
|
pub(self) mod v3;
|
2022-10-05 20:11:07 +02:00
|
|
|
pub(self) mod v4;
|
|
|
|
pub(self) mod v5;
|
|
|
|
pub(self) mod v6;
|
2022-10-03 13:57:18 +02:00
|
|
|
|
2022-10-10 17:58:30 +02:00
|
|
|
pub type Document = serde_json::Map<String, serde_json::Value>;
|
|
|
|
pub type UpdateFile = dyn Iterator<Item = Result<Document>>;
|
|
|
|
|
2022-10-06 19:44:50 +02:00
|
|
|
pub fn open(dump: impl Read) -> Result<Compat> {
|
2022-10-03 13:57:18 +02:00
|
|
|
let path = TempDir::new()?;
|
|
|
|
let mut dump = BufReader::new(dump);
|
|
|
|
let gz = GzDecoder::new(&mut dump);
|
|
|
|
let mut archive = tar::Archive::new(gz);
|
|
|
|
archive.unpack(path.path())?;
|
|
|
|
|
|
|
|
#[derive(Deserialize)]
|
2022-10-03 18:50:06 +02:00
|
|
|
#[serde(rename_all = "camelCase")]
|
2022-10-03 13:57:18 +02:00
|
|
|
struct MetadataVersion {
|
|
|
|
pub dump_version: Version,
|
|
|
|
}
|
|
|
|
let mut meta_file = File::open(path.path().join("metadata.json"))?;
|
|
|
|
let MetadataVersion { dump_version } = serde_json::from_reader(&mut meta_file)?;
|
|
|
|
|
|
|
|
match dump_version {
|
|
|
|
// Version::V1 => Ok(Box::new(v1::Reader::open(path)?)),
|
|
|
|
Version::V1 => todo!(),
|
2022-10-10 18:57:27 +02:00
|
|
|
Version::V2 => Ok(v2::V2Reader::open(path)?
|
|
|
|
.to_v3()
|
|
|
|
.to_v4()
|
|
|
|
.to_v5()
|
|
|
|
.to_v6()
|
|
|
|
.into()),
|
2022-10-09 02:49:42 +02:00
|
|
|
Version::V3 => Ok(v3::V3Reader::open(path)?.to_v4().to_v5().to_v6().into()),
|
|
|
|
Version::V4 => Ok(v4::V4Reader::open(path)?.to_v5().to_v6().into()),
|
2022-10-06 19:44:50 +02:00
|
|
|
Version::V5 => Ok(v5::V5Reader::open(path)?.to_v6().into()),
|
|
|
|
Version::V6 => Ok(v6::V6Reader::open(path)?.into()),
|
2022-10-03 16:12:01 +02:00
|
|
|
}
|
2022-10-03 13:57:18 +02:00
|
|
|
}
|