const char kMemoryDBPrefix[] = "file:memdb_";
const char kMemoryDBPostFix[] = "?mode=memory&cache=shared";
-uid_t ConvertUID(uid_t uid) {
- if (uid < REGULAR_USER)
- return tzplatform_getuid(TZ_SYS_GLOBALAPP_USER);
- else
- return uid;
-}
-
#define BUSY_WAITING_USEC (1000000 / 10 / 2) /* 0.05 sec */
#define BUSY_WAITING_MAX 100 /* wait for max 5 sec */
std::string db_path = GetDBPath();
int ret = 0;
if (op_type_ == OPERATION_TYPE_READ)
- ret = __open_read_db(db_path.c_str(), &db_, SQLITE_OPEN_READONLY);
+ ret = __open_read_db(db_path.c_str(), &db_, SQLITE_OPEN_READONLY |
+ SQLITE_OPEN_URI);
else
ret = __open_write_db(uid_, db_path.c_str(), &db_,
SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE);
* limitations under the License.
*/
+#include <tzplatform_config.h>
+
#include "db_handle_provider.hh"
#include "pkgmgr-info.h"
#include "pkgmgrinfo_debug.h"
#endif
#define LOG_TAG "PKGMGR_INFO"
+namespace {
+
+constexpr uid_t REGULAR_USER = 5000;
+
+uid_t ConvertUID(uid_t uid) {
+ if (uid < REGULAR_USER)
+ return tzplatform_getuid(TZ_SYS_GLOBALAPP_USER);
+ else
+ return uid;
+}
+
+} // namespace
+
namespace pkgmgr_common {
-std::unordered_map<uid_t, std::unique_ptr<DBHandleProvider>> DBHandleProvider::provider_;
+std::unordered_map<uid_t, std::unique_ptr<DBHandleProvider>>
+ DBHandleProvider::provider_;
bool DBHandleProvider::is_memory_ = false;
DBHandleProvider::DBHandleProvider(uid_t uid) : uid_(uid),
DBHandleProvider& DBHandleProvider::GetInst(uid_t uid) {
static std::mutex singleton_lock;
std::unique_lock<std::mutex> u(singleton_lock);
+ uid = ConvertUID(uid);
auto& prov = provider_[uid];
if (prov == nullptr) {
prov.reset(new DBHandleProvider(uid));
const std::string& memorydb_path) {
sqlite3* memorydb = nullptr;
sqlite3* filedb = nullptr;
-
- if (sqlite3_open_v2(memorydb_path.c_str(), &memorydb,
- SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE, NULL) != SQLITE_OK) {
- LOGE("Failed to open memory DB");
+ int ret = sqlite3_open_v2(memorydb_path.c_str(), &memorydb,
+ SQLITE_OPEN_READONLY | SQLITE_OPEN_URI, nullptr);
+ if (ret != SQLITE_OK) {
+ LOGE("Failed to open memory DB %d(%s)", ret, memorydb_path.c_str());
return nullptr;
}
- if (sqlite3_open_v2(filedb_path.c_str(), &filedb,
- SQLITE_OPEN_READONLY, NULL) != SQLITE_OK) {
- LOGE("Failed to open file DB");
+ ret = sqlite3_open_v2(filedb_path.c_str(), &filedb,
+ SQLITE_OPEN_READONLY, nullptr);
+ if (ret != SQLITE_OK) {
+ LOGE("Failed to open file DB %d(%s)", ret, filedb_path.c_str());
sqlite3_close_v2(memorydb);
return nullptr;
}
sqlite3_backup_step(backup, -1);
sqlite3_backup_finish(backup);
- LOGD("Set memory DB");
+ LOGD("Set memory DB(%s)", memorydb_path.c_str());
sqlite3_close_v2(filedb);
return memorydb;
}