#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() {}
}
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());
+ if (!is_offline_)
+ DBHandleProvider::GetInst(uid_).SetMemoryMode(GetPID());
+
std::vector<std::pair<sqlite3*, uid_t>> conn_list = GetConnection();
sqlite3* conn = conn_list.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)
else
LOG(ERROR) << "Unknown db write type";
- 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(package_);
+
return ret;
}