From ec60500d65e8fc266c7e080d5e8ed03ef7f786f2 Mon Sep 17 00:00:00 2001 From: Sangyoon Jang Date: Wed, 4 Jan 2017 20:50:04 +0900 Subject: [PATCH] Fix wgt lib to extract manifest and icon only Extracting whole files can cause memory issue. Instead of extracting whole files, wgt lib will extract manifest first and find icon file from manifest, and then extract icon file. Change-Id: I2b7a5c1039dc94411e68c7bdffb61d139aa43ef9 Signed-off-by: Sangyoon Jang --- src/lib/wgt_archive_info.cc | 34 +++++++++++++++++++--------------- 1 file changed, 19 insertions(+), 15 deletions(-) diff --git a/src/lib/wgt_archive_info.cc b/src/lib/wgt_archive_info.cc index aeed341..d30577c 100644 --- a/src/lib/wgt_archive_info.cc +++ b/src/lib/wgt_archive_info.cc @@ -29,9 +29,11 @@ namespace ci = common_installer; namespace { const char kVconfLanguageKey[] = "db/menu_widget/language"; +const char kConfigFileName[] = "config.xml"; -bool ExtractPackageArchive(const char* file_path, const bf::path& tmp_dir) { - if (!ci::ExtractToTmpDir(file_path, tmp_dir)) { +bool ExtractPackageArchive(const char* file_path, const char* file, + const bf::path& tmp_dir) { + if (!ci::ExtractToTmpDir(file_path, tmp_dir, file)) { LOG(ERROR) << "Failed to extract"; return false; } @@ -133,11 +135,7 @@ bool GetDescriptionInfo(const wgt::parse::WidgetConfigParser& parser, bool ReadIcon(const bf::path& icon, const bf::path& tmp_dir, package_manager_pkg_detail_info_t* info) { - bf::path icon_path; - if (icon.is_absolute()) - icon_path = icon; - else - icon_path = tmp_dir / icon; + bf::path icon_path = tmp_dir / icon; LOG(INFO) << "Icon file path: " << icon_path; @@ -161,15 +159,14 @@ bool ReadIcon(const bf::path& icon, const bf::path& tmp_dir, return true; } -bool GetIconInfo(const wgt::parse::WidgetConfigParser& parser, - const bf::path& tmp_dir, package_manager_pkg_detail_info_t* info) { +std::string GetIconInfo(const wgt::parse::WidgetConfigParser& parser) { auto icons_info = std::static_pointer_cast( parser.GetManifestData(wgt::parse::ApplicationIconsInfo::Key())); if (!icons_info) - return false; + return {}; - return ReadIcon(icons_info->icons().front().path(), tmp_dir, info); + return std::string(icons_info->icons().front().path()); } } // namespace @@ -180,11 +177,11 @@ bool WgtArchiveInfo::GetArchiveInfo(const char* file_path, if (!ci::CreateDir(tmp_dir)) return false; LOG(DEBUG) << "Unpack at temporary dir: " << tmp_dir; - if (!ExtractPackageArchive(file_path, tmp_dir)) + if (!ExtractPackageArchive(file_path, kConfigFileName, tmp_dir)) return false; wgt::parse::WidgetConfigParser parser; - bf::path manifest_path = tmp_dir / "config.xml"; + bf::path manifest_path = tmp_dir / kConfigFileName; if (!parser.ParseManifest(manifest_path)) { LOG(ERROR) << "Failed to parse"; bf::remove_all(tmp_dir); @@ -198,8 +195,15 @@ bool WgtArchiveInfo::GetArchiveInfo(const char* file_path, } if (!GetPrivilegesInfo(parser, info)) LOG(WARNING) << "Failed to get privileges info"; - if (!GetIconInfo(parser, tmp_dir, info)) - LOG(WARNING) << "Failed to get icon info"; + std::string icon = GetIconInfo(parser); + if (!icon.empty()) { + if (!ExtractPackageArchive(file_path, icon.c_str(), tmp_dir)) + return false; + if (!ReadIcon(icon, tmp_dir, info)) { + LOG(WARNING) << "Failed to get icon info"; + return false; + } + } char* locale = vconf_get_str(kVconfLanguageKey); if (!GetLabelInfo(parser, locale, info)) -- 2.7.4