upgrade key alias 10

Signed-off-by: Cai Xincheng <caixincheng@huawei.com>
Change-Id: Ia1a64a93b666bc5676b32b051d29bedbf101ef63
This commit is contained in:
Cai Xincheng 2024-09-20 18:06:38 +08:00
parent ff837be7f9
commit a038a9002e
3 changed files with 23 additions and 17 deletions

View File

@ -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;

View File

@ -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;

View File

@ -75,19 +75,6 @@ fn get_db_before_split(user_id: i32) -> Result<Database> {
get_db(user_id, OLD_DB_NAME, false)
}
/// Trigger upgrading db_version and key alias
pub fn get_all_db_before_split() -> Result<Vec<Database>> {
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::<i32>() {
db_vec.push(get_db_before_split(user_id)?);
}
}
Ok(db_vec)
}
fn get_value_from_db_map(db_map: &DbMap, key: &str) -> Result<Value> {
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<Database> {
get_db(user_id, &new_db_name, false)
}
/// Get all new db
pub fn get_all_new_db() -> Result<Vec<Database>> {
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::<i32>() {
// 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<DbMap> {
let mut old_data_query_condition = DbMap::new();
let owner_info = info_map.get_bytes_attr(&column::OWNER)?;