From ca4234b445da4296b3222c07b1b69545c040f0c9 Mon Sep 17 00:00:00 2001 From: Irevoire Date: Fri, 21 Oct 2022 18:09:51 +0200 Subject: [PATCH] fix the deletion of the data.ms in case of failure --- meilisearch-http/src/lib.rs | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/meilisearch-http/src/lib.rs b/meilisearch-http/src/lib.rs index d9a3c35d6..e075428d5 100644 --- a/meilisearch-http/src/lib.rs +++ b/meilisearch-http/src/lib.rs @@ -144,8 +144,13 @@ pub fn setup_meilisearch(opt: &Opt) -> anyhow::Result<(IndexScheduler, AuthContr if empty_db && src_path_exists { let (mut index_scheduler, mut auth_controller) = meilisearch_builder()?; - import_dump(&opt.db_path, path, &mut index_scheduler, &mut auth_controller)?; - (index_scheduler, auth_controller) + match import_dump(&opt.db_path, path, &mut index_scheduler, &mut auth_controller) { + Ok(()) => (index_scheduler, auth_controller), + Err(e) => { + std::fs::remove_dir_all(&opt.db_path)?; + return Err(e.into()); + } + } } else if !empty_db && !opt.ignore_dump_if_db_exists { bail!( "database already exists at {:?}, try to delete it or rename it", @@ -155,8 +160,13 @@ pub fn setup_meilisearch(opt: &Opt) -> anyhow::Result<(IndexScheduler, AuthContr bail!("dump doesn't exist at {:?}", path) } else { let (mut index_scheduler, mut auth_controller) = meilisearch_builder()?; - import_dump(&opt.db_path, path, &mut index_scheduler, &mut auth_controller)?; - (index_scheduler, auth_controller) + match import_dump(&opt.db_path, path, &mut index_scheduler, &mut auth_controller) { + Ok(()) => (index_scheduler, auth_controller), + Err(e) => { + std::fs::remove_dir_all(&opt.db_path)?; + return Err(e.into()); + } + } } } else { meilisearch_builder()?