#include <vector>
+#include "cache_flag.hh"
#include "db_handle_provider.hh"
#include "utils/logging.hh"
namespace pkgmgr_server {
namespace database {
-PkgSetDBHandler::PkgSetDBHandler(uid_t uid, int pid)
- : AbstractDBHandler(uid, pid), uid_(uid) {}
+PkgSetDBHandler::PkgSetDBHandler(uid_t uid, int pid, bool is_offline)
+ : AbstractDBHandler(uid, pid), uid_(uid), is_offline_(is_offline) {}
PkgSetDBHandler::~PkgSetDBHandler() {}
package_ = package;
}
-void PkgSetDBHandler::SetPkgID(std::string pkgid) {
- pkgid = std::move(pkgid);
-}
-
void PkgSetDBHandler::SetWriteType(pkgmgr_common::PkgWriteType write_type) {
write_type_ = write_type;
}
}
int PkgSetDBHandler::Execute() {
- std::unique_lock<std::shared_timed_mutex> u(lock_);
+ std::unique_lock<std::shared_mutex> u(lock_);
SetOpType(pkgmgr_common::DBOperationType::OPERATION_TYPE_WRITE);
SetDBType(pkgmgr_common::DBType::DB_TYPE_FILE_PKGDB);
if (!Connect())
return PMINFO_R_ERROR;
- DBHandleProvider::GetInst(uid_).SetMemoryMode(GetPID());
- std::vector<std::pair<sqlite3*, uid_t>> conn_list = GetConnection();
- sqlite3* conn = conn_list.front().first;
+ const auto& db = GetConnection().front().first;
int ret = 0;
- if (write_type_ == pkgmgr_common::PkgWriteType::Insert)
- ret = pkgmgr_parser_insert_pkg_info(conn, package_, uid_);
- else if (write_type_ == pkgmgr_common::PkgWriteType::Update)
- ret = pkgmgr_parser_update_pkg_info(conn, package_, uid_);
- else if (write_type_ == pkgmgr_common::PkgWriteType::Delete)
- ret = pkgmgr_parser_delete_pkg_info(conn, package_->package, uid_);
- else
+
+ if (write_type_ == pkgmgr_common::PkgWriteType::Insert) {
+ ret = pkgmgr_server::internal::InsertPkgInfo(db, package_, uid_);
+ } else if (write_type_ == pkgmgr_common::PkgWriteType::Update) {
+ ret = pkgmgr_server::internal::UpdatePkgInfo(db, package_, uid_);
+ } else if (write_type_ == pkgmgr_common::PkgWriteType::Delete) {
+ ret = pkgmgr_server::internal::DeletePkgInfo(db, package_->package, uid_);
+ } else {
LOG(ERROR) << "Unknown db write type";
+ return PMINFO_R_ERROR;
+ }
- if (ret != PM_PARSER_R_OK)
+ if (is_offline_ || ret != PMINFO_R_OK)
return ret;
+ auto lock = CacheFlag::GetWriterLock();
+ if (CacheFlag::GetStatus() == CacheFlag::Status::PREPARED) {
+ DBHandleProvider::GetInst(uid_).RegisterPendingPackageInfo(db,
+ package_, GetPID(), uid_, GetLocale(), write_type_);
+ }
+
return ret;
}