From 8f42dc6feba68a1cede1d7f5a6aa12ce1f30c787 Mon Sep 17 00:00:00 2001 From: Kyungwook Tak Date: Mon, 23 May 2016 17:00:10 +0900 Subject: [PATCH] Check pkg id by pkgmgr-info API additionally Change-Id: I614e244da92bc68d38c5719dfac8f8959a672ffe Signed-off-by: Kyungwook Tak --- packaging/csr-framework.spec | 1 + src/CMakeLists.txt | 1 + src/framework/service/file-system.cpp | 61 ++++++++++++++++++++++++++++++----- 3 files changed, 55 insertions(+), 8 deletions(-) diff --git a/packaging/csr-framework.spec b/packaging/csr-framework.spec index 85c40d2..a520315 100644 --- a/packaging/csr-framework.spec +++ b/packaging/csr-framework.spec @@ -13,6 +13,7 @@ BuildRequires: pkgconfig(vconf) BuildRequires: pkgconfig(elementary) BuildRequires: pkgconfig(sqlite3) BuildRequires: pkgconfig(pkgmgr) +BuildRequires: pkgconfig(pkgmgr-info) BuildRequires: pkgconfig(libsmack) Requires: lib%{name}-common = %{version}-%{release} %{?systemd_requires} diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 0a09e47..a2fbedc 100755 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -23,6 +23,7 @@ PKG_CHECK_MODULES(${TARGET_CSR_SERVER}_DEP libsystemd-daemon sqlite3 pkgmgr + pkgmgr-info libsmack ) diff --git a/src/framework/service/file-system.cpp b/src/framework/service/file-system.cpp index e3c7c55..54bdbe3 100644 --- a/src/framework/service/file-system.cpp +++ b/src/framework/service/file-system.cpp @@ -33,6 +33,8 @@ #include "service/app-deleter.h" #include "service/fs-utils.h" +#include + namespace Csr { namespace { @@ -56,12 +58,28 @@ std::vector g_regexprs{ //makeRegexpr("^(/sdcard/apps/([^/]+)/apps_rw/([^/]+))") // /sdcard/apps/{user}/apps_rw/{pkgid}/ }; +bool isInPackageList(const std::string &pkgid) +{ + if (pkgid.empty()) + return false; + + bool isPackage = false; + pkgmgrinfo_pkginfo_h handle; + auto ret = ::pkgmgrinfo_pkginfo_get_pkginfo(pkgid.c_str(), &handle); + if (ret == PMINFO_R_OK) { + isPackage = true; + ::pkgmgrinfo_pkginfo_destroy_pkginfo(handle); + } + + return isPackage; +} + } // namespace anonymous bool hasPermToRemove(const std::string &filepath) { auto parent = filepath.substr(0, filepath.find_last_of('/')); - return access(parent.c_str(), W_OK) == 0; + return ::access(parent.c_str(), W_OK) == 0; } bool File::isInApp(const std::string &path) @@ -69,7 +87,19 @@ bool File::isInApp(const std::string &path) std::smatch matched; for (const auto ®e : g_regexprs) { - if (std::regex_search(path, matched, rege)) + if (!std::regex_search(path, matched, rege)) + continue; + + std::string pkgId; + + if (matched.size() == 3) + pkgId = matched[2]; + else if (matched.size() == 4) + pkgId = matched[3]; + else + continue; + + if (isInPackageList(pkgId)) return true; } @@ -84,16 +114,28 @@ std::string File::getPkgPath(const std::string &path) if (!std::regex_search(path, matched, rege)) continue; - if (matched.size() == 3) - return matched[1]; - else if (matched.size() == 4) - return matched[1]; + std::string pkgPath; + std::string pkgId; + + if (matched.size() == 3) { + pkgPath = matched[1]; + pkgId = matched[2]; + } else if (matched.size() == 4) { + pkgPath = matched[1]; + pkgId = matched[3]; + } else { + continue; + } + + if (isInPackageList(pkgId)) + return pkgPath; } return path; } -File::File(const std::string &fpath, bool isDir) : m_path(fpath), m_inApp(false), m_isDir(isDir) +File::File(const std::string &fpath, bool isDir) : + m_path(fpath), m_inApp(false), m_isDir(isDir) { std::smatch matched; @@ -112,7 +154,10 @@ File::File(const std::string &fpath, bool isDir) : m_path(fpath), m_inApp(false) continue; } - m_inApp = true; + if (isInPackageList(m_appPkgId)) { + m_inApp = true; + return; + } } } -- 2.7.4