From 6029945d07403071f38a7e27f0aa0d7ebdb33b4c Mon Sep 17 00:00:00 2001 From: houpengtao Date: Sat, 24 Jun 2023 17:23:32 +0800 Subject: [PATCH] fix xts Signed-off-by: houpengtao --- frameworks/native/rdb/include/rdb_store_manager.h | 2 +- frameworks/native/rdb/mock/include/rdb_store_manager.h | 2 +- frameworks/native/rdb/src/rdb_helper.cpp | 2 +- frameworks/native/rdb/src/rdb_store_impl.cpp | 10 +++++----- frameworks/native/rdb/src/rdb_store_manager.cpp | 5 +++-- 5 files changed, 11 insertions(+), 10 deletions(-) diff --git a/frameworks/native/rdb/include/rdb_store_manager.h b/frameworks/native/rdb/include/rdb_store_manager.h index 9e0fdd0a5..6204943aa 100644 --- a/frameworks/native/rdb/include/rdb_store_manager.h +++ b/frameworks/native/rdb/include/rdb_store_manager.h @@ -34,7 +34,7 @@ public: std::shared_ptr GetRdbStore(const RdbStoreConfig &config, int &errCode, int version, RdbOpenCallback &openCallback); void Clear(); - bool IsInUsing(const std::string &path); + bool Remove(const std::string &path); int SetSecurityLabel(const RdbStoreConfig &config); private: diff --git a/frameworks/native/rdb/mock/include/rdb_store_manager.h b/frameworks/native/rdb/mock/include/rdb_store_manager.h index 9e0fdd0a5..6204943aa 100644 --- a/frameworks/native/rdb/mock/include/rdb_store_manager.h +++ b/frameworks/native/rdb/mock/include/rdb_store_manager.h @@ -34,7 +34,7 @@ public: std::shared_ptr GetRdbStore(const RdbStoreConfig &config, int &errCode, int version, RdbOpenCallback &openCallback); void Clear(); - bool IsInUsing(const std::string &path); + bool Remove(const std::string &path); int SetSecurityLabel(const RdbStoreConfig &config); private: diff --git a/frameworks/native/rdb/src/rdb_helper.cpp b/frameworks/native/rdb/src/rdb_helper.cpp index 8609a9f95..c2daf6832 100644 --- a/frameworks/native/rdb/src/rdb_helper.cpp +++ b/frameworks/native/rdb/src/rdb_helper.cpp @@ -60,7 +60,7 @@ int RdbHelper::DeleteRdbStore(const std::string &dbFileName) if (dbFileName.empty()) { return E_EMPTY_FILE_NAME; } - RdbStoreManager::GetInstance().IsInUsing(dbFileName); // maybe need to return here + RdbStoreManager::GetInstance().Remove(dbFileName); // maybe need to return here if (access(dbFileName.c_str(), F_OK) != 0) { return E_OK; // not not exist } diff --git a/frameworks/native/rdb/src/rdb_store_impl.cpp b/frameworks/native/rdb/src/rdb_store_impl.cpp index 49a30cab5..b24e27694 100644 --- a/frameworks/native/rdb/src/rdb_store_impl.cpp +++ b/frameworks/native/rdb/src/rdb_store_impl.cpp @@ -616,6 +616,11 @@ int RdbStoreImpl::GetDataBasePath(const std::string &databasePath, std::string & backupFilePath = databasePath; } + if (backupFilePath == path) { + LOG_ERROR("The backupPath and path should not be same."); + return E_INVALID_FILE_PATH; + } + LOG_INFO("databasePath is %{public}s.", SqliteUtils::Anonymous(backupFilePath).c_str()); return E_OK; } @@ -1167,11 +1172,6 @@ int RdbStoreImpl::Restore(const std::string backupPath, const std::vectorChangeDbFileForRestore(path, backupFilePath, newKey); } diff --git a/frameworks/native/rdb/src/rdb_store_manager.cpp b/frameworks/native/rdb/src/rdb_store_manager.cpp index ed680ee57..f0384f679 100644 --- a/frameworks/native/rdb/src/rdb_store_manager.cpp +++ b/frameworks/native/rdb/src/rdb_store_manager.cpp @@ -100,16 +100,17 @@ void RdbStoreManager::Clear() storeCache_.clear(); } -bool RdbStoreManager::IsInUsing(const std::string &path) +bool RdbStoreManager::Remove(const std::string &path) { std::lock_guard lock(mutex_); if (storeCache_.find(path) != storeCache_.end()) { if (storeCache_[path].lock()) { LOG_INFO("store in use by %{public}ld holders", storeCache_[path].lock().use_count()); - return true; } storeCache_.erase(path); // clean invalid store ptr + return true; } + return false; } -- Gitee