mirror of
				https://github.com/meilisearch/meilisearch.git
				synced 2025-11-04 09:56:28 +00:00 
			
		
		
		
	Move dump v4 patcher into v4.rs
This commit is contained in:
		@@ -1,12 +1,12 @@
 | 
			
		||||
use std::fs::{self, create_dir_all, File};
 | 
			
		||||
use std::io::Write;
 | 
			
		||||
use std::io::{BufReader, Write};
 | 
			
		||||
use std::path::Path;
 | 
			
		||||
 | 
			
		||||
use fs_extra::dir::{self, CopyOptions};
 | 
			
		||||
use log::info;
 | 
			
		||||
use serde_json::{Deserializer, Map, Value};
 | 
			
		||||
use tempfile::tempdir;
 | 
			
		||||
 | 
			
		||||
use meilisearch_auth::AuthController;
 | 
			
		||||
use uuid::Uuid;
 | 
			
		||||
 | 
			
		||||
use crate::dump::{compat, Metadata};
 | 
			
		||||
use crate::options::IndexerOpts;
 | 
			
		||||
@@ -26,14 +26,10 @@ pub fn load_dump(
 | 
			
		||||
    let options = CopyOptions::default();
 | 
			
		||||
 | 
			
		||||
    // Indexes
 | 
			
		||||
    dir::copy(src.as_ref().join("indexes"), patched_dir.path(), &options)?;
 | 
			
		||||
    dir::copy(src.as_ref().join("indexes"), &patched_dir, &options)?;
 | 
			
		||||
 | 
			
		||||
    // Index uuids
 | 
			
		||||
    dir::copy(
 | 
			
		||||
        src.as_ref().join("index_uuids"),
 | 
			
		||||
        patched_dir.path(),
 | 
			
		||||
        &options,
 | 
			
		||||
    )?;
 | 
			
		||||
    dir::copy(src.as_ref().join("index_uuids"), &patched_dir, &options)?;
 | 
			
		||||
 | 
			
		||||
    // Metadata
 | 
			
		||||
    fs::copy(
 | 
			
		||||
@@ -45,11 +41,11 @@ pub fn load_dump(
 | 
			
		||||
    patch_updates(&src, &patched_dir)?;
 | 
			
		||||
 | 
			
		||||
    // Keys
 | 
			
		||||
    AuthController::patch_dump_v4(&src, patched_dir.path())?;
 | 
			
		||||
    patch_keys(&src, &patched_dir)?;
 | 
			
		||||
 | 
			
		||||
    super::v5::load_dump(
 | 
			
		||||
        meta,
 | 
			
		||||
        patched_dir.path(),
 | 
			
		||||
        &patched_dir,
 | 
			
		||||
        dst,
 | 
			
		||||
        index_db_size,
 | 
			
		||||
        meta_env_size,
 | 
			
		||||
@@ -79,3 +75,29 @@ fn patch_updates(src: impl AsRef<Path>, dst: impl AsRef<Path>) -> anyhow::Result
 | 
			
		||||
 | 
			
		||||
    Ok(())
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
fn patch_keys(src: impl AsRef<Path>, dst: impl AsRef<Path>) -> anyhow::Result<()> {
 | 
			
		||||
    let keys_file_src = src.as_ref().join("keys");
 | 
			
		||||
 | 
			
		||||
    if !keys_file_src.exists() {
 | 
			
		||||
        return Ok(());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    fs::create_dir_all(&dst)?;
 | 
			
		||||
    let keys_file_dst = dst.as_ref().join("keys");
 | 
			
		||||
    let mut writer = File::create(&keys_file_dst)?;
 | 
			
		||||
 | 
			
		||||
    let reader = BufReader::new(File::open(&keys_file_src)?);
 | 
			
		||||
    for key in Deserializer::from_reader(reader).into_iter() {
 | 
			
		||||
        let mut key: Map<String, Value> = key?;
 | 
			
		||||
 | 
			
		||||
        // generate a new uuid v4 and insert it in the key.
 | 
			
		||||
        let uid = serde_json::to_value(Uuid::new_v4()).unwrap();
 | 
			
		||||
        key.insert("uid".to_string(), uid);
 | 
			
		||||
 | 
			
		||||
        serde_json::to_writer(&mut writer, &key)?;
 | 
			
		||||
        writer.write_all(b"\n")?;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    Ok(())
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user