diff --git a/frameworks/native/rdb/include/rdb_store_manager.h b/frameworks/native/rdb/include/rdb_store_manager.h index 9e0fdd0a5c9628ab54b4ec612813041ed6ab47b2..6204943aa618f672b4b5f56b8998aaff3a85f8e1 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 9e0fdd0a5c9628ab54b4ec612813041ed6ab47b2..6204943aa618f672b4b5f56b8998aaff3a85f8e1 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 8609a9f95d95fb9cd61c36e1fc450857dd874f4d..c2daf6832f1470e338b1a2dbb1a5dc97f439573a 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 49a30cab551032e619ad4a4d0ec5dc4ff68b0fa8..b24e27694f434f0488b950d587a68bacc2a1ff1c 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 ed680ee579576cbc80dab0e5434562ba12c2b6cc..f0384f6797ee897401738cc3329b03bedf7f5bbc 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; }