From 6a1af585cce26f559da915ee57ceae2cebe2e98b Mon Sep 17 00:00:00 2001 From: steven_q Date: Fri, 11 Oct 2024 20:37:02 +0800 Subject: [PATCH] fix account list no update Signed-off-by: steven_q Change-Id: I07997e28e389a231bbef87cd34a810b81634bd82 --- .../common/file_operator/src/account_file_operator.cpp | 1 + .../src/osaccount/os_account_control_file_manager.cpp | 10 ++++++++-- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/frameworks/common/file_operator/src/account_file_operator.cpp b/frameworks/common/file_operator/src/account_file_operator.cpp index ef2c5ddb0..6d371d684 100644 --- a/frameworks/common/file_operator/src/account_file_operator.cpp +++ b/frameworks/common/file_operator/src/account_file_operator.cpp @@ -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; diff --git a/services/accountmgr/src/osaccount/os_account_control_file_manager.cpp b/services/accountmgr/src/osaccount/os_account_control_file_manager.cpp index 2411525c2..68d5d8eb5 100644 --- a/services/accountmgr/src/osaccount/os_account_control_file_manager.cpp +++ b/services/accountmgr/src/osaccount/os_account_control_file_manager.cpp @@ -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 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;