diff --git a/services/core_service/src/common_event/listener.rs b/services/core_service/src/common_event/listener.rs index f6933fb..c138b58 100644 --- a/services/core_service/src/common_event/listener.rs +++ b/services/core_service/src/common_event/listener.rs @@ -27,7 +27,7 @@ use asset_crypto_manager::{crypto_manager::CryptoManager, secret_key::SecretKey} use asset_db_key_operator::DbKey; use asset_db_operator::{ database::Database, - database_file_upgrade::{construct_splited_db_name, get_all_db_before_split}, + database_file_upgrade::{construct_splited_db_name, get_all_new_db}, types::{column, DbMap}, }; use asset_definition::{log_throw_error, ErrCode, Result, SyncType, Value}; @@ -239,7 +239,7 @@ pub(crate) extern "C" fn on_user_unlocked(user_id: i32) { logi!("[INFO]On user -{}- unlocked.", user_id); // Trigger upgrading db version and key alias - match get_all_db_before_split() { + match get_all_new_db() { Ok(_) => logi!("Upgrade db version and key alias succeeded."), Err(e) => loge!("Upgrade db version and key alias failed, err is: {}", e), } @@ -321,7 +321,7 @@ fn backup_all_db(start_time: &Instant) -> Result<()> { } } - // Backup all ce db if db key cipher file exists. + // Backup all ce db if accessible. let mut user_ids_size: u32 = 0; let user_ids_size_ptr = &mut user_ids_size; let mut ret: i32; diff --git a/services/crypto_manager/src/secret_key.rs b/services/crypto_manager/src/secret_key.rs index d556d79..e6a7afb 100644 --- a/services/crypto_manager/src/secret_key.rs +++ b/services/crypto_manager/src/secret_key.rs @@ -16,7 +16,7 @@ //! This module is used to implement cryptographic algorithm operations, including key generation. use asset_common::{transfer_error_code, CallingInfo, SUCCESS}; -use asset_definition::{Accessibility, AuthType, ErrCode, Result, log_throw_error}; +use asset_definition::{Accessibility, AuthType, ErrCode, Result}; use asset_log::{loge, logi, logw}; use asset_utils::hasher; diff --git a/services/db_operator/src/database_file_upgrade.rs b/services/db_operator/src/database_file_upgrade.rs index 885f574..2e0db64 100644 --- a/services/db_operator/src/database_file_upgrade.rs +++ b/services/db_operator/src/database_file_upgrade.rs @@ -75,19 +75,6 @@ fn get_db_before_split(user_id: i32) -> Result { get_db(user_id, OLD_DB_NAME, false) } -/// Trigger upgrading db_version and key alias -pub fn get_all_db_before_split() -> Result> { - let mut db_vec = Vec::new(); - for entry in fs::read_dir(DE_ROOT_PATH)? { - let entry = entry?; - if let Ok(user_id) = entry.file_name().to_string_lossy().parse::() { - db_vec.push(get_db_before_split(user_id)?); - } - } - - Ok(db_vec) -} - fn get_value_from_db_map(db_map: &DbMap, key: &str) -> Result { match db_map.get(key) { Some(value) => Ok(value.clone()), @@ -115,6 +102,25 @@ fn get_new_db(user_id: i32, info_map: &DbMap) -> Result { get_db(user_id, &new_db_name, false) } +/// Get all new db +pub fn get_all_new_db() -> Result> { + let mut db_vec = Vec::new(); + for entry in fs::read_dir(DE_ROOT_PATH)? { + let entry = entry?; + if let Ok(user_id) = entry.file_name().to_string_lossy().parse::() { + // 1.1 extract db name stem from new db name + if let Some(new_db_name_stem) = entry.file_name().to_string_lossy().split('.').next() { + // 1.2 construct new db + let db = get_db(user_id, new_db_name_stem, false)?; + // 1.3 push new db into vec + db_vec.push(db); + } + } + } + + Ok(db_vec) +} + fn construct_old_query_condition(info_map: &DbMap) -> Result { let mut old_data_query_condition = DbMap::new(); let owner_info = info_map.get_bytes_attr(&column::OWNER)?;