#include <fcntl.h>
#include <glib.h>
+#include <sys/stat.h>
#include <sys/types.h>
#include <tzplatform_config.h>
return uid;
}
+bool GetModifiedTime(const char* dbpath, timespec* t) {
+ if (dbpath == nullptr || t == nullptr) {
+ LOG(ERROR) << "Invalid argument";
+ return false;
+ }
+
+ struct stat attr;
+ if (stat(dbpath, &attr)) {
+ LOG(ERROR) << "Fail to get status from file "
+ << dbpath << " errno : " << errno;
+ return false;
+ }
+
+ *t = attr.st_mtim;
+
+ return true;
+}
+
static const std::string global_parser_memdb_path =
"file:parserdb?mode=memory&cache=shared";
is_user_memdb_set_ = false;
is_global_memdb_set_ = false;
- auto lock = CacheFlag::GetWriterLock();
- CacheFlag::SetStatus(CacheFlag::Status::PREPARING);
+ TrimCache();
- pkg_map_.clear();
- app_map_.clear();
- CacheFlag::SetStatus(CacheFlag::Status::UNPREPARED);
LOG(DEBUG) << "Set Memory mode : File";
}
return PMINFO_R_ERROR;
}
- auto tmp_filter = reinterpret_cast<pkgmgrinfo_filter_x*>(
- calloc(1, sizeof(pkgmgrinfo_filter_x)));
- if (tmp_filter == nullptr) {
- LOG(ERROR) << "Out of memory";
- g_hash_table_destroy(list);
- return PMINFO_R_ERROR;
+ const char* dbpath = sqlite3_db_filename(db, "main");
+ bool is_inmemory_db = false;
+ if (dbpath == nullptr || strlen(dbpath) == 0) {
+ LOG(INFO) << "database is inmemory db";
+ is_inmemory_db = true;
}
- int ret = pkginfo_internal_filter_get_list(db, tmp_filter, uid_,
+ timespec start_time = { 0, };
+ timespec end_time = { 0, };
+ if (!is_inmemory_db && !GetModifiedTime(dbpath, &start_time))
+ return PMINFO_R_ERROR;
+
+ pkgmgrinfo_filter_x tmp_filter = { 0, };
+ int ret = pkginfo_internal_filter_get_list(db, &tmp_filter, uid_,
locale.c_str(), list);
if (ret == PMINFO_R_OK) {
GHashTableIter iter;
}
g_hash_table_destroy(list);
- if (ret == PMINFO_R_ERROR) {
- free(tmp_filter);
+ if (ret == PMINFO_R_ERROR)
return ret;
+
+ if (!is_inmemory_db && !GetModifiedTime(dbpath, &end_time))
+ return PMINFO_R_ERROR;
+
+ if (start_time.tv_sec != end_time.tv_sec ||
+ start_time.tv_nsec != end_time.tv_nsec) {
+ LOG(ERROR) << "Database(" << dbpath << ") modification was detected";
+ return PMINFO_R_ERROR;
}
std::vector<std::shared_ptr<application_x>> app_list;
ret = pkgmgr_server::internal::appinfo_internal_filter_get_list(db,
- tmp_filter, uid_, uid, locale.c_str(), app_list);
- free(tmp_filter);
+ &tmp_filter, uid_, uid, locale.c_str(), app_list);
+
+ if (!is_inmemory_db && !GetModifiedTime(dbpath, &end_time))
+ return PMINFO_R_ERROR;
+
+ if (start_time.tv_sec != end_time.tv_sec ||
+ start_time.tv_nsec != end_time.tv_nsec) {
+ LOG(ERROR) << "Database(" << dbpath << ") modification was detected";
+ return PMINFO_R_ERROR;
+ }
+
if (ret == PMINFO_R_OK) {
for (auto& app : app_list) {
+ if (pkg_map_.find(app->package) == pkg_map_.end()) {
+ LOG(ERROR) << "Can not find package from pkg_map";
+ return PMINFO_R_ERROR;
+ }
+
app->privileges = pkg_map_[app->package].front()->privileges;
std::string appid = app->appid;
AddApplication(std::move(appid), std::move(app));
}
}
+
released_ = false;
return ret;