!2155 fix account list no update

Merge pull request !2155 from steven_Q/1011
This commit is contained in:
openharmony_ci 2024-10-11 14:20:28 +00:00 committed by Gitee
commit 2c432ea21b
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
2 changed files with 9 additions and 2 deletions

View File

@ -338,6 +338,7 @@ bool AccountFileOperator::IsJsonFormat(const std::string &path)
nlohmann::json jsonData = nlohmann::json::parse(content, nullptr, false);
if (jsonData.is_discarded() || !jsonData.is_structured()) {
ACCOUNT_LOGE("File %{public}s is invalid json format, size: %{public}zu", path.c_str(), content.size());
return false;
}
return true;

View File

@ -949,7 +949,7 @@ ErrCode OsAccountControlFileManager::InsertOsAccount(OsAccountInfo &osAccountInf
std::string path = Constants::USER_INFO_BASE + Constants::PATH_SEPARATOR + osAccountInfo.GetPrimeKey() +
Constants::PATH_SEPARATOR + Constants::USER_INFO_FILE_NAME;
if (accountFileOperator_->IsExistFile(path) && accountFileOperator_->IsJsonFormat(path)) {
ACCOUNT_LOGE("OsAccountControlFileManagerInsertOsAccountControlFileManagerCreateAccountDir ERR");
ACCOUNT_LOGE("Account %{public}d already exists", osAccountInfo.GetLocalId());
return ERR_OSACCOUNT_SERVICE_CONTROL_INSERT_FILE_EXISTS_ERROR;
}
@ -959,6 +959,13 @@ ErrCode OsAccountControlFileManager::InsertOsAccount(OsAccountInfo &osAccountInf
return ERR_OSACCOUNT_SERVICE_ACCOUNT_INFO_EMPTY_ERROR;
}
std::lock_guard<std::mutex> lock(accountInfoFileLock_);
if (osAccountInfo.GetLocalId() >= Constants::START_USER_ID) {
ErrCode updateRet = UpdateAccountList(osAccountInfo.GetPrimeKey(), true);
if (updateRet != ERR_OK) {
ACCOUNT_LOGE("Update account list failed, errCode: %{public}d", updateRet);
return updateRet;
}
}
ErrCode result = accountFileOperator_->InputFileByPathAndContent(path, accountInfoStr);
if (result != ERR_OK) {
ACCOUNT_LOGE("InputFileByPathAndContent failed! path %{public}s.", path.c_str());
@ -971,7 +978,6 @@ ErrCode OsAccountControlFileManager::InsertOsAccount(OsAccountInfo &osAccountInf
if (osAccountInfo.GetLocalId() >= Constants::START_USER_ID) {
accountFileWatcherMgr_.AddAccountInfoDigest(accountInfoStr, path);
accountFileWatcherMgr_.AddFileWatcher(osAccountInfo.GetLocalId(), eventCallbackFunc_);
return UpdateAccountList(osAccountInfo.GetPrimeKey(), true);
}
ACCOUNT_LOGI("end");
return ERR_OK;