From: Tomasz Iwanek Date: Mon, 14 Dec 2015 15:19:55 +0000 (+0100) Subject: Remove tpk and wgt backend code X-Git-Tag: accepted/tizen/mobile/20151219.044136^0 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=3d4f35d407b05cb1bf750d00715efd00e2ec6d06;p=platform%2Fcore%2Fappfw%2Fapp-installers.git Remove tpk and wgt backend code Source code is being transfered to separate git repositories. This repository will export devel package for those backends. Requires to be submitted together with commits moving source code of backends to repositories: - platform/appfw/wgt-backend, - platform/appfw/tpk-backend. Submit with: - https://review.tizen.org/gerrit/#/c/54291/, - https://review.tizen.org/gerrit/#/c/54886/. Change-Id: I7a4ba6f6dd732418ae896130010d22c99ceb8e30 --- diff --git a/CMakeLists.txt b/CMakeLists.txt index e0e9f61..72edc95 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -23,10 +23,6 @@ SET(CMAKE_CXX_FLAGS_CCOV "-O0 -std=c++11 -g --coverage") # Targets SET(TARGET_LIBNAME_COMMON "app-installers") -SET(TARGET_LIBNAME_WGT "wgt-installer") -SET(TARGET_LIBNAME_TPK "tpk-installer") -SET(TARGET_WGT_BACKEND "wgt-backend") -SET(TARGET_TPK_BACKEND "tpk-backend") SET(TARGET_PKGDIR_TOOL "pkgdir-tool") ADD_DEFINITIONS("-Wall") @@ -45,16 +41,13 @@ PKG_CHECK_MODULES(MINIZIP_DEPS REQUIRED minizip) PKG_CHECK_MODULES(ZLIB_DEPS REQUIRED zlib) PKG_CHECK_MODULES(TZPLATFORM_CONFIG_DEPS REQUIRED libtzplatform-config) PKG_CHECK_MODULES(SECURITY_MANAGER_DEPS REQUIRED security-manager) -PKG_CHECK_MODULES(MANIFEST_PARSER_DEPS REQUIRED manifest-parser) -PKG_CHECK_MODULES(MANIFEST_HANDLERS_DEPS REQUIRED manifest-handlers) PKG_CHECK_MODULES(DELTA_MANIFEST_HANDLERS_DEPS REQUIRED delta-manifest-handlers) -PKG_CHECK_MODULES(TPK_MANIFEST_HANDLERS_DEPS REQUIRED tpk-manifest-handlers) -PKG_CHECK_MODULES(CERT_SVC_DEPS_VCORE REQUIRED cert-svc-vcore) +PKG_CHECK_MODULES(MANIFEST_PARSER_UTILS_DEPS REQUIRED manifest-parser-utils) +PKG_CHECK_MODULES(CERT_SVC_DEPS_VCORE_DEPS REQUIRED cert-svc-vcore) PKG_CHECK_MODULES(PKGMGR_PARSER_DEPS REQUIRED pkgmgr-parser) PKG_CHECK_MODULES(PKGMGR_INFO_DEPS REQUIRED pkgmgr-info) PKG_CHECK_MODULES(LIBXML_DEPS REQUIRED libxml-2.0) PKG_CHECK_MODULES(PRIVILEGE_CHECKER_DEPS REQUIRED capi-security-privilege-manager) -PKG_CHECK_MODULES(ENCRYPTION_DEPS REQUIRED libwebappenc) PKG_CHECK_MODULES(APPMANAGER_DEPS REQUIRED capi-appfw-app-manager) FIND_PACKAGE(Boost REQUIRED COMPONENTS system filesystem regex program_options) diff --git a/packaging/app-installers.spec b/packaging/app-installers.spec index 19b6f81..0fc9088 100644 --- a/packaging/app-installers.spec +++ b/packaging/app-installers.spec @@ -9,9 +9,7 @@ Group: Application Framework/Package Management License: Apache-2.0 Source0: %{name}-%{version}.tar.gz Source1000: app-installers.manifest -Source1001: wgt-backend.manifest -Source1002: tpk-backend.manifest -Source1003: app-installers-tests.manifest +Source1001: app-installers-tests.manifest BuildRequires: boost-devel BuildRequires: cmake @@ -29,34 +27,19 @@ BuildRequires: pkgconfig(minizip) BuildRequires: pkgconfig(libzip) BuildRequires: pkgconfig(libtzplatform-config) BuildRequires: pkgconfig(cert-svc-vcore) -BuildRequires: pkgconfig(manifest-parser) -BuildRequires: pkgconfig(manifest-handlers) +BuildRequires: pkgconfig(manifest-parser-utils) BuildRequires: pkgconfig(delta-manifest-handlers) BuildRequires: pkgconfig(capi-security-privilege-manager) -BuildRequires: pkgconfig(libwebappenc) BuildRequires: pkgconfig(capi-appfw-app-manager) Requires: ca-certificates-tizen Requires: libtzplatform-config Requires: xdelta3 - %description This is a meta package that installs the common application installers of Tizen. -%package -n wgt-backend -Summary: Backend of WGT files - -%description -n wgt-backend -Backend for standard widget files WGT - -%package -n tpk-backend -Summary: Backend of TPK files - -%description -n tpk-backend -Backend for tizen package files - %package devel Summary: App-installers development files Group: Application Framework/Package Management @@ -77,25 +60,14 @@ Unit tests for al modules of app-installers cp %{SOURCE1000} . cp %{SOURCE1001} . -cp %{SOURCE1002} . -cp %{SOURCE1003} . %build -#Variable for setting symlink to runtime -runtime_path=%{_bindir}/xwalk-launcher -%if "%{profile}" == "mobile" || "%{profile}" == "wearable" || "%{profile}" == "tv" -runtime_path=%{_bindir}/wrt -%endif -%cmake . -DCMAKE_BUILD_TYPE=%{?build_type:%build_type} -DWRT_LAUNCHER=${runtime_path} +%cmake . -DCMAKE_BUILD_TYPE=%{?build_type:%build_type} make %{?_smp_mflags} %install %make_install -mkdir -p %{buildroot}/etc/package-manager/backend -ln -s %{_bindir}/wgt-backend %{buildroot}%{_sysconfdir}/package-manager/backend/wgt -ln -s %{_bindir}/tpk-backend %{buildroot}%{_sysconfdir}/package-manager/backend/tpk - %post ln -sf %{_bindir}/pkgdir-tool %{_bindir}/pkgdir_maker @@ -110,16 +82,6 @@ ln -sf %{_bindir}/pkgdir-tool %{_bindir}/pkgdir_maker %attr(6750,root,users) %{_bindir}/pkgdir-tool %license LICENSE -%files -n wgt-backend -%manifest wgt-backend.manifest -%{_sysconfdir}/package-manager/backend/wgt -%{_bindir}/wgt-backend - -%files -n tpk-backend -%{_sysconfdir}/package-manager/backend/tpk -%manifest tpk-backend.manifest -%{_bindir}/tpk-backend - %files devel %{_includedir}/app-installers/common/*.h %{_includedir}/app-installers/common/*/*.h diff --git a/packaging/tpk-backend.manifest b/packaging/tpk-backend.manifest deleted file mode 100644 index 925f49b..0000000 --- a/packaging/tpk-backend.manifest +++ /dev/null @@ -1,8 +0,0 @@ - - - - - - - - diff --git a/packaging/wgt-backend.manifest b/packaging/wgt-backend.manifest deleted file mode 100644 index 55125da..0000000 --- a/packaging/wgt-backend.manifest +++ /dev/null @@ -1,8 +0,0 @@ - - - - - - - - diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index b8d7337..d1a2d79 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -1,5 +1,3 @@ ADD_SUBDIRECTORY(common) -ADD_SUBDIRECTORY(wgt) -ADD_SUBDIRECTORY(tpk) ADD_SUBDIRECTORY(pkgdir_tool) ADD_SUBDIRECTORY(unit_tests) diff --git a/src/common/CMakeLists.txt b/src/common/CMakeLists.txt index 4a15a29..94cac15 100644 --- a/src/common/CMakeLists.txt +++ b/src/common/CMakeLists.txt @@ -60,10 +60,11 @@ APPLY_PKG_CONFIG(${TARGET_LIBNAME_COMMON} PUBLIC PKGMGR_INFO_DEPS PKGMGR_PARSER_DEPS PKGMGR_INSTALLER_DEPS + MANIFEST_PARSER_UTILS_DEPS SECURITY_MANAGER_DEPS TZPLATFORM_CONFIG_DEPS LIBXML_DEPS - CERT_SVC_DEPS_VCORE + CERT_SVC_DEPS_VCORE_DEPS MINIZIP_DEPS ZLIB_DEPS PRIVILEGE_CHECKER_DEPS diff --git a/src/common/app-installers.pc.in b/src/common/app-installers.pc.in index 0d1f585..2949579 100644 --- a/src/common/app-installers.pc.in +++ b/src/common/app-installers.pc.in @@ -6,6 +6,6 @@ includedir=@INCLUDEDIR@ Name: app-installers Description: Common library for pkgmgr backends Version: @VERSION@ -Requires: pkgmgr pkgmgr-installer minizip zlib libtzplatform-config security-manager manifest-parser manifest-handlers delta-manifest-handlers tpk-manifest-handlers cert-svc-vcore pkgmgr-parser pkgmgr-info libxml-2.0 capi-security-privilege-manager libwebappenc capi-appfw-app-manager +Requires: pkgmgr pkgmgr-installer minizip zlib libtzplatform-config security-manager manifest-parser-utils delta-manifest-handlers cert-svc-vcore pkgmgr-parser pkgmgr-info libxml-2.0 capi-security-privilege-manager capi-appfw-app-manager Libs: -L${libdir} -lapp-installers Cflags: -I${includedir}/app-installers/ diff --git a/src/tpk/CMakeLists.txt b/src/tpk/CMakeLists.txt deleted file mode 100644 index 7301962..0000000 --- a/src/tpk/CMakeLists.txt +++ /dev/null @@ -1,25 +0,0 @@ -SET(SRCS - step/step_check_tpk_background_category.cc - step/step_create_symbolic_link.cc - step/step_parse.cc - step/step_parse_recovery.cc - step/step_convert_xml.cc - tpk_app_query_interface.cc - tpk_installer.cc -) -ADD_LIBRARY(${TARGET_LIBNAME_TPK} STATIC ${SRCS}) -ADD_EXECUTABLE(${TARGET_TPK_BACKEND} "tpk_backend.cc") - -TARGET_INCLUDE_DIRECTORIES(${TARGET_LIBNAME_TPK} PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/../") -TARGET_INCLUDE_DIRECTORIES(${TARGET_TPK_BACKEND} PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/../") - -APPLY_PKG_CONFIG(${TARGET_LIBNAME_TPK} - PUBLIC PKGMGR_DEPS - TPK_MANIFEST_HANDLERS_DEPS - MANIFEST_PARSER_DEPS - Boost -) -TARGET_LINK_LIBRARIES(${TARGET_LIBNAME_TPK} PUBLIC ${TARGET_LIBNAME_COMMON}) -TARGET_LINK_LIBRARIES(${TARGET_TPK_BACKEND} PRIVATE ${TARGET_LIBNAME_TPK}) - -INSTALL(TARGETS ${TARGET_TPK_BACKEND} DESTINATION ${BINDIR}) diff --git a/src/tpk/step/step_check_tpk_background_category.cc b/src/tpk/step/step_check_tpk_background_category.cc deleted file mode 100644 index cd2a30c..0000000 --- a/src/tpk/step/step_check_tpk_background_category.cc +++ /dev/null @@ -1,24 +0,0 @@ -// Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved -// Use of this source code is governed by a apache 2.0 license that can be -// found in the LICENSE file. - -#include "common/installer_context.h" -#include "tpk/step/step_check_tpk_background_category.h" - -namespace { -namespace ci_sec = common_installer::security; -} // namespace - -namespace tpk { -namespace security { - -StepCheckTpkBackgroundCategory::StepCheckTpkBackgroundCategory( - common_installer::InstallerContext* context) : - ci_sec::StepCheckBackgroundCategory(context) {} - -bool StepCheckTpkBackgroundCategory::GetBackgroundSupport() { - return true; -} - -} // namespace security -} // namespace tpk diff --git a/src/tpk/step/step_check_tpk_background_category.h b/src/tpk/step/step_check_tpk_background_category.h deleted file mode 100644 index d6ce75a..0000000 --- a/src/tpk/step/step_check_tpk_background_category.h +++ /dev/null @@ -1,32 +0,0 @@ -// Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved -// Use of this source code is governed by a apache 2.0 license that can be -// found in the LICENSE file. - -#ifndef TPK_STEP_STEP_CHECK_TPK_BACKGROUND_CATEGORY_H_ -#define TPK_STEP_STEP_CHECK_TPK_BACKGROUND_CATEGORY_H_ - -#include - -#include "common/step/step_check_background_category.h" - -namespace tpk { -namespace security { - -/** - * \brief This step check background category value and modify it depending on - * required version, cert level, background support, and value itself - */ -class StepCheckTpkBackgroundCategory : - public common_installer::security::StepCheckBackgroundCategory { - public: - explicit StepCheckTpkBackgroundCategory( - common_installer::InstallerContext* context); - - protected: - bool GetBackgroundSupport() override; -}; - -} // namespace security -} // namespace tpk - -#endif // TPK_STEP_STEP_CHECK_TPK_BACKGROUND_CATEGORY_H_ diff --git a/src/tpk/step/step_convert_xml.cc b/src/tpk/step/step_convert_xml.cc deleted file mode 100644 index 6051901..0000000 --- a/src/tpk/step/step_convert_xml.cc +++ /dev/null @@ -1,127 +0,0 @@ -// Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved -// Use of this source code is governed by a apache 2.0 license that can be -// found in the LICENSE file. - -#include "tpk/step/step_convert_xml.h" - -#include -#include - -#include -#include -#include -#include -#include -#include - -#include - -#include "common/utils/glist_range.h" - -namespace bs = boost::system; -namespace bf = boost::filesystem; - -namespace { - -const xmlChar kExecAttributeKey[] = "exec"; -const xmlChar kXmlNamespaceUri[] = "http://tizen.org/ns/packages"; -const char kXmlXPathAppExpr[] = - "//*[local-name()='ui-application' or local-name()='service-application' " - "or local-name()='widget-application']"; - -} // namespace - -namespace common_installer { -namespace tpk { - -Step::Status StepConvertXml::precheck() { - bf::path xml_path = context_->pkg_path.get(); - xml_path /= "tizen-manifest.xml"; - - if (!bf::exists(xml_path)) { - LOG(ERROR) << "Cannot find manifest file"; - return Step::Status::INVALID_VALUE; - } - - xml_path_ = xml_path; - - return Step::Status::OK; -} - -bool StepConvertXml::ConvertXml(xmlDocPtr doc) { - xmlXPathContextPtr xpath_ctx; - - xpath_ctx = xmlXPathNewContext(doc); - if (!xpath_ctx) { - LOG(ERROR) << "Failed to create XPath context"; - return false; - } - - for (application_x* app : - GListRange(context_->manifest_data.get()->application)) { - std::string expr; - xmlXPathObjectPtr xpath_obj; - xmlNodePtr node; - - expr = std::string(kXmlXPathAppExpr) + "[@appid='" + app->appid + "']"; - xpath_obj = xmlXPathEvalExpression((const xmlChar*)expr.c_str(), xpath_ctx); - if (!xpath_obj || !xpath_obj->nodesetval || !xpath_obj->nodesetval->nodeNr) - continue; - - node = xpath_obj->nodesetval->nodeTab[0]; - xmlSetProp(node, kExecAttributeKey, (const xmlChar*)app->exec); - xmlXPathFreeObject(xpath_obj); - } - - xmlXPathFreeContext(xpath_ctx); - - return true; -} - -Step::Status StepConvertXml::process() { - xmlDocPtr doc = xmlParseFile(xml_path_.string().c_str()); - if (!doc) { - LOG(ERROR) << "Failed to parse xml file"; - return Step::Status::ERROR; - } - - if (!ConvertXml(doc)) - return Step::Status::ERROR; - - bf::path new_path = bf::path(getUserManifestPath(context_->uid.get())) - / bf::path(context_->pkgid.get()); - new_path += ".xml"; - if (xmlSaveFile(new_path.string().c_str(), doc) == -1) { - LOG(ERROR) << "Failed to write xml file"; - return Step::Status::ERROR; - } - - context_->xml_path.set(new_path.string()); - - if (pkgmgr_parser_check_manifest_validation( - context_->xml_path.get().c_str()) != 0) { - LOG(ERROR) << "Manifest is not valid"; - return Step::Status::ERROR; - } - - LOG(DEBUG) << "Successfully create manifest xml " - << context_->xml_path.get(); - - return Step::Status::OK; -} - -Step::Status StepConvertXml::clean() { - return Step::Status::OK; -} - -Step::Status StepConvertXml::undo() { - bs::error_code error; - - if (bf::exists(context_->xml_path.get())) - bf::remove_all(context_->xml_path.get(), error); - - return Step::Status::OK; -} - -} // namespace tpk -} // namespace common_installer diff --git a/src/tpk/step/step_convert_xml.h b/src/tpk/step/step_convert_xml.h deleted file mode 100644 index 9f129fb..0000000 --- a/src/tpk/step/step_convert_xml.h +++ /dev/null @@ -1,37 +0,0 @@ -// Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved -// Use of this source code is governed by a apache 2.0 license that can be -// found in the LICENSE file. - -#ifndef TPK_STEP_STEP_CONVERT_XML_H_ -#define TPK_STEP_STEP_CONVERT_XML_H_ - -#include - -#include -#include - -#include "common/step/step.h" - -namespace common_installer { -namespace tpk { - -class StepConvertXml : public common_installer::Step { - public: - using Step::Step; - - Status process() override; - Status clean() override; - Status undo() override; - Status precheck() override; - - private: - boost::filesystem::path xml_path_; - bool ConvertXml(xmlDocPtr doc); - - SCOPE_LOG_TAG(ConvertXml) -}; - -} // namespace tpk -} // namespace common_installer - -#endif // TPK_STEP_STEP_CONVERT_XML_H_ diff --git a/src/tpk/step/step_create_symbolic_link.cc b/src/tpk/step/step_create_symbolic_link.cc deleted file mode 100644 index 8c1aab1..0000000 --- a/src/tpk/step/step_create_symbolic_link.cc +++ /dev/null @@ -1,94 +0,0 @@ -/* Copyright 2015 Samsung Electronics, license APACHE-2.0, see LICENSE file */ -#include "tpk/step/step_create_symbolic_link.h" -#include -#include -#include - -#include - -#include "common/step/step.h" -#include "common/app_installer.h" -#include "common/installer_context.h" -#include "common/utils/file_util.h" -#include "common/utils/glist_range.h" - -namespace tpk { -namespace filesystem { - -namespace bf = boost::filesystem; -using common_installer::InstallerContext; -typedef common_installer::Step::Status Status; - -namespace { - -bool CreateSymLink(application_x* app, InstallerContext* context) { - boost::system::error_code boost_error; - bf::path bindir = context->pkg_path.get() / - bf::path("bin"); - LOG(DEBUG) << "Creating dir: " << bindir; - if (!common_installer::CreateDir(bindir)) { - LOG(ERROR) << "Directory creation failure: " << bindir; - return false; - } - - // Exec path - // Make a symlink with the name of appid, pointing exec file - bf::path symlink_path = bindir / bf::path(app->appid); - LOG(DEBUG) << "Creating symlink " << symlink_path << " pointing " << - app->exec; - bf::create_symlink(bf::path(app->exec), symlink_path, boost_error); - if (boost_error) { - LOG(ERROR) << "Symlink creation failure: " << symlink_path; - return false; - } - - // Give an execution permission to the original executable - LOG(DEBUG) << "Giving exec permission to " << app->exec; - bf::permissions(bf::path(app->exec), bf::owner_all | - bf::group_read | bf::group_exe | - bf::others_read | bf::others_exe, boost_error); - if (boost_error) { - LOG(ERROR) << "Permission change failure"; - return false; - } - return true; -} - -} // namespace - -Status StepCreateSymbolicLink::precheck() { - manifest_x *m = context_->manifest_data.get(); - if (!m) { - LOG(ERROR) << "manifest_data attribute is empty"; - return Step::Status::INVALID_VALUE; - } - if (!m->application) { - LOG(ERROR) << "No application exists"; - return Step::Status::ERROR; - } - - return Step::Status::OK; -} - -Status StepCreateSymbolicLink::process() { - manifest_x* m = context_->manifest_data.get(); - for (application_x* app : GListRange(m->application)) { - if (!CreateSymLink(app, context_)) - return Status::ERROR; - } - return Status::OK; -} - - -Status StepCreateSymbolicLink::undo() { - manifest_x* m = context_->manifest_data.get(); - Step::Status ret = Status::OK; - for (application_x* app : GListRange(m->application)) { - if (!CreateSymLink(app, context_)) - ret = Status::ERROR; - } - return ret; -} - -} // namespace filesystem -} // namespace tpk diff --git a/src/tpk/step/step_create_symbolic_link.h b/src/tpk/step/step_create_symbolic_link.h deleted file mode 100644 index 0339cf7..0000000 --- a/src/tpk/step/step_create_symbolic_link.h +++ /dev/null @@ -1,26 +0,0 @@ -/* Copyright 2015 Samsung Electronics, license APACHE-2.0, see LICENSE file */ -#ifndef TPK_STEP_STEP_CREATE_SYMBOLIC_LINK_H_ -#define TPK_STEP_STEP_CREATE_SYMBOLIC_LINK_H_ - -#include - -#include "common/app_installer.h" - -namespace tpk { -namespace filesystem { - -class StepCreateSymbolicLink : public common_installer::Step { - public: - using Step::Step; - Status process() override; - Status clean() override { return Status::OK; } - Status undo() override; - Status precheck() override; - - SCOPE_LOG_TAG(SymbolicLink) -}; - -} // namespace filesystem -} // namespace tpk - -#endif // TPK_STEP_STEP_CREATE_SYMBOLIC_LINK_H_ diff --git a/src/tpk/step/step_parse.cc b/src/tpk/step/step_parse.cc deleted file mode 100644 index 4085116..0000000 --- a/src/tpk/step/step_parse.cc +++ /dev/null @@ -1,671 +0,0 @@ -// Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved -// Use of this source code is governed by an apache 2.0 license that can be -// found in the LICENSE file. - -#include "tpk/step/step_parse.h" - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include "common/app_installer.h" -#include "common/installer_context.h" -#include "common/step/step.h" -#include "common/utils/glist_range.h" - -namespace tpk { -namespace parse { - -namespace { - -namespace app_keys = tpk::application_keys; -namespace bf = boost::filesystem; - -const char kManifestFileName[] = "tizen-manifest.xml"; - -} // namepsace - -common_installer::Step::Status StepParse::precheck() { - if (context_->unpacked_dir_path.get().empty()) { - LOG(ERROR) << "unpacked_dir_path attribute is empty"; - return common_installer::Step::Status::INVALID_VALUE; - } - if (!boost::filesystem::exists(context_->unpacked_dir_path.get())) { - LOG(ERROR) << "unpacked_dir_path (" - << context_->unpacked_dir_path.get() - << ") path does not exist"; - return common_installer::Step::Status::INVALID_VALUE; - } - - boost::filesystem::path tmp; - if (!context_->xml_path.get().empty()) { - tmp = context_->xml_path.get(); - } else { - tmp = context_->unpacked_dir_path.get(); - tmp /= kManifestFileName; - } - - if (!boost::filesystem::exists(tmp)) { - LOG(ERROR) << "manifest not found from the package"; - return common_installer::Step::Status::INVALID_VALUE; - } - - return common_installer::Step::Status::OK; -} - -bool StepParse::LocateConfigFile() { - boost::filesystem::path manifest; - if (!context_->xml_path.get().empty()) { - manifest = context_->xml_path.get(); - } else { - manifest = context_->unpacked_dir_path.get(); - manifest /= kManifestFileName; - } - - LOG(DEBUG) << "manifest path: " << manifest; - - if (!boost::filesystem::exists(manifest)) - return false; - - path_ = manifest; - return true; -} - -bf::path StepParse::LocateConfigFile() const { - boost::filesystem::path path; - if (!context_->xml_path.get().empty()) { - path = context_->xml_path.get(); - } else { - path = context_->unpacked_dir_path.get(); - path /= kManifestFileName; - } - return path; -} - -bool StepParse::FillInstallationInfo(manifest_x* manifest) { - manifest->root_path = strdup( - (context_->root_application_path.get() / manifest->package).c_str()); - manifest->installed_time = - strdup(std::to_string(std::chrono::system_clock::to_time_t( - std::chrono::system_clock::now())).c_str()); - return true; -} - -bool StepParse::FillPackageInfo(manifest_x* manifest) { - std::shared_ptr pkg_info = - std::static_pointer_cast( - parser_->GetManifestData(app_keys::kManifestKey)); - if (!pkg_info) { - LOG(ERROR) << "Package info manifest data has not been found."; - return false; - } - - std::shared_ptr ui_application_list = - std::static_pointer_cast( - parser_->GetManifestData(app_keys::kUIApplicationKey)); - std::shared_ptr service_application_list = - std::static_pointer_cast( - parser_->GetManifestData(app_keys::kServiceApplicationKey)); - std::shared_ptr widget_application_list = - std::static_pointer_cast( - parser_->GetManifestData(app_keys::kWidgetApplicationKey)); - - // mandatory check - if (!ui_application_list && !service_application_list && - !widget_application_list) { - LOG(ERROR) << "UI Application or Service Application or Widget Application " - "are mandatory and has not been found."; - return false; - } - - manifest->ns = strdup(pkg_info->xmlns().c_str()); - manifest->package = strdup(pkg_info->package().c_str()); - manifest->nodisplay_setting = strdup(pkg_info->nodisplay_setting().c_str()); - manifest->type = strdup("tpk"); - manifest->appsetting = strdup("false"); - manifest->support_disable = strdup("false"); - manifest->version = strdup(pkg_info->version().c_str()); - manifest->installlocation = strdup(pkg_info->install_location().c_str()); - manifest->api_version = strdup(pkg_info->api_version().c_str()); - - for (auto& pair : pkg_info->labels()) { - label_x* label = reinterpret_cast(calloc(1, sizeof(label_x))); - if (!pair.first.empty()) - label->lang = strdup(pair.first.c_str()); - else - label->lang = strdup(DEFAULT_LOCALE); - label->name = strdup(pair.second.c_str()); - manifest->label = g_list_append(manifest->label, label); - } - - std::shared_ptr profile_info = - std::static_pointer_cast( - parser_->GetManifestData(ProfileInfo::Key())); - if (profile_info) { - for (auto& profile : profile_info->profiles()) { - manifest->deviceprofile = g_list_append(manifest->deviceprofile, - strdup(profile.c_str())); - } - } - - if (ui_application_list) { - manifest->mainapp_id = - strdup(ui_application_list->items[0].ui_info.appid().c_str()); - } else if (service_application_list) { - manifest->mainapp_id = - strdup(service_application_list->items[0].sa_info.appid().c_str()); - } else if (widget_application_list) { - manifest->mainapp_id = - strdup(widget_application_list->items[0].widget_info.appid().c_str()); - } - return true; -} - -bool StepParse::FillAuthorInfo(manifest_x* manifest) { - std::shared_ptr author_info = - std::static_pointer_cast( - parser_->GetManifestData(app_keys::kAuthorKey)); - - if (!author_info) { - LOG(ERROR) << "Author data has not been found."; - return false; - } - - author_x* author = reinterpret_cast(calloc(1, sizeof(author_x))); - author->text = strdup(author_info->name().c_str()); - author->email = strdup(author_info->email().c_str()); - author->href = strdup(author_info->href().c_str()); - author->lang = strdup(DEFAULT_LOCALE); - manifest->author = g_list_append(manifest->author, author); - return true; -} - -bool StepParse::FillDescription(manifest_x* manifest) { - std::shared_ptr description_info = - std::static_pointer_cast( - parser_->GetManifestData(app_keys::kDescriptionKey)); - - if (!description_info) { - LOG(ERROR) << "Description data has not been found."; - return false; - } - - description_x* description = reinterpret_cast - (calloc(1, sizeof(description_x))); - description->text = strdup(description_info->description().c_str()); - description->lang = !description_info->xml_lang().empty() ? - strdup(description_info->xml_lang().c_str()) : strdup(DEFAULT_LOCALE); - manifest->description = g_list_append(manifest->description, description); - return true; -} - -bool StepParse::FillPrivileges(manifest_x* manifest) { - std::shared_ptr perm_info = - std::static_pointer_cast(parser_->GetManifestData( - app_keys::kPrivilegesKey)); - if (!perm_info) - return true; - - std::set privileges = perm_info->GetPrivileges(); - for (auto& priv : privileges) { - manifest->privileges = g_list_append(manifest->privileges, - strdup(priv.c_str())); - } - return true; -} - -bool StepParse::FillWidgetApplication(manifest_x* manifest) { - std::shared_ptr widget_application_list = - std::static_pointer_cast( - parser_->GetManifestData(app_keys::kWidgetApplicationKey)); - if (!widget_application_list) - return true; - - for (const auto& application : widget_application_list->items) { - // if there is no app yet, set this app as mainapp - bool main_app = manifest->application == nullptr; - - application_x* widget_app = - static_cast(calloc(1, sizeof(application_x))); - widget_app->appid = strdup(application.widget_info.appid().c_str()); - widget_app->exec = strdup((context_->root_application_path.get() - / manifest->package / "bin" - / application.widget_info.exec()).c_str()); - widget_app->launch_mode = - strdup(application.widget_info.launch_mode().c_str()); - widget_app->multiple = strdup(application.widget_info.multiple().c_str()); - widget_app->nodisplay = - strdup(application.widget_info.nodisplay().c_str()); - widget_app->type = strdup("capp"); - widget_app->component_type = strdup("widgetapp"); - widget_app->hwacceleration = - strdup(application.widget_info.hwacceleration().c_str()); - widget_app->onboot = strdup("false"); - widget_app->autorestart = strdup("false"); - widget_app->mainapp = main_app ? strdup("true") : strdup("false"); - widget_app->enabled = strdup("true"); - widget_app->screenreader = strdup("use-system-setting"); - widget_app->recentimage = strdup("false"); - widget_app->launchcondition = strdup("false"); - widget_app->guestmode_visibility = strdup("true"); - widget_app->permission_type = strdup("normal"); - widget_app->ambient_support = strdup("false"); - widget_app->package = strdup(manifest->package); - widget_app->support_disable = strdup(manifest->support_disable); - manifest->application = g_list_append(manifest->application, widget_app); - - if (!FillApplicationIconPaths(widget_app, application.app_icons)) - return false; - if (!FillLabel(widget_app, application.label)) - return false; - if (!FillImage(widget_app, application.app_images)) - return false; - if (!FillMetadata(widget_app, application.meta_data)) - return false; - } - return true; -} - -bool StepParse::FillServiceApplication(manifest_x* manifest) { - std::shared_ptr service_application_list = - std::static_pointer_cast( - parser_->GetManifestData(app_keys::kServiceApplicationKey)); - if (!service_application_list) - return true; - - for (const auto& application : service_application_list->items) { - // if there is no app yet, set this app as mainapp - bool main_app = manifest->application == nullptr; - - application_x* service_app = - static_cast(calloc(1, sizeof(application_x))); - service_app->appid = strdup(application.sa_info.appid().c_str()); - service_app->autorestart = - strdup(application.sa_info.auto_restart().c_str()); - service_app->exec = strdup((context_->root_application_path.get() - / manifest->package / "bin" - / application.sa_info.exec()).c_str()); - service_app->onboot = strdup(application.sa_info.on_boot().c_str()); - service_app->type = strdup(application.sa_info.type().c_str()); - service_app->process_pool = - strdup(application.sa_info.process_pool().c_str()); - service_app->component_type = strdup("svcapp"); - service_app->mainapp = main_app ? strdup("true") : strdup("false"); - service_app->enabled = strdup("true"); - service_app->hwacceleration = strdup("default"); - service_app->screenreader = strdup("use-system-setting"); - service_app->recentimage = strdup("false"); - service_app->launchcondition = strdup("false"); - service_app->indicatordisplay = strdup("true"); - service_app->effectimage_type = strdup("image"); - service_app->guestmode_visibility = strdup("true"); - service_app->permission_type = strdup("normal"); - service_app->submode = strdup("false"); - service_app->process_pool = strdup("false"); - service_app->ambient_support = strdup("false"); - service_app->package = strdup(manifest->package); - service_app->support_disable = strdup(manifest->support_disable); - manifest->application = g_list_append(manifest->application, service_app); - - if (!FillAppControl(service_app, application.app_control)) - return false; - if (!FillDataControl(service_app, application.data_control)) - return false; - if (!FillApplicationIconPaths(service_app, application.app_icons)) - return false; - if (!FillLabel(service_app, application.label)) - return false; - if (!FillMetadata(service_app, application.meta_data)) - return false; - if (!FillBackgroundCategoryInfo(service_app, - application.background_category)) - return false; - } - return true; -} - -bool StepParse::FillUIApplication(manifest_x* manifest) { - std::shared_ptr ui_application_list = - std::static_pointer_cast( - parser_->GetManifestData(app_keys::kUIApplicationKey)); - if (!ui_application_list) - return true; - - for (const auto& application : ui_application_list->items) { - // if there is no app yet, set this app as mainapp - bool main_app = manifest->application == nullptr; - - application_x* ui_app = - static_cast(calloc(1, sizeof(application_x))); - ui_app->appid = strdup(application.ui_info.appid().c_str()); - ui_app->exec = strdup((context_->root_application_path.get() - / manifest->package / "bin" - / application.ui_info.exec()).c_str()); - ui_app->launch_mode = strdup(application.ui_info.launch_mode().c_str()); - ui_app->multiple = strdup(application.ui_info.multiple().c_str()); - ui_app->nodisplay = strdup(application.ui_info.nodisplay().c_str()); - ui_app->taskmanage = strdup(application.ui_info.taskmanage().c_str()); - ui_app->type = strdup(application.ui_info.type().c_str()); - ui_app->component_type = strdup("uiapp"); - ui_app->ui_gadget = strdup(application.ui_info.uigadget().c_str()); - ui_app->process_pool = strdup(application.ui_info.process_pool().c_str()); - ui_app->submode = strdup(application.ui_info.submode().c_str()); - ui_app->indicatordisplay = - strdup(application.ui_info.indicator_display().c_str()); - ui_app->effectimage_type = - strdup(application.ui_info.effectimage_type().c_str()); - ui_app->portraitimg = - strdup(application.ui_info.portrait_image().c_str()); - ui_app->landscapeimg = - strdup(application.ui_info.landscape_image().c_str()); - ui_app->submode_mainid = - strdup(application.ui_info.submode_mainid().c_str()); - ui_app->hwacceleration = - strdup(application.ui_info.hwacceleration().c_str()); - ui_app->onboot = strdup("false"); - ui_app->autorestart = strdup("false"); - ui_app->component_type = strdup("uiapp"); - ui_app->mainapp = main_app ? strdup("true") : strdup("false"); - ui_app->enabled = strdup("true"); - ui_app->screenreader = strdup("use-system-setting"); - ui_app->recentimage = strdup("false"); - ui_app->launchcondition = strdup("false"); - ui_app->guestmode_visibility = strdup("true"); - ui_app->permission_type = strdup("normal"); - ui_app->ambient_support = strdup("false"); - ui_app->package = strdup(manifest->package); - ui_app->support_disable = strdup(manifest->support_disable); - manifest->application = g_list_append(manifest->application, ui_app); - - if (!FillAppControl(ui_app, application.app_control)) - return false; - if (!FillDataControl(ui_app, application.data_control)) - return false; - if (!FillApplicationIconPaths(ui_app, application.app_icons)) - return false; - if (!FillLabel(ui_app, application.label)) - return false; - if (!FillImage(ui_app, application.app_images)) - return false; - if (!FillMetadata(ui_app, application.meta_data)) - return false; - if (!FillBackgroundCategoryInfo(ui_app, application.background_category)) - return false; - } - return true; -} - -template -bool StepParse::FillAppControl(application_x* app, const T& app_control_list) { - if (app_control_list.empty()) - return true; - - for (const auto& control : app_control_list) { - appcontrol_x* app_control = - static_cast(calloc(1, sizeof(appcontrol_x))); - app_control->operation = strdup(control.operation().c_str()); - if (!control.mime().empty()) - app_control->mime = strdup(control.mime().c_str()); - if (!control.uri().empty()) - app_control->uri = strdup(control.uri().c_str()); - app->appcontrol = g_list_append(app->appcontrol, app_control); - } - return true; -} - -template -bool StepParse::FillDataControl(application_x* app, - const T& data_control_list) { - if (data_control_list.empty()) - return true; - - for (const auto& control : data_control_list) { - datacontrol_x* data_control = - static_cast(calloc(1, sizeof(datacontrol_x))); - data_control->access = strdup(control.access().c_str()); - data_control->providerid = strdup(control.providerid().c_str()); - data_control->type = strdup(control.type().c_str()); - app->datacontrol = g_list_append(app->datacontrol, data_control); - } - return true; -} - -template -bool StepParse::FillApplicationIconPaths(application_x* app, - const T& icons_info) { - for (auto& application_icon : icons_info.icons()) { - icon_x* icon = reinterpret_cast (calloc(1, sizeof(icon_x))); - // NOTE: name is an attribute, but the xml writer uses it as text. - // This must be fixed in whole app-installer modules, including wgt. - // Current implementation is just for compatibility. - icon->text = strdup(application_icon.path().c_str()); - icon->name = strdup(application_icon.path().c_str()); - icon->lang = strdup(DEFAULT_LOCALE); - app->icon = g_list_append(app->icon, icon); - } - return true; -} - -template -bool StepParse::FillLabel(application_x* app, const T& label_list) { - if (label_list.empty()) - return true; - - for (const auto& control : label_list) { - label_x* label = - static_cast(calloc(1, sizeof(label_x))); - // NOTE: name is an attribute, but the xml writer uses it as text. - // This must be fixed in whole app-installer modules, including wgt. - // Current implementation is just for compatibility. - label->text = strdup(control.text().c_str()); - label->name = strdup(control.name().c_str()); - label->lang = !control.xml_lang().empty() ? - strdup(control.xml_lang().c_str()) : strdup(DEFAULT_LOCALE); - app->label = g_list_append(app->label, label); - } - return true; -} - -template -bool StepParse::FillMetadata(application_x* app, const T& meta_data_list) { - if (meta_data_list.empty()) - return true; - - for (auto& meta : meta_data_list) { - metadata_x* metadata = - static_cast(calloc(1, sizeof(metadata_x))); - metadata->key = strdup(meta.key().c_str()); - metadata->value = strdup(meta.val().c_str()); - app->metadata = g_list_append(app->metadata, metadata); - } - return true; -} - -bool StepParse::FillImage(application_x* app, - const tpk::parse::ApplicationImagesInfo& image_list) { - for (auto& app_image : image_list.images) { - image_x* image = - static_cast(calloc(1, sizeof(image_x))); - image->name = strdup(app_image.name().c_str()); - const std::string& lang = app_image.lang(); - if (!lang.empty()) - image->lang = strdup(lang.c_str()); - else - image->lang = strdup(DEFAULT_LOCALE); - if (!app_image.section().empty()) - image->section = strdup(app_image.section().c_str()); - app->image = g_list_append(app->image, image); - } - return true; -} - -bool StepParse::FillAccounts() { - std::shared_ptr account_info = - std::static_pointer_cast(parser_->GetManifestData( - app_keys::kAccountKey)); - if (!account_info) - return true; - - common_installer::AccountInfo info; - for (auto& account : account_info->accounts()) { - common_installer::SingleAccountInfo single_info; - single_info.capabilities = account.capabilities; - single_info.icon_paths = account.icon_paths; - single_info.multiple_account_support = account.multiple_account_support; - single_info.names = account.labels; - // appid has the same value as package - single_info.appid = account.app_id; - single_info.providerid = account.provider_id; - info.set_account(single_info); - } - context_->manifest_plugins_data.get().account_info.set(info); - return true; -} - -bool StepParse::FillShortcuts() { - std::shared_ptr shortcut_info = - std::static_pointer_cast(parser_->GetManifestData( - app_keys::kShortcutListKey)); - if (!shortcut_info) - return true; - - common_installer::ShortcutListInfo list; - for (auto& shortcut : shortcut_info->shortcuts) { - common_installer::ShortcutInfo single_info; - single_info.app_id = shortcut.app_id; - single_info.extra_data = shortcut.extra_data; - single_info.extra_key = shortcut.extra_key; - single_info.icon = shortcut.icon; - single_info.labels = shortcut.labels; - list.push_back(single_info); - } - context_->manifest_plugins_data.get().shortcut_info.set(list); - return true; -} - -template -bool StepParse::FillBackgroundCategoryInfo(application_x* app, - const T& background_category_data_list) { - for (const auto& background_category : background_category_data_list) { - app->background_category = g_list_append( - app->background_category, strdup(background_category.value().c_str())); - } - - return true; -} - -bool StepParse::FillManifestX(manifest_x* manifest) { - if (!FillPackageInfo(manifest)) - return false; - if (!FillInstallationInfo(manifest)) - return false; - if (!FillUIApplication(manifest)) - return false; - if (!FillServiceApplication(manifest)) - return false; - if (!FillWidgetApplication(manifest)) - return false; - if (!FillPrivileges(manifest)) - return false; - if (!FillAccounts()) - return false; - if (!FillShortcuts()) - return false; - return true; -} - -common_installer::Step::Status StepParse::process() { - if (!LocateConfigFile()) { - LOG(ERROR) << "No manifest file exists"; - return common_installer::Step::Status::ERROR; - } - parser_.reset(new tpk::parse::TPKConfigParser()); - if (!parser_->ParseManifest(path_)) { - LOG(ERROR) << "[Parse] Parse failed. " << parser_->GetErrorMessage(); - return common_installer::Step::Status::ERROR; - } - - manifest_x* manifest = - static_cast(calloc(1, sizeof(manifest_x))); - - if (!FillManifestX(const_cast(manifest))) { - LOG(ERROR) << "[Parse] Storing manifest_x failed. " - << parser_->GetErrorMessage(); - return common_installer::Step::Status::ERROR; - } - - if (!context_->tep_path.get().empty()) - manifest->tep_name = context_->tep_path.get().c_str(); - - // Copy data from ManifestData to InstallerContext - std::shared_ptr info = - std::static_pointer_cast( - parser_->GetManifestData( - app_keys::kManifestKey)); - - context_->pkgid.set(manifest->package); - - // write pkgid for recovery file - if (context_->recovery_info.get().recovery_file) { - context_->recovery_info.get().recovery_file->set_pkgid(manifest->package); - context_->recovery_info.get().recovery_file->WriteAndCommitFileContent(); - } - - std::shared_ptr perm_info = - std::static_pointer_cast( - parser_->GetManifestData( - application_keys::kPrivilegesKey)); - parser::PrivilegesSet privileges; - if (perm_info) - privileges = perm_info->GetPrivileges(); - - std::shared_ptr ui_application_list = - std::static_pointer_cast( - parser_->GetManifestData(app_keys::kUIApplicationKey)); - - LOG(DEBUG) << " Read data -[ "; - LOG(DEBUG) << "App package: " << info->package(); - LOG(DEBUG) << " aplication version = " << info->version(); - LOG(DEBUG) << " api_version = " << info->api_version(); - if (ui_application_list) { - LOG(DEBUG) << " launch_modes -["; - for (const auto& application : ui_application_list->items) { - LOG(DEBUG) << " launch_mode[" << application.ui_info.appid() << "] = " - << application.ui_info.launch_mode(); - } - } - LOG(DEBUG) << " ]-"; - LOG(DEBUG) << " privileges -["; - for (const auto& p : privileges) { - LOG(DEBUG) << " " << p; - } - LOG(DEBUG) << " ]-"; - LOG(DEBUG) << "]-"; - - context_->manifest_data.set(manifest); - return common_installer::Step::Status::OK; -} - -} // namespace parse -} // namespace tpk diff --git a/src/tpk/step/step_parse.h b/src/tpk/step/step_parse.h deleted file mode 100644 index b1ccc4e..0000000 --- a/src/tpk/step/step_parse.h +++ /dev/null @@ -1,81 +0,0 @@ -// Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved -// Use of this source code is governed by an apache 2.0 license that can be -// found in the LICENSE file. - -#ifndef TPK_STEP_STEP_PARSE_H_ -#define TPK_STEP_STEP_PARSE_H_ - -#include - -#include -#include -#include -#include - -#include -#include -#include - -#include "common/app_installer.h" -#include "common/installer_context.h" -#include "common/step/step.h" - -namespace tpk { -namespace parse { - -class StepParse : public common_installer::Step { - public: - using Step::Step; - explicit StepParse(common_installer::InstallerContext* context, - bool check_start_file); - - Status process() override; - Status clean() override { return Status::OK; } - Status undo() override { return Status::OK; } - Status precheck() override; - - protected: - virtual bool LocateConfigFile(); - // This function is needed by recovery mode to override searching - // of configuration file of the package - virtual boost::filesystem::path LocateConfigFile() const; - boost::filesystem::path path_; - - private: - bool FillInstallationInfo(manifest_x* manifest); - bool FillPackageInfo(manifest_x* manifest); - bool FillAuthorInfo(manifest_x* manifest); - bool FillDescription(manifest_x* manifest); - bool FillPrivileges(manifest_x* manifest); - bool FillWidgetApplication(manifest_x* manifest); - bool FillServiceApplication(manifest_x* manifest); - bool FillUIApplication(manifest_x* manifest); - template - bool FillAppControl(application_x* manifest, const T& app_control_list); - template - bool FillDataControl(application_x* manifest, const T& data_control_list); - template - bool FillApplicationIconPaths(application_x* manifest, - const T& icons_info); - template - bool FillLabel(application_x* manifest, const T& label_list); - template - bool FillMetadata(application_x* manifest, const T& meta_data_list); - bool FillImage(application_x* app, - const tpk::parse::ApplicationImagesInfo& label_list); - bool FillAccounts(); - bool FillShortcuts(); - template - bool FillBackgroundCategoryInfo(application_x* app, - const T& background_category_data_list); - bool FillManifestX(manifest_x* manifest); - - std::unique_ptr parser_; - - SCOPE_LOG_TAG(Parse) -}; - -} // namespace parse -} // namespace tpk - -#endif // TPK_STEP_STEP_PARSE_H_ diff --git a/src/tpk/step/step_parse_recovery.cc b/src/tpk/step/step_parse_recovery.cc deleted file mode 100644 index da0fd29..0000000 --- a/src/tpk/step/step_parse_recovery.cc +++ /dev/null @@ -1,55 +0,0 @@ -// Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved -// Use of this source code is governed by an apache-2.0 license that can be -// found in the LICENSE file. - -#include "tpk/step/step_parse_recovery.h" - -#include - -#include "common/backup_paths.h" - -namespace bf = boost::filesystem; - -namespace { - -const char kManifestFileName[] = "tizen-manifest.xml"; - -} // namespace - -namespace tpk { -namespace parse { - -common_installer::Step::Status StepParseRecovery::process() { - (void) StepParse::process(); - return Status::OK; -} - - -common_installer::Step::Status StepParseRecovery::precheck() { - if (context_->root_application_path.get().empty()) { - LOG(ERROR) << "Root path of packages in not set"; - return Status::ERROR; - } - if (context_->pkgid.get().empty()) { - LOG(WARNING) << "Pkgid is not set. Parsing skipped"; - return Status::OK; - } - return Status::OK; -} - -boost::filesystem::path StepParseRecovery::LocateConfigFile() const { - context_->pkg_path.set( - context_->root_application_path.get() / context_->pkgid.get()); - bf::path path1 = common_installer::GetBackupPathForPackagePath( - context_->pkg_path.get()) / kManifestFileName; - bf::path path2 = context_->pkg_path.get() / kManifestFileName; - if (bf::exists(path1)) - return path1; - if (bf::exists(path2)) - return path2; - return {}; -} - -} // namespace parse -} // namespace tpk - diff --git a/src/tpk/step/step_parse_recovery.h b/src/tpk/step/step_parse_recovery.h deleted file mode 100644 index 5522ed0..0000000 --- a/src/tpk/step/step_parse_recovery.h +++ /dev/null @@ -1,32 +0,0 @@ -// Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved -// Use of this source code is governed by an apache-2.0 license that can be -// found in the LICENSE file. - -#ifndef TPK_STEP_STEP_PARSE_RECOVERY_H_ -#define TPK_STEP_STEP_PARSE_RECOVERY_H_ - -#include - -#include - -#include "tpk/step/step_parse.h" - -namespace tpk { -namespace parse { - -class StepParseRecovery : public StepParse { - public: - using StepParse::StepParse; - - Status process() override; - Status precheck() override; - - protected: - boost::filesystem::path LocateConfigFile() const override; - - SCOPE_LOG_TAG(ParseRecovery) -}; -} // namespace parse -} // namespace tpk - -#endif // TPK_STEP_STEP_PARSE_RECOVERY_H_ diff --git a/src/tpk/tpk_app_query_interface.cc b/src/tpk/tpk_app_query_interface.cc deleted file mode 100644 index 228aea7..0000000 --- a/src/tpk/tpk_app_query_interface.cc +++ /dev/null @@ -1,119 +0,0 @@ -// Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved -// Use of this source code is governed by an apache-2.0 license that can be -// found in the LICENSE file. - -#include "tpk/tpk_app_query_interface.h" - -#include -#include - -#include -#include -#include - -#include -#include -#include -#include - -#include -#include - -#include "common/pkgmgr_registration.h" -#include "common/request.h" -#include "common/utils/file_util.h" - -namespace bf = boost::filesystem; -namespace bs = boost::system; -namespace ci = common_installer; - -namespace { - -const char kManifestFileName[] = "tizen-manifest.xml"; - -std::string GetInstallationPackagePath(int argc, char** argv) { - std::string path; - for (int i = 0; i < argc; ++i) { - if (!strcmp(argv[i], "-i")) { - if (i + 1 < argc) { - path = argv[i + 1]; - break; - } - } - } - return path; -} - -std::string GetXmlPath(int argc, char** argv) { - std::string path; - for (int i = 0; i < argc; ++i) { - if (!strcmp(argv[i], "-x")) { - if (i + 1 < argc) { - path = argv[i + 1]; - break; - } - } - } - return path; -} - -std::string GetPkgIdFromXml(const std::string&path) { - bf::path xml_path(path); - - return xml_path.stem().string(); -} - -std::string GetPkgIdFromPath(const std::string& path) { - bf::path tmp_path = common_installer::GenerateTmpDir("/tmp"); - bs::error_code code; - bf::create_directories(tmp_path, code); - if (code) - return {}; - if (!common_installer::ExtractToTmpDir(path.c_str(), tmp_path, - kManifestFileName)) { - bf::remove_all(tmp_path, code); - return {}; - } - bf::path manifest_path = tmp_path / kManifestFileName; - if (!bf::exists(manifest_path)) { - bf::remove_all(tmp_path, code); - return {}; - } - - tpk::parse::TPKConfigParser parser; - if (!parser.ParseManifest(manifest_path)) - return {}; - auto package_info = std::static_pointer_cast( - parser.GetManifestData(tpk::application_keys::kManifestKey)); - if (!package_info) - return {}; - std::string pkg_id = package_info->package(); - bf::remove_all(tmp_path, code); - return pkg_id; -} - -} // namespace - -namespace tpk { - -bool TpkAppQueryInterface::IsAppInstalledByArgv(int argc, char** argv) { - std::string path = GetInstallationPackagePath(argc, argv); - std::string pkg_id; - if (path.empty()) { - // check if it is manifest direct install - path = GetXmlPath(argc, argv); - if (path.empty()) - return false; - - pkg_id = GetPkgIdFromXml(path); - } else { - pkg_id = GetPkgIdFromPath(path); - } - - if (pkg_id.empty()) - return false; - return ci::IsPackageInstalled(pkg_id, ci::GetRequestMode()); -} - -} // namespace tpk - diff --git a/src/tpk/tpk_app_query_interface.h b/src/tpk/tpk_app_query_interface.h deleted file mode 100644 index bfe2a14..0000000 --- a/src/tpk/tpk_app_query_interface.h +++ /dev/null @@ -1,19 +0,0 @@ -// Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved -// Use of this source code is governed by an apache-2.0 license that can be -// found in the LICENSE file. - -#ifndef TPK_TPK_APP_QUERY_INTERFACE_H_ -#define TPK_TPK_APP_QUERY_INTERFACE_H_ - -#include "common/app_query_interface.h" - -namespace tpk { - -class TpkAppQueryInterface : public common_installer::AppQueryInterface { - public: - bool IsAppInstalledByArgv(int argc, char** argv) override; -}; - -} // namespace tpk - -#endif // TPK_TPK_APP_QUERY_INTERFACE_H_ diff --git a/src/tpk/tpk_backend.cc b/src/tpk/tpk_backend.cc deleted file mode 100644 index 2df73d0..0000000 --- a/src/tpk/tpk_backend.cc +++ /dev/null @@ -1,26 +0,0 @@ -/* Copyright 2015 Samsung Electronics, license APACHE-2.0, see LICENSE file */ - -#include - -#include - -#include "common/pkgmgr_interface.h" -#include "tpk/tpk_app_query_interface.h" -#include "tpk/tpk_installer.h" - -namespace ci = common_installer; - -int main(const int argc, char* argv[]) { - tpk::TpkAppQueryInterface interface; - ci::PkgMgrPtr pkgmgr = ci::PkgMgrInterface::Create(argc, argv, &interface); - if (!pkgmgr) { - LOG(ERROR) << "Failed to create pkgmgr interface"; - return -1; - } - tpk::TpkInstaller t(pkgmgr); - if (t.Run() != ci::AppInstaller::Result::OK) { - LOG(ERROR) << "TpkInstaller run failure"; - return -1; - } - return 0; -} diff --git a/src/tpk/tpk_installer.cc b/src/tpk/tpk_installer.cc deleted file mode 100644 index 65cb108..0000000 --- a/src/tpk/tpk_installer.cc +++ /dev/null @@ -1,218 +0,0 @@ -/* Copyright 2015 Samsung Electronics, license APACHE-2.0, see LICENSE file */ -#include "tpk/tpk_installer.h" -#include "common/app_installer.h" -#include "common/step/step_configure.h" -#include "common/step/step_backup_icons.h" -#include "common/step/step_backup_manifest.h" -#include "common/step/step_create_icons.h" -#include "common/step/step_create_storage_directories.h" -#include "common/step/step_copy.h" -#include "common/step/step_copy_tep.h" -#include "common/step/step_copy_backup.h" -#include "common/step/step_check_old_certificate.h" -#include "common/step/step_delta_patch.h" -#include "common/step/step_fail.h" -#include "common/step/step_kill_apps.h" -#include "common/step/step_old_manifest.h" -#include "common/step/step_open_recovery_file.h" -#include "common/step/step_parse.h" -#include "common/step/step_privilege_compatibility.h" -#include "common/step/step_recover_application.h" -#include "common/step/step_recover_files.h" -#include "common/step/step_recover_icons.h" -#include "common/step/step_recover_manifest.h" -#include "common/step/step_recover_security.h" -#include "common/step/step_recover_storage_directories.h" -#include "common/step/step_register_app.h" -#include "common/step/step_remove_icons.h" -#include "common/step/step_remove_files.h" -#include "common/step/step_revoke_security.h" -#include "common/step/step_remove_temporary_directory.h" -#include "common/step/step_register_security.h" -#include "common/step/step_rollback_deinstallation_security.h" -#include "common/step/step_rollback_installation_security.h" -#include "common/step/step_check_signature.h" -#include "common/step/step_unregister_app.h" -#include "common/step/step_unzip.h" -#include "common/step/step_update_app.h" -#include "common/step/step_update_security.h" -#include "common/step/step_update_tep.h" -#include "tpk/step/step_check_tpk_background_category.h" -#include "tpk/step/step_create_symbolic_link.h" -#include "tpk/step/step_parse.h" -#include "tpk/step/step_parse_recovery.h" -#include "tpk/step/step_convert_xml.h" - -namespace ci = common_installer; - -namespace { - -const char kPkgType[] = "tpk"; - -} // namespace - -namespace tpk { - -TpkInstaller::TpkInstaller(common_installer::PkgMgrPtr pkgmgr) - : AppInstaller(kPkgType, pkgmgr) { - Prepare(); -} - -TpkInstaller::~TpkInstaller() { -} - -void TpkInstaller::Prepare() { - switch (pkgmgr_->GetRequestType()) { - case ci::RequestType::Install: - InstallSteps(); - break; - case ci::RequestType::Update: - UpdateSteps(); - break; - case ci::RequestType::Uninstall: - UninstallSteps(); - break; - case ci::RequestType::Reinstall: - ReinstallSteps(); - break; - case ci::RequestType::Delta: - DeltaSteps(); - break; - case ci::RequestType::Recovery: - RecoverySteps(); - break; - case ci::RequestType::ManifestDirectInstall: - ManifestDirectInstallSteps(); - break; - case ci::RequestType::ManifestDirectUpdate: - ManifestDirectUpdateSteps(); - break; - default: - AddStep(); - break; - } -} - -void TpkInstaller::InstallSteps() { - AddStep(pkgmgr_); - AddStep(); - AddStep(); - AddStep(); - AddStep(); - AddStep(); - AddStep(); - AddStep(); - AddStep(); - AddStep(); - AddStep(); - AddStep(); - AddStep(); - AddStep(); - AddStep(); -} - -void TpkInstaller::UpdateSteps() { - AddStep(pkgmgr_); - AddStep(); - AddStep(); - AddStep(); - AddStep(); - AddStep(); - AddStep(); - AddStep(); - AddStep(); - AddStep(); - AddStep(); - AddStep(); - AddStep(); - AddStep(); - // TODO(t.iwanek): handle coping storage directories - AddStep(); - AddStep(); - AddStep(); - AddStep(); - AddStep(); - /* TODO(jungh.yeon): this temporary step will be removed - * when secondary parsing procedure has removed*/ - AddStep(); -} - -void TpkInstaller::UninstallSteps() { - AddStep(pkgmgr_); - AddStep(); - AddStep(); - AddStep(); - AddStep(); - AddStep(); - AddStep(); - AddStep(); - AddStep(); -} - -void TpkInstaller::ReinstallSteps() { - AddStep(); -} - -void TpkInstaller::DeltaSteps() { - AddStep(pkgmgr_); - AddStep(); - AddStep(); - AddStep(); - AddStep(); - AddStep(); - AddStep(); - AddStep(); - AddStep(); - AddStep(); - AddStep(); - AddStep(); - AddStep(); - AddStep(); - // TODO(t.iwanek): handle coping storage directories - AddStep(); - AddStep(); - AddStep(); - AddStep(); - AddStep(); -} - -void TpkInstaller::RecoverySteps() { - AddStep(pkgmgr_); - AddStep(); - AddStep(); - AddStep(); - AddStep(); - AddStep(); - AddStep(); - AddStep(); - AddStep(); - AddStep(); -} - -void TpkInstaller::ManifestDirectInstallSteps() { - AddStep(pkgmgr_); - AddStep(); - AddStep(); - AddStep(); - AddStep(); - AddStep(); - AddStep(); - AddStep(); -} - -void TpkInstaller::ManifestDirectUpdateSteps() { - AddStep(pkgmgr_); - AddStep(); - AddStep(); - AddStep(); - AddStep(); - AddStep(); - AddStep(); - AddStep(); - AddStep(); - AddStep(); -} - - -} // namespace tpk - diff --git a/src/tpk/tpk_installer.h b/src/tpk/tpk_installer.h deleted file mode 100644 index 43acab5..0000000 --- a/src/tpk/tpk_installer.h +++ /dev/null @@ -1,42 +0,0 @@ -/* Copyright 2015 Samsung Electronics, license APACHE-2.0, see LICENSE file */ - -#ifndef TPK_TPK_INSTALLER_H_ -#define TPK_TPK_INSTALLER_H_ - -#include - -#include "common/app_installer.h" -#include "common/pkgmgr_interface.h" - -namespace tpk { - -/** - * @brief The TpkInstaller class - * Handles request of tpk packages. - * - * This class is main class for installation/update/deinstallation of tpk - * packages. Pkgmgr request is parsed within and sequence of steps is built to - * be run. - */ -class TpkInstaller : public common_installer::AppInstaller { - public: - explicit TpkInstaller(common_installer::PkgMgrPtr pkgmgr); - ~TpkInstaller(); - void Prepare(); - - private: - void InstallSteps(); - void UpdateSteps(); - void UninstallSteps(); - void ReinstallSteps(); - void DeltaSteps(); - void RecoverySteps(); - void ManifestDirectInstallSteps(); - void ManifestDirectUpdateSteps(); - - SCOPE_LOG_TAG(TpkInstaller) -}; - -} // namespace tpk - -#endif // TPK_TPK_INSTALLER_H_ diff --git a/src/unit_tests/CMakeLists.txt b/src/unit_tests/CMakeLists.txt index 54f33fa..fab013c 100644 --- a/src/unit_tests/CMakeLists.txt +++ b/src/unit_tests/CMakeLists.txt @@ -1,7 +1,3 @@ -SET(TESTS - signature_unittest - smoke_test -) SET(DESTINATION_DIR app-installers-ut) INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/../) @@ -10,27 +6,17 @@ INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/../) ADD_EXECUTABLE(signature_unittest signature_unittest.cc ) -ADD_EXECUTABLE(smoke_test - smoke_test.cc -) INSTALL(DIRECTORY test_samples/ DESTINATION ${SHAREDIR}/${DESTINATION_DIR}/test_samples) -INSTALL(FILES run-unit-tests.sh DESTINATION ${BINDIR}/app-installers-ut/ - PERMISSIONS OWNER_EXECUTE OWNER_WRITE OWNER_READ GROUP_EXECUTE GROUP_READ) -FOREACH(test ${TESTS}) -APPLY_PKG_CONFIG(${test} PUBLIC +APPLY_PKG_CONFIG(signature_unittest PUBLIC Boost GTEST ) -ENDFOREACH(test) # FindGTest module do not sets all needed libraries in GTEST_LIBRARIES and # GTest main libraries is still missing, so additional linking of # GTEST_MAIN_LIBRARIES is needed. target_link_libraries(signature_unittest PUBLIC ${TARGET_LIBNAME_COMMON} ${GTEST_MAIN_LIBRARIES} pthread) -target_link_libraries(smoke_test PRIVATE ${TARGET_LIBNAME_WGT} ${TARGET_LIBNAME_TPK} pthread) -FOREACH(test ${TESTS}) - INSTALL(TARGETS ${test} DESTINATION ${BINDIR}/${DESTINATION_DIR}) -ENDFOREACH(test) +INSTALL(TARGETS signature_unittest DESTINATION ${BINDIR}/${DESTINATION_DIR}) diff --git a/src/unit_tests/run-unit-tests.sh b/src/unit_tests/run-unit-tests.sh deleted file mode 100755 index 26db6c3..0000000 --- a/src/unit_tests/run-unit-tests.sh +++ /dev/null @@ -1,11 +0,0 @@ -#!/bin/sh - -test_dir="`dirname $0`/*" -for file in $test_dir -do - if test -f "$file"; then - if [[ -x "$file" && ${file: -3} != ".sh" ]]; then - $file --gtest_output=xml:$file.xml - fi - fi -done diff --git a/src/unit_tests/smoke_test.cc b/src/unit_tests/smoke_test.cc deleted file mode 100644 index 29a0973..0000000 --- a/src/unit_tests/smoke_test.cc +++ /dev/null @@ -1,587 +0,0 @@ -// Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved -// Use of this source code is governed by an apache-2.0 license that can be -// found in the LICENSE file. - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include -#include - -#include "common/backup_paths.h" -#include "common/pkgmgr_interface.h" -#include "common/pkgmgr_registration.h" -#include "common/request.h" -#include "common/step/step_fail.h" -#include "tpk/tpk_app_query_interface.h" -#include "tpk/tpk_installer.h" -#include "wgt/wgt_app_query_interface.h" -#include "wgt/wgt_installer.h" - -#define SIZEOFARRAY(ARR) \ - sizeof(ARR) / sizeof(ARR[0]) \ - -namespace bf = boost::filesystem; -namespace bs = boost::system; -namespace ci = common_installer; - -namespace { - -const char kApplicationDir[] = ".applications"; -const char kApplicationDirBackup[] = ".applications.bck"; -const char KUserAppsDir[] = "apps_rw"; -const char KUserAppsDirBackup[] = "apps_rw.bck"; - -enum class RequestResult { - NORMAL, - FAIL, - CRASH -}; - -enum class PackageType { - TPK, - WGT -}; - -class StepCrash : public ci::Step { - public: - using Step::Step; - - ci::Step::Status process() override { - raise(SIGSEGV); - return Status::OK; - } - ci::Step::Status clean() override { return ci::Step::Status::OK; } - ci::Step::Status undo() override { return ci::Step::Status::OK; } - ci::Step::Status precheck() override { return ci::Step::Status::OK; } -}; - -void RemoveAllRecoveryFiles() { - bf::path root_path = ci::GetRootAppPath(); - for (auto& dir_entry : boost::make_iterator_range( - bf::directory_iterator(root_path), bf::directory_iterator())) { - if (bf::is_regular_file(dir_entry)) { - if (dir_entry.path().string().find("/recovery") != std::string::npos) { - bs::error_code error; - bf::remove(dir_entry.path(), error); - } - } - } -} - -bf::path FindRecoveryFile() { - bf::path root_path = ci::GetRootAppPath(); - for (auto& dir_entry : boost::make_iterator_range( - bf::directory_iterator(root_path), bf::directory_iterator())) { - if (bf::is_regular_file(dir_entry)) { - if (dir_entry.path().string().find("/recovery") != std::string::npos) { - return dir_entry.path(); - } - } - } - return {}; -} - -bool ValidateFileContentInPackage(const std::string& pkgid, - const std::string& relative, - const std::string& expected) { - bf::path root_path = ci::GetRootAppPath(); - bf::path file_path = root_path / pkgid / relative; - if (!bf::exists(file_path)) { - LOG(ERROR) << file_path << " doesn't exist"; - return false; - } - FILE* handle = fopen(file_path.c_str(), "r"); - if (!handle) { - LOG(ERROR) << file_path << " cannot be open"; - return false; - } - std::string content; - std::array buffer; - while (fgets(buffer.data(), buffer.size(), handle)) { - content += buffer.data(); - } - fclose(handle); - return content == expected; -} - -void ValidatePackageFS(const std::string& pkgid, const std::string& appid, - PackageType type) { - bf::path root_path = ci::GetRootAppPath(); - bf::path package_path = root_path / pkgid; - bf::path binary_path = package_path / "bin" / appid; - bf::path data_path = package_path / "data"; - bf::path shared_path = package_path / "shared"; - bf::path cache_path = package_path / "cache"; - ASSERT_TRUE(bf::exists(root_path)); - ASSERT_TRUE(bf::exists(package_path)); - ASSERT_TRUE(bf::exists(binary_path)); - ASSERT_TRUE(bf::exists(data_path)); - ASSERT_TRUE(bf::exists(shared_path)); - ASSERT_TRUE(bf::exists(cache_path)); - - bf::path manifest_path = - bf::path(getUserManifestPath(getuid())) / (pkgid + ".xml"); - bf::path icon_path = bf::path(getIconPath(getuid())) / (appid + ".png"); - ASSERT_TRUE(bf::exists(manifest_path)); - ASSERT_TRUE(bf::exists(icon_path)); - - if (type == PackageType::WGT) { - bf::path widget_root_path = package_path / "res" / "wgt"; - bf::path config_path = widget_root_path / "config.xml"; - ASSERT_TRUE(bf::exists(widget_root_path)); - ASSERT_TRUE(bf::exists(config_path)); - - bf::path private_tmp_path = package_path / "tmp"; - ASSERT_TRUE(bf::exists(private_tmp_path)); - } - - // backups should not exist - bf::path package_backup = ci::GetBackupPathForPackagePath(package_path); - bf::path manifest_backup = ci::GetBackupPathForManifestFile(manifest_path); - bf::path icon_backup = ci::GetBackupPathForIconFile(icon_path); - ASSERT_FALSE(bf::exists(package_backup)); - ASSERT_FALSE(bf::exists(manifest_backup)); - ASSERT_FALSE(bf::exists(icon_backup)); -} - -void PackageCheckCleanup(const std::string& pkgid, const std::string& appid) { - bf::path root_path = ci::GetRootAppPath(); - bf::path package_path = root_path / pkgid; - ASSERT_FALSE(bf::exists(package_path)); - - bf::path manifest_path = - bf::path(getUserManifestPath(getuid())) / (pkgid + ".xml"); - bf::path icon_path = bf::path(getIconPath(getuid())) / (appid + ".png"); - ASSERT_FALSE(bf::exists(manifest_path)); - ASSERT_FALSE(bf::exists(icon_path)); - - // backups should not exist - bf::path package_backup = ci::GetBackupPathForPackagePath(package_path); - bf::path manifest_backup = ci::GetBackupPathForManifestFile(manifest_path); - bf::path icon_backup = ci::GetBackupPathForIconFile(icon_path); - ASSERT_FALSE(bf::exists(package_backup)); - ASSERT_FALSE(bf::exists(manifest_backup)); - ASSERT_FALSE(bf::exists(icon_backup)); -} - -void ValidatePackage(const std::string& pkgid, const std::string& appid, - PackageType type) { - ASSERT_TRUE(ci::IsPackageInstalled(pkgid, ci::GetRequestMode())); - ValidatePackageFS(pkgid, appid, type); -} - -void CheckPackageNonExistance(const std::string& pkgid, - const std::string& appid) { - ASSERT_FALSE(ci::IsPackageInstalled(pkgid, ci::GetRequestMode())); - PackageCheckCleanup(pkgid, appid); -} - -std::unique_ptr CreateQueryInterface(PackageType type) { - std::unique_ptr query_interface; - switch (type) { - case PackageType::TPK: - query_interface.reset(new tpk::TpkAppQueryInterface()); - break; - case PackageType::WGT: - query_interface.reset(new wgt::WgtAppQueryInterface()); - break; - } - return query_interface; -} - -std::unique_ptr CreateInstaller(ci::PkgMgrPtr pkgmgr, - PackageType type) { - std::unique_ptr installer; - switch (type) { - case PackageType::TPK: - installer.reset(new tpk::TpkInstaller(pkgmgr)); - break; - case PackageType::WGT: - installer.reset(new wgt::WgtInstaller(pkgmgr)); - break; - } - return installer; -} - -ci::AppInstaller::Result RunInstallerWithPkgrmgr(ci::PkgMgrPtr pkgmgr, - PackageType type, - RequestResult mode) { - std::unique_ptr installer = CreateInstaller(pkgmgr, type); - switch (mode) { - case RequestResult::FAIL: - installer->AddStep(); - break; - case RequestResult::CRASH: - installer->AddStep(); - default: - break; - } - return installer->Run(); -} - -ci::AppInstaller::Result Install(const bf::path& path, - PackageType type, - RequestResult mode = RequestResult::NORMAL) { - const char* argv[] = {"", "-i", path.c_str()}; - std::unique_ptr query_interface = - CreateQueryInterface(type); - auto pkgmgr = - ci::PkgMgrInterface::Create(SIZEOFARRAY(argv), const_cast(argv), - query_interface.get()); - if (!pkgmgr) { - LOG(ERROR) << "Failed to initialize pkgmgr interface"; - return ci::AppInstaller::Result::UNKNOWN; - } - return RunInstallerWithPkgrmgr(pkgmgr, type, mode); -} - -ci::AppInstaller::Result Update(const bf::path& path_old, - const bf::path& path_new, - PackageType type, - RequestResult mode = RequestResult::NORMAL) { - if (Install(path_old, type) != ci::AppInstaller::Result::OK) { - LOG(ERROR) << "Failed to install application. Cannot update"; - return ci::AppInstaller::Result::UNKNOWN; - } - return Install(path_new, type, mode); -} - -ci::AppInstaller::Result Uninstall(const std::string& pkgid, - PackageType type, - RequestResult mode = RequestResult::NORMAL) { - const char* argv[] = {"", "-d", pkgid.c_str()}; - std::unique_ptr query_interface = - CreateQueryInterface(type); - auto pkgmgr = - ci::PkgMgrInterface::Create(SIZEOFARRAY(argv), const_cast(argv), - query_interface.get()); - if (!pkgmgr) { - LOG(ERROR) << "Failed to initialize pkgmgr interface"; - return ci::AppInstaller::Result::UNKNOWN; - } - return RunInstallerWithPkgrmgr(pkgmgr, type, mode); -} - -ci::AppInstaller::Result Reinstall(const bf::path& path, - const bf::path& delta_dir, - PackageType type, - RequestResult mode = RequestResult::NORMAL) { - if (Install(path, type) != ci::AppInstaller::Result::OK) { - LOG(ERROR) << "Failed to install application. Cannot perform RDS"; - return ci::AppInstaller::Result::UNKNOWN; - } - const char* argv[] = {"", "-r", delta_dir.c_str()}; - std::unique_ptr query_interface = - CreateQueryInterface(type); - auto pkgmgr = - ci::PkgMgrInterface::Create(SIZEOFARRAY(argv), const_cast(argv), - query_interface.get()); - if (!pkgmgr) { - LOG(ERROR) << "Failed to initialize pkgmgr interface"; - return ci::AppInstaller::Result::UNKNOWN; - } - return RunInstallerWithPkgrmgr(pkgmgr, type, mode); -} - -ci::AppInstaller::Result DeltaInstall(const bf::path& path, - const bf::path& delta_package, PackageType type) { - if (Install(path, type) != ci::AppInstaller::Result::OK) { - LOG(ERROR) << "Failed to install application. Cannot perform RDS"; - return ci::AppInstaller::Result::UNKNOWN; - } - return Install(delta_package, type); -} - -ci::AppInstaller::Result Recover(const bf::path& recovery_file, - PackageType type, - RequestResult mode = RequestResult::NORMAL) { - const char* argv[] = {"", "-e", recovery_file.c_str()}; - std::unique_ptr query_interface = - CreateQueryInterface(type); - auto pkgmgr = - ci::PkgMgrInterface::Create(SIZEOFARRAY(argv), const_cast(argv), - query_interface.get()); - if (!pkgmgr) { - LOG(ERROR) << "Failed to initialize pkgmgr interface"; - return ci::AppInstaller::Result::UNKNOWN; - } - return RunInstallerWithPkgrmgr(pkgmgr, type, mode); -} - -} // namespace - -namespace common_installer { - -class SmokeEnvironment : public testing::Environment { - public: - explicit SmokeEnvironment(const bf::path& home) : home_(home) { - } - void SetUp() override { - bs::error_code error; - bf::remove_all(home_ / kApplicationDirBackup, error); - bf::remove_all(home_ / KUserAppsDirBackup, error); - if (bf::exists(home_ / KUserAppsDir)) { - bf::rename(home_ / KUserAppsDir, home_ / KUserAppsDirBackup, error); - assert(!error); - } - if (bf::exists(home_ / kApplicationDir)) { - bf::rename(home_ / kApplicationDir, home_ / kApplicationDirBackup, error); - assert(!error); - } - } - void TearDown() override { - bs::error_code error; - bf::remove_all(home_ / kApplicationDir, error); - bf::remove_all(home_ / KUserAppsDir, error); - if (bf::exists(home_ / KUserAppsDirBackup)) - bf::rename(home_ / KUserAppsDirBackup, home_ / KUserAppsDir, error); - if (bf::exists(home_ / kApplicationDirBackup)) - bf::rename(home_ / kApplicationDirBackup, home_ / kApplicationDir, error); - } - - private: - bf::path home_; -}; - -class SmokeTest : public testing::Test { -}; - -TEST_F(SmokeTest, InstallationMode) { - bf::path path = "/usr/share/app-installers-ut/test_samples/smoke/InstallationMode.wgt"; // NOLINT - std::string pkgid = "smokeapp03"; - std::string appid = "smokeapp03.InstallationMode"; - ASSERT_EQ(Install(path, PackageType::WGT), ci::AppInstaller::Result::OK); - ValidatePackage(pkgid, appid, PackageType::WGT); -} - -TEST_F(SmokeTest, UpdateMode) { - bf::path path_old = "/usr/share/app-installers-ut/test_samples/smoke/UpdateMode.wgt"; // NOLINT - bf::path path_new = "/usr/share/app-installers-ut/test_samples/smoke/UpdateMode_2.wgt"; // NOLINT - std::string pkgid = "smokeapp04"; - std::string appid = "smokeapp04.UpdateMode"; - ASSERT_EQ(Update(path_old, path_new, PackageType::WGT), - ci::AppInstaller::Result::OK); - ValidatePackage(pkgid, appid, PackageType::WGT); - - ASSERT_TRUE(ValidateFileContentInPackage(pkgid, "res/wgt/VERSION", "2\n")); -} - -TEST_F(SmokeTest, DeinstallationMode) { - bf::path path = "/usr/share/app-installers-ut/test_samples/smoke/DeinstallationMode.wgt"; // NOLINT - std::string pkgid = "smokeapp05"; - std::string appid = "smokeapp05.DeinstallationMode"; - ASSERT_EQ(Install(path, PackageType::WGT), - ci::AppInstaller::Result::OK); - ASSERT_EQ(Uninstall(pkgid, PackageType::WGT), ci::AppInstaller::Result::OK); - CheckPackageNonExistance(pkgid, appid); -} - -TEST_F(SmokeTest, RDSMode) { - bf::path path = "/usr/share/app-installers-ut/test_samples/smoke/RDSMode.wgt"; // NOLINT - std::string delta_directory = "/usr/share/app-installers-ut/test_samples/smoke/delta_dir/"; // NOLINT - std::string pkgid = "smokeapp11"; - std::string appid = "smokeapp11.RDSMode"; - ASSERT_EQ(Reinstall(path, delta_directory, PackageType::WGT), - ci::AppInstaller::Result::OK); - ValidatePackage(pkgid, appid, PackageType::WGT); - - // Check delta modifications - bf::path root_path = ci::GetRootAppPath(); - ASSERT_FALSE(bf::exists(root_path / pkgid / "res" / "wgt" / "DELETED")); - ASSERT_TRUE(bf::exists(root_path / pkgid / "res" / "wgt" / "ADDED")); - ValidateFileContentInPackage(pkgid, "res/wgt/MODIFIED", "2\n"); -} - -TEST_F(SmokeTest, DeltaMode) { - bf::path path = "/usr/share/app-installers-ut/test_samples/smoke/DeltaMode.wgt"; // NOLINT - std::string delta_package = "/usr/share/app-installers-ut/test_samples/smoke/DeltaMode.delta"; // NOLINT - std::string pkgid = "smokeapp17"; - std::string appid = "smokeapp17.DeltaMode"; - ASSERT_EQ(DeltaInstall(path, delta_package, PackageType::WGT), - ci::AppInstaller::Result::OK); - ValidatePackage(pkgid, appid, PackageType::WGT); - - // Check delta modifications - bf::path root_path = ci::GetRootAppPath(); - ASSERT_FALSE(bf::exists(root_path / pkgid / "res" / "wgt" / "DELETED")); - ASSERT_TRUE(bf::exists(root_path / pkgid / "res" / "wgt" / "ADDED")); - ASSERT_TRUE(bf::exists(root_path / pkgid / "res" / "wgt" / "css" / "style.css")); // NOLINT - ASSERT_TRUE(bf::exists(root_path / pkgid / "res" / "wgt" / "images" / "tizen_32.png")); // NOLINT - ASSERT_TRUE(bf::exists(root_path / pkgid / "res" / "wgt" / "js" / "main.js")); - ValidateFileContentInPackage(pkgid, "res/wgt/MODIFIED", "version 2\n"); -} - -TEST_F(SmokeTest, DeltaMode_Tpk) { - bf::path path = "/usr/share/app-installers-ut/test_samples/smoke/DeltaMode_Tpk.tpk"; // NOLINT - std::string delta_package = "/usr/share/app-installers-ut/test_samples/smoke/DeltaMode_Tpk.delta"; // NOLINT - std::string pkgid = "smokeapp18"; - std::string appid = "smokeapp18.DeltaModeTpk"; - ASSERT_EQ(DeltaInstall(path, delta_package, PackageType::TPK), - ci::AppInstaller::Result::OK); - ValidatePackage(pkgid, appid, PackageType::TPK); - - // Check delta modifications - bf::path root_path = ci::GetRootAppPath(); - ASSERT_FALSE(bf::exists(root_path / pkgid / "DELETED")); - ASSERT_TRUE(bf::exists(root_path / pkgid / "ADDED")); - ASSERT_TRUE(bf::exists(root_path / pkgid / "bin" / "native")); - ASSERT_TRUE(bf::exists(root_path / pkgid / "shared" / "res" / "native.png")); - ValidateFileContentInPackage(pkgid, "MODIFIED", "version 2\n"); -} - -TEST_F(SmokeTest, RecoveryMode_ForInstallation) { - bf::path path = "/usr/share/app-installers-ut/test_samples/smoke/RecoveryMode_ForInstallation.wgt"; // NOLINT - ASSERT_DEATH(Install(path, PackageType::WGT, RequestResult::CRASH), ".*"); - - std::string pkgid = "smokeapp09"; - std::string appid = "smokeapp09.RecoveryModeForInstallation"; - bf::path recovery_file = FindRecoveryFile(); - ASSERT_FALSE(recovery_file.empty()); - ASSERT_EQ(Recover(recovery_file, PackageType::WGT), - ci::AppInstaller::Result::OK); - CheckPackageNonExistance(pkgid, appid); -} - -TEST_F(SmokeTest, RecoveryMode_ForUpdate) { - bf::path path_old = "/usr/share/app-installers-ut/test_samples/smoke/RecoveryMode_ForUpdate.wgt"; // NOLINT - bf::path path_new = "/usr/share/app-installers-ut/test_samples/smoke/RecoveryMode_ForUpdate_2.wgt"; // NOLINT - RemoveAllRecoveryFiles(); - ASSERT_DEATH(Update(path_old, path_new, PackageType::WGT, - RequestResult::CRASH), ".*"); - - std::string pkgid = "smokeapp10"; - std::string appid = "smokeapp10.RecoveryModeForUpdate"; - bf::path recovery_file = FindRecoveryFile(); - ASSERT_FALSE(recovery_file.empty()); - ASSERT_EQ(Recover(recovery_file, PackageType::WGT), - ci::AppInstaller::Result::OK); - ValidatePackage(pkgid, appid, PackageType::WGT); - - ASSERT_TRUE(ValidateFileContentInPackage(pkgid, "res/wgt/VERSION", "1\n")); -} - -TEST_F(SmokeTest, InstallationMode_GoodSignature) { - bf::path path = "/usr/share/app-installers-ut/test_samples/smoke/InstallationMode_GoodSignature.wgt"; // NOLINT - ASSERT_EQ(Install(path, PackageType::WGT), ci::AppInstaller::Result::OK); -} - -TEST_F(SmokeTest, InstallationMode_WrongSignature) { - bf::path path = "/usr/share/app-installers-ut/test_samples/smoke/InstallationMode_WrongSignature.wgt"; // NOLINT - ASSERT_EQ(Install(path, PackageType::WGT), ci::AppInstaller::Result::ERROR); -} - -TEST_F(SmokeTest, InstallationMode_Rollback) { - bf::path path = "/usr/share/app-installers-ut/test_samples/smoke/InstallationMode_Rollback.wgt"; // NOLINT - std::string pkgid = "smokeapp06"; - std::string appid = "smokeapp06.InstallationModeRollback"; - ASSERT_EQ(Install(path, PackageType::WGT, RequestResult::FAIL), - ci::AppInstaller::Result::ERROR); - CheckPackageNonExistance(pkgid, appid); -} - -TEST_F(SmokeTest, UpdateMode_Rollback) { - bf::path path_old = "/usr/share/app-installers-ut/test_samples/smoke/UpdateMode_Rollback.wgt"; // NOLINT - bf::path path_new = "/usr/share/app-installers-ut/test_samples/smoke/UpdateMode_Rollback_2.wgt"; // NOLINT - std::string pkgid = "smokeapp07"; - std::string appid = "smokeapp07.UpdateModeRollback"; - ASSERT_EQ(Update(path_old, path_new, PackageType::WGT, RequestResult::FAIL), - ci::AppInstaller::Result::ERROR); - ValidatePackage(pkgid, appid, PackageType::WGT); - - ASSERT_TRUE(ValidateFileContentInPackage(pkgid, "res/wgt/VERSION", "1\n")); -} - -TEST_F(SmokeTest, DeinstallationMode_Rollback) { - bf::path path = "/usr/share/app-installers-ut/test_samples/smoke/DeinstallationMode_Rollback.wgt"; // NOLINT - std::string pkgid = "smokeapp08"; - std::string appid = "smokeapp08.DeinstallationModeRollback"; - ASSERT_EQ(Install(path, PackageType::WGT), ci::AppInstaller::Result::OK); - ASSERT_EQ(Uninstall(pkgid, PackageType::WGT, RequestResult::FAIL), - ci::AppInstaller::Result::ERROR); - ValidatePackage(pkgid, appid, PackageType::WGT); -} - -TEST_F(SmokeTest, InstallationMode_Tpk) { - bf::path path = "/usr/share/app-installers-ut/test_samples/smoke/InstallationMode_Tpk.tpk"; // NOLINT - std::string pkgid = "smokeapp12"; - std::string appid = "smokeapp12.InstallationModeTpk"; - ASSERT_EQ(Install(path, PackageType::TPK), ci::AppInstaller::Result::OK); - ValidatePackage(pkgid, appid, PackageType::TPK); -} - -TEST_F(SmokeTest, UpdateMode_Tpk) { - bf::path path_old = "/usr/share/app-installers-ut/test_samples/smoke/UpdateMode_Tpk.tpk"; // NOLINT - bf::path path_new = "/usr/share/app-installers-ut/test_samples/smoke/UpdateMode_Tpk_2.tpk"; // NOLINT - std::string pkgid = "smokeapp13"; - std::string appid = "smokeapp13.UpdateModeTpk"; - ASSERT_EQ(Update(path_old, path_new, PackageType::TPK), - ci::AppInstaller::Result::OK); - ValidatePackage(pkgid, appid, PackageType::TPK); - - ASSERT_TRUE(ValidateFileContentInPackage(pkgid, "VERSION", "2\n")); -} - -TEST_F(SmokeTest, DeinstallationMode_Tpk) { - bf::path path = "/usr/share/app-installers-ut/test_samples/smoke/DeinstallationMode_Tpk.tpk"; // NOLINT - std::string pkgid = "smokeapp14"; - std::string appid = "smokeapp14.DeinstallationModeTpk"; - ASSERT_EQ(Install(path, PackageType::TPK), - ci::AppInstaller::Result::OK); - ASSERT_EQ(Uninstall(pkgid, PackageType::TPK), ci::AppInstaller::Result::OK); - CheckPackageNonExistance(pkgid, appid); -} - -TEST_F(SmokeTest, RecoveryMode_Tpk_Installation) { - bf::path path = "/usr/share/app-installers-ut/test_samples/smoke/RecoveryMode_Tpk_Installation.tpk"; // NOLINT - ASSERT_DEATH(Install(path, PackageType::TPK, RequestResult::CRASH), ".*"); - - std::string pkgid = "smokeapp15"; - std::string appid = "smokeapp15.RecoveryModeTpkInstallation"; - bf::path recovery_file = FindRecoveryFile(); - ASSERT_FALSE(recovery_file.empty()); - ASSERT_EQ(Recover(recovery_file, PackageType::TPK), - ci::AppInstaller::Result::OK); - CheckPackageNonExistance(pkgid, appid); -} - -TEST_F(SmokeTest, RecoveryMode_Tpk_Update) { - bf::path path_old = "/usr/share/app-installers-ut/test_samples/smoke/RecoveryMode_Tpk_Update.tpk"; // NOLINT - bf::path path_new = "/usr/share/app-installers-ut/test_samples/smoke/RecoveryMode_Tpk_Update_2.tpk"; // NOLINT - RemoveAllRecoveryFiles(); - ASSERT_DEATH(Update(path_old, path_new, PackageType::TPK, - RequestResult::CRASH), ".*"); - - std::string pkgid = "smokeapp16"; - std::string appid = "smokeapp16.RecoveryModeTpkUpdate"; - bf::path recovery_file = FindRecoveryFile(); - ASSERT_FALSE(recovery_file.empty()); - ASSERT_EQ(Recover(recovery_file, PackageType::TPK), - ci::AppInstaller::Result::OK); - ValidatePackage(pkgid, appid, PackageType::TPK); - - ASSERT_TRUE(ValidateFileContentInPackage(pkgid, "VERSION", "1\n")); -} - -} // namespace common_installer - -int main(int argc, char** argv) { - testing::InitGoogleTest(&argc, argv); - const char* directory = getenv("HOME"); - if (!directory) { - LOG(ERROR) << "Cannot get $HOME value"; - return 1; - } - testing::AddGlobalTestEnvironment( - new common_installer::SmokeEnvironment(directory)); - return RUN_ALL_TESTS(); -} diff --git a/src/unit_tests/test_samples/smoke/DeinstallationMode.wgt b/src/unit_tests/test_samples/smoke/DeinstallationMode.wgt deleted file mode 100644 index bf5b7d0..0000000 Binary files a/src/unit_tests/test_samples/smoke/DeinstallationMode.wgt and /dev/null differ diff --git a/src/unit_tests/test_samples/smoke/DeinstallationMode_Rollback.wgt b/src/unit_tests/test_samples/smoke/DeinstallationMode_Rollback.wgt deleted file mode 100644 index ea83495..0000000 Binary files a/src/unit_tests/test_samples/smoke/DeinstallationMode_Rollback.wgt and /dev/null differ diff --git a/src/unit_tests/test_samples/smoke/DeinstallationMode_Tpk.tpk b/src/unit_tests/test_samples/smoke/DeinstallationMode_Tpk.tpk deleted file mode 100644 index 955b8b5..0000000 Binary files a/src/unit_tests/test_samples/smoke/DeinstallationMode_Tpk.tpk and /dev/null differ diff --git a/src/unit_tests/test_samples/smoke/DeltaMode.delta b/src/unit_tests/test_samples/smoke/DeltaMode.delta deleted file mode 100644 index 2cf6105..0000000 Binary files a/src/unit_tests/test_samples/smoke/DeltaMode.delta and /dev/null differ diff --git a/src/unit_tests/test_samples/smoke/DeltaMode.wgt b/src/unit_tests/test_samples/smoke/DeltaMode.wgt deleted file mode 100644 index 2837000..0000000 Binary files a/src/unit_tests/test_samples/smoke/DeltaMode.wgt and /dev/null differ diff --git a/src/unit_tests/test_samples/smoke/DeltaMode_Tpk.delta b/src/unit_tests/test_samples/smoke/DeltaMode_Tpk.delta deleted file mode 100644 index bae36e2..0000000 Binary files a/src/unit_tests/test_samples/smoke/DeltaMode_Tpk.delta and /dev/null differ diff --git a/src/unit_tests/test_samples/smoke/DeltaMode_Tpk.tpk b/src/unit_tests/test_samples/smoke/DeltaMode_Tpk.tpk deleted file mode 100644 index b0a04ec..0000000 Binary files a/src/unit_tests/test_samples/smoke/DeltaMode_Tpk.tpk and /dev/null differ diff --git a/src/unit_tests/test_samples/smoke/InstallationMode.wgt b/src/unit_tests/test_samples/smoke/InstallationMode.wgt deleted file mode 100644 index 8fe0773..0000000 Binary files a/src/unit_tests/test_samples/smoke/InstallationMode.wgt and /dev/null differ diff --git a/src/unit_tests/test_samples/smoke/InstallationMode_GoodSignature.wgt b/src/unit_tests/test_samples/smoke/InstallationMode_GoodSignature.wgt deleted file mode 100644 index 87604e7..0000000 Binary files a/src/unit_tests/test_samples/smoke/InstallationMode_GoodSignature.wgt and /dev/null differ diff --git a/src/unit_tests/test_samples/smoke/InstallationMode_Rollback.wgt b/src/unit_tests/test_samples/smoke/InstallationMode_Rollback.wgt deleted file mode 100644 index 4742bbe..0000000 Binary files a/src/unit_tests/test_samples/smoke/InstallationMode_Rollback.wgt and /dev/null differ diff --git a/src/unit_tests/test_samples/smoke/InstallationMode_Tpk.tpk b/src/unit_tests/test_samples/smoke/InstallationMode_Tpk.tpk deleted file mode 100644 index 42dcc5d..0000000 Binary files a/src/unit_tests/test_samples/smoke/InstallationMode_Tpk.tpk and /dev/null differ diff --git a/src/unit_tests/test_samples/smoke/InstallationMode_WrongSignature.wgt b/src/unit_tests/test_samples/smoke/InstallationMode_WrongSignature.wgt deleted file mode 100644 index 8731bea..0000000 Binary files a/src/unit_tests/test_samples/smoke/InstallationMode_WrongSignature.wgt and /dev/null differ diff --git a/src/unit_tests/test_samples/smoke/RDSMode.wgt b/src/unit_tests/test_samples/smoke/RDSMode.wgt deleted file mode 100644 index 1245406..0000000 Binary files a/src/unit_tests/test_samples/smoke/RDSMode.wgt and /dev/null differ diff --git a/src/unit_tests/test_samples/smoke/RecoveryMode_ForInstallation.wgt b/src/unit_tests/test_samples/smoke/RecoveryMode_ForInstallation.wgt deleted file mode 100644 index 1244cf5..0000000 Binary files a/src/unit_tests/test_samples/smoke/RecoveryMode_ForInstallation.wgt and /dev/null differ diff --git a/src/unit_tests/test_samples/smoke/RecoveryMode_ForUpdate.wgt b/src/unit_tests/test_samples/smoke/RecoveryMode_ForUpdate.wgt deleted file mode 100644 index d1f0b4b..0000000 Binary files a/src/unit_tests/test_samples/smoke/RecoveryMode_ForUpdate.wgt and /dev/null differ diff --git a/src/unit_tests/test_samples/smoke/RecoveryMode_ForUpdate_2.wgt b/src/unit_tests/test_samples/smoke/RecoveryMode_ForUpdate_2.wgt deleted file mode 100644 index 37d89dd..0000000 Binary files a/src/unit_tests/test_samples/smoke/RecoveryMode_ForUpdate_2.wgt and /dev/null differ diff --git a/src/unit_tests/test_samples/smoke/RecoveryMode_Tpk_Installation.tpk b/src/unit_tests/test_samples/smoke/RecoveryMode_Tpk_Installation.tpk deleted file mode 100644 index 9ef0e27..0000000 Binary files a/src/unit_tests/test_samples/smoke/RecoveryMode_Tpk_Installation.tpk and /dev/null differ diff --git a/src/unit_tests/test_samples/smoke/RecoveryMode_Tpk_Update.tpk b/src/unit_tests/test_samples/smoke/RecoveryMode_Tpk_Update.tpk deleted file mode 100644 index 5a111e5..0000000 Binary files a/src/unit_tests/test_samples/smoke/RecoveryMode_Tpk_Update.tpk and /dev/null differ diff --git a/src/unit_tests/test_samples/smoke/RecoveryMode_Tpk_Update_2.tpk b/src/unit_tests/test_samples/smoke/RecoveryMode_Tpk_Update_2.tpk deleted file mode 100644 index 22db6cb..0000000 Binary files a/src/unit_tests/test_samples/smoke/RecoveryMode_Tpk_Update_2.tpk and /dev/null differ diff --git a/src/unit_tests/test_samples/smoke/UpdateMode.wgt b/src/unit_tests/test_samples/smoke/UpdateMode.wgt deleted file mode 100644 index 1c22e45..0000000 Binary files a/src/unit_tests/test_samples/smoke/UpdateMode.wgt and /dev/null differ diff --git a/src/unit_tests/test_samples/smoke/UpdateMode_2.wgt b/src/unit_tests/test_samples/smoke/UpdateMode_2.wgt deleted file mode 100644 index 39ab8a8..0000000 Binary files a/src/unit_tests/test_samples/smoke/UpdateMode_2.wgt and /dev/null differ diff --git a/src/unit_tests/test_samples/smoke/UpdateMode_Rollback.wgt b/src/unit_tests/test_samples/smoke/UpdateMode_Rollback.wgt deleted file mode 100644 index 3e090e4..0000000 Binary files a/src/unit_tests/test_samples/smoke/UpdateMode_Rollback.wgt and /dev/null differ diff --git a/src/unit_tests/test_samples/smoke/UpdateMode_Rollback_2.wgt b/src/unit_tests/test_samples/smoke/UpdateMode_Rollback_2.wgt deleted file mode 100644 index 20efef2..0000000 Binary files a/src/unit_tests/test_samples/smoke/UpdateMode_Rollback_2.wgt and /dev/null differ diff --git a/src/unit_tests/test_samples/smoke/UpdateMode_Tpk.tpk b/src/unit_tests/test_samples/smoke/UpdateMode_Tpk.tpk deleted file mode 100644 index 490b632..0000000 Binary files a/src/unit_tests/test_samples/smoke/UpdateMode_Tpk.tpk and /dev/null differ diff --git a/src/unit_tests/test_samples/smoke/UpdateMode_Tpk_2.tpk b/src/unit_tests/test_samples/smoke/UpdateMode_Tpk_2.tpk deleted file mode 100644 index 5bb17b6..0000000 Binary files a/src/unit_tests/test_samples/smoke/UpdateMode_Tpk_2.tpk and /dev/null differ diff --git a/src/unit_tests/test_samples/smoke/delta_dir/.rds_delta b/src/unit_tests/test_samples/smoke/delta_dir/.rds_delta deleted file mode 100644 index fb08dcc..0000000 --- a/src/unit_tests/test_samples/smoke/delta_dir/.rds_delta +++ /dev/null @@ -1,6 +0,0 @@ -#add -ADDED -#modify -MODIFIED -#delete -DELETED diff --git a/src/unit_tests/test_samples/smoke/delta_dir/ADDED b/src/unit_tests/test_samples/smoke/delta_dir/ADDED deleted file mode 100644 index e69de29..0000000 diff --git a/src/unit_tests/test_samples/smoke/delta_dir/MODIFIED b/src/unit_tests/test_samples/smoke/delta_dir/MODIFIED deleted file mode 100644 index 0cfbf08..0000000 --- a/src/unit_tests/test_samples/smoke/delta_dir/MODIFIED +++ /dev/null @@ -1 +0,0 @@ -2 diff --git a/src/unit_tests/test_samples/smoke/delta_dir/config.xml b/src/unit_tests/test_samples/smoke/delta_dir/config.xml deleted file mode 100644 index 66d7bdc..0000000 --- a/src/unit_tests/test_samples/smoke/delta_dir/config.xml +++ /dev/null @@ -1,9 +0,0 @@ - - - - - - - smokeapp1 - - diff --git a/src/wgt/CMakeLists.txt b/src/wgt/CMakeLists.txt deleted file mode 100644 index 2640375..0000000 --- a/src/wgt/CMakeLists.txt +++ /dev/null @@ -1,50 +0,0 @@ -# Target - sources -SET(SRCS - rds_parser.cc - step/step_check_settings_level.cc - step/step_check_wgt_background_category.cc - step/step_create_symbolic_link.cc - step/step_encrypt_resources.cc - step/step_generate_xml.cc - step/step_parse.cc - step/step_remove_encryption_data.cc - step/step_parse_recovery.cc - step/step_rds_parse.cc - step/step_rds_modify.cc - step/step_wgt_create_icons.cc - step/step_wgt_create_storage_directories.cc - step/step_wgt_copy_storage_directories.cc - step/step_wgt_resource_directory.cc - step/step_add_default_privileges.cc - wgt_app_query_interface.cc - wgt_installer.cc -) - -IF(WRT_LAUNCHER) - ADD_DEFINITIONS("-DWRT_LAUNCHER=\"${WRT_LAUNCHER}\"") - MESSAGE( "WRT LAUNCHER binary path is set to ${WRT_LAUNCHER}") -ELSE(WRT_LAUNCHER) - MESSAGE(FATAL_ERROR, "WRT LAUNCHER binary path is not set") -ENDIF(WRT_LAUNCHER) - -# Target - definition -ADD_LIBRARY(${TARGET_LIBNAME_WGT} STATIC ${SRCS}) -ADD_EXECUTABLE(${TARGET_WGT_BACKEND} "wgt_backend.cc") -# Target - includes -TARGET_INCLUDE_DIRECTORIES(${TARGET_LIBNAME_WGT} PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/../") -TARGET_INCLUDE_DIRECTORIES(${TARGET_WGT_BACKEND} PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/../") -# Target - deps -APPLY_PKG_CONFIG(${TARGET_LIBNAME_WGT} PUBLIC - MANIFEST_HANDLERS_DEPS - MANIFEST_PARSER_DEPS - PKGMGR_INSTALLER_DEPS - ENCRYPTION_DEPS -) - -# Target - in-package deps -TARGET_LINK_LIBRARIES(${TARGET_LIBNAME_WGT} PUBLIC ${TARGET_LIBNAME_COMMON}) -TARGET_LINK_LIBRARIES(${TARGET_WGT_BACKEND} PRIVATE ${TARGET_LIBNAME_WGT}) - -# Install -INSTALL(TARGETS ${TARGET_LIBNAME_WGT} DESTINATION ${LIB_INSTALL_DIR}) -INSTALL(TARGETS ${TARGET_WGT_BACKEND} DESTINATION ${BINDIR}) diff --git a/src/wgt/rds_parser.cc b/src/wgt/rds_parser.cc deleted file mode 100644 index 9f2fbb7..0000000 --- a/src/wgt/rds_parser.cc +++ /dev/null @@ -1,61 +0,0 @@ -// Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved -// Use of this source code is governed by a apache 2.0 license that can be -// found in the LICENSE file. - -#include "wgt/rds_parser.h" - -#include - -namespace { -const char kAdd[] = "#add"; -const char kModify[] = "#modify"; -const char kDelete[] = "#delete"; -} - -namespace wgt { -namespace rds_parser { - -RDSParser::RDSParser(const std::string& path_to_delta) - : path_to_delta_(path_to_delta) {} - -bool RDSParser::Parse() { - std::vector* current_container = nullptr; - std::string line; - - std::ifstream file_to_parse(path_to_delta_); - if (!file_to_parse.is_open()) - return false; - while (getline(file_to_parse, line)) { - if (line.compare(kDelete) == 0) { - current_container = &files_to_delete_; - continue; - } - if (line.compare(kAdd) == 0) { - current_container = &files_to_add_; - continue; - } - if (line.compare(kModify) == 0) { - current_container = &files_to_modify_; - continue; - } - if (current_container) - current_container->push_back(line); - } - file_to_parse.close(); - return true; -} - -const std::vector& RDSParser::files_to_modify() const { - return files_to_modify_; -} - -const std::vector& RDSParser::files_to_add() const { - return files_to_add_; -} - -const std::vector& RDSParser::files_to_delete() const { - return files_to_delete_; -} - -} // namespace rds_parser -} // namespace wgt diff --git a/src/wgt/rds_parser.h b/src/wgt/rds_parser.h deleted file mode 100644 index 7c412d1..0000000 --- a/src/wgt/rds_parser.h +++ /dev/null @@ -1,63 +0,0 @@ -// Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved -// Use of this source code is governed by a apache 2.0 license that can be -// found in the LICENSE file. - -#ifndef WGT_RDS_PARSER_H_ -#define WGT_RDS_PARSER_H_ - -#include -#include -namespace wgt { -namespace rds_parser { - -/** - * \brief Parse RDS config file - */ -class RDSParser { - public: - /** - * \brief Explicit constructor - * - * \param path_to_delta path to directory - */ - explicit RDSParser(const std::string& path_to_delta); - - /** - * \brief Parse package xml - * - * \return true if parsing was successful - */ - bool Parse(); - - /** - * \brief Accessor to vector of files to modify - * - * \return files to modify - */ - const std::vector& files_to_modify() const; - - /** - * \brief Accessor to vector of files to add - * - * \return files to add - */ - const std::vector& files_to_add() const; - - /** - * \brief Accessor to vector of files to delete - * - * \return files to delete - */ - const std::vector& files_to_delete() const; - - private: - std::string path_to_delta_; - std::vector files_to_modify_; - std::vector files_to_add_; - std::vector files_to_delete_; -}; - -} // namespace rds_parser -} // namespace wgt - -#endif // WGT_RDS_PARSER_H_ diff --git a/src/wgt/step/step_add_default_privileges.cc b/src/wgt/step/step_add_default_privileges.cc deleted file mode 100644 index 18eb902..0000000 --- a/src/wgt/step/step_add_default_privileges.cc +++ /dev/null @@ -1,38 +0,0 @@ -// Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved -// Use of this source code is governed by a apache 2.0 license that can be -// found in the LICENSE file. - -#include "wgt/step/step_add_default_privileges.h" - -#include - -#include -#include -#include - -namespace { - -const char kPrivForWebApp[] = - "http://tizen.org/privilege/internal/webappdefault"; - -} // namespace - -namespace wgt { -namespace security { - -common_installer::Step::Status StepAddDefaultPrivileges::precheck() { - if (!context_->manifest_data.get()) { - LOG(ERROR) << "Manifest data is not set"; - return Status::ERROR; - } - return Status::OK; -} - -common_installer::Step::Status StepAddDefaultPrivileges::process() { - manifest_x* m = context_->manifest_data.get(); - m->privileges = g_list_append(m->privileges, strdup(kPrivForWebApp)); - return Status::OK; -} - -} // namespace security -} // namespace wgt diff --git a/src/wgt/step/step_add_default_privileges.h b/src/wgt/step/step_add_default_privileges.h deleted file mode 100644 index 1fd1d79..0000000 --- a/src/wgt/step/step_add_default_privileges.h +++ /dev/null @@ -1,59 +0,0 @@ -// Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved -// Use of this source code is governed by a apache 2.0 license that can be -// found in the LICENSE file. - -#ifndef WGT_STEP_STEP_ADD_DEFAULT_PRIVILEGES_H_ -#define WGT_STEP_STEP_ADD_DEFAULT_PRIVILEGES_H_ - -#include - -#include "common/app_installer.h" -#include "common/installer_context.h" -#include "common/step/step.h" - -namespace wgt { -namespace security { - -/** - * \brief Step that add default privileges during installation - */ -class StepAddDefaultPrivileges : public common_installer::Step { - public: - using Step::Step; - - /** - * \brief Add default privileges - * - * \return Status::OK - */ - Status process() override; - - /** - * \brief Empty method - * - * \return Status::OK - */ - Status clean() override { return Status::OK; } - - /** - * \brief Empty method - * - * \return Status::OK - */ - Status undo() override { return Status::OK; } - - /** - * \brief Check requirements for this step - * - * \return Status::ERROR when rmanifest data are missing, - * Status::OK otherwise - */ - Status precheck() override; - - SCOPE_LOG_TAG(AddDefaultPrivileges) -}; - -} // namespace security -} // namespace wgt - -#endif // WGT_STEP_STEP_ADD_DEFAULT_PRIVILEGES_H_ diff --git a/src/wgt/step/step_check_settings_level.cc b/src/wgt/step/step_check_settings_level.cc deleted file mode 100644 index 664e376..0000000 --- a/src/wgt/step/step_check_settings_level.cc +++ /dev/null @@ -1,47 +0,0 @@ -// Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved -// Use of this source code is governed by a apache 2.0 license that can be -// found in the LICENSE file. - -#include "wgt/step/step_check_settings_level.h" - -#include -#include - -#include - -#include "wgt/wgt_backend_data.h" - -namespace { - -bool ValidateSettingsForLevel(common_installer::PrivilegeLevel level, - const wgt::parse::SettingInfo& settings) { - if (settings.background_vibration()) { - common_installer::PrivilegeLevel required_level = - common_installer::PrivilegeLevel::PARTNER; - if (!common_installer::SatifiesPrivilegeLevel(required_level, level)) { - LOG(ERROR) << "background_vibration requires visibility level: " - << common_installer::PrivilegeLevelToString(required_level); - return false; - } - LOG(INFO) << "Setting: 'background-vibration' allowed"; - } - return true; -} - -} // namespace - -namespace wgt { -namespace security { - -common_installer::Step::Status StepCheckSettingsLevel::process() { - if (!ValidateSettingsForLevel(context_->privilege_level.get(), - static_cast( - context_->backend_data.get())->settings.get())) { - return Status::ERROR; - } - LOG(INFO) << "Settings privilege level checked"; - return Status::OK; -} - -} // namespace security -} // namespace wgt diff --git a/src/wgt/step/step_check_settings_level.h b/src/wgt/step/step_check_settings_level.h deleted file mode 100644 index 9e903de..0000000 --- a/src/wgt/step/step_check_settings_level.h +++ /dev/null @@ -1,59 +0,0 @@ -// Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved -// Use of this source code is governed by a apache 2.0 license that can be -// found in the LICENSE file. - -#ifndef WGT_STEP_STEP_CHECK_SETTINGS_LEVEL_H_ -#define WGT_STEP_STEP_CHECK_SETTINGS_LEVEL_H_ - -#include - -#include "common/app_installer.h" -#include "common/installer_context.h" -#include "common/step/step.h" - -namespace wgt { -namespace security { - -/** - * \brief Step that check privileges level for settings - */ -class StepCheckSettingsLevel : public common_installer::Step { - public: - using Step::Step; - - /** - * \brief Check privileges level for settings - * - * \return Status::ERROR when invalid privileges detected, - * Status::OK otherwise - */ - Status process() override; - - /** - * \brief Empty method - * - * \return Status::OK - */ - Status clean() override { return Status::OK; } - - /** - * \brief Empty method - * - * \return Status::OK - */ - Status undo() override { return Status::OK; } - - /** - * \brief Empty method - * - * \return Status::OK - */ - Status precheck() override { return Status::OK; } - - SCOPE_LOG_TAG(CheckSettingsLevel) -}; - -} // namespace security -} // namespace wgt - -#endif // WGT_STEP_STEP_CHECK_SETTINGS_LEVEL_H_ diff --git a/src/wgt/step/step_check_wgt_background_category.cc b/src/wgt/step/step_check_wgt_background_category.cc deleted file mode 100644 index 5a1265f..0000000 --- a/src/wgt/step/step_check_wgt_background_category.cc +++ /dev/null @@ -1,29 +0,0 @@ -// Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved -// Use of this source code is governed by a apache 2.0 license that can be -// found in the LICENSE file. - -#include - -#include "common/installer_context.h" -#include "wgt/step/step_check_wgt_background_category.h" -#include "wgt/wgt_backend_data.h" - -namespace { -namespace ci_sec = common_installer::security; -} // namespace - -namespace wgt { -namespace security { - -StepCheckWgtBackgroundCategory::StepCheckWgtBackgroundCategory( - common_installer::InstallerContext* context) : - ci_sec::StepCheckBackgroundCategory(context) {} - -bool StepCheckWgtBackgroundCategory::GetBackgroundSupport() { - const wgt::parse::SettingInfo& settings = static_cast( - context_->backend_data.get())->settings.get(); - return settings.background_support_enabled(); -} - -} // namespace security -} // namespace wgt diff --git a/src/wgt/step/step_check_wgt_background_category.h b/src/wgt/step/step_check_wgt_background_category.h deleted file mode 100644 index 68a63d8..0000000 --- a/src/wgt/step/step_check_wgt_background_category.h +++ /dev/null @@ -1,32 +0,0 @@ -// Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved -// Use of this source code is governed by a apache 2.0 license that can be -// found in the LICENSE file. - -#ifndef WGT_STEP_STEP_CHECK_WGT_BACKGROUND_CATEGORY_H_ -#define WGT_STEP_STEP_CHECK_WGT_BACKGROUND_CATEGORY_H_ - -#include - -#include "common/step/step_check_background_category.h" - -namespace wgt { -namespace security { - -/** - * \brief This step check background category value and modify it depending on - * required version, cert level, background support, and value itself - */ -class StepCheckWgtBackgroundCategory : - public common_installer::security::StepCheckBackgroundCategory { - public: - explicit StepCheckWgtBackgroundCategory( - common_installer::InstallerContext* context); - - protected: - bool GetBackgroundSupport() override; -}; - -} // namespace security -} // namespace wgt - -#endif // WGT_STEP_STEP_CHECK_WGT_BACKGROUND_CATEGORY_H_ diff --git a/src/wgt/step/step_create_symbolic_link.cc b/src/wgt/step/step_create_symbolic_link.cc deleted file mode 100644 index 6d53415..0000000 --- a/src/wgt/step/step_create_symbolic_link.cc +++ /dev/null @@ -1,71 +0,0 @@ -/* 2014, Copyright © Eurogiciel Coporation, APACHE-2.0, see LICENSE file */ -// Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved -// Use of this source code is governed by a apache 2.0 license that can be -// found in the LICENSE file. - -#include "wgt/step/step_create_symbolic_link.h" - -#include -#include - -#include -#include -#include -#include -#include - -#include "common/utils/file_util.h" -#include "common/utils/glist_range.h" - -namespace { - -const char kWrtServiceBinaryPath[] = "/usr/bin/wrt-service"; - -} // namespace - -namespace wgt { -namespace filesystem { - -namespace bf = boost::filesystem; - -common_installer::Step::Status StepCreateSymbolicLink::process() { - assert(context_->manifest_data.get()); - boost::system::error_code error; - for (application_x* app : - GListRange(context_->manifest_data.get()->application)) { - // binary is a symbolic link named and is located in / - bf::path exec_path = - context_->pkg_path.get() - / bf::path("bin"); - common_installer::CreateDir(exec_path); - - exec_path /= bf::path(app->appid); - - if (strcmp(app->component_type, "uiapp") == 0) { - bf::create_symlink(bf::path(WRT_LAUNCHER), exec_path, error); - } else { - bf::create_symlink(kWrtServiceBinaryPath, exec_path, error); - } - if (error) { - LOG(ERROR) << "Failed to set symbolic link " - << boost::system::system_error(error).what(); - return Step::Status::ERROR; - } - } - LOG(DEBUG) << "Successfully parse tizen manifest xml"; - - return Status::OK; -} - -common_installer::Step::Status StepCreateSymbolicLink::undo() { - for (application_x* app : - GListRange(context_->manifest_data.get()->application)) { - bf::path exec_path = context_->pkg_path.get() / "bin" / app->appid; - if (bf::exists(exec_path)) - bf::remove_all(exec_path); - } - return Status::OK; -} - -} // namespace filesystem -} // namespace wgt diff --git a/src/wgt/step/step_create_symbolic_link.h b/src/wgt/step/step_create_symbolic_link.h deleted file mode 100644 index 470c065..0000000 --- a/src/wgt/step/step_create_symbolic_link.h +++ /dev/null @@ -1,61 +0,0 @@ -// Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved -// Use of this source code is governed by a apache 2.0 license that can be -// found in the LICENSE file. - -#ifndef WGT_STEP_STEP_CREATE_SYMBOLIC_LINK_H_ -#define WGT_STEP_STEP_CREATE_SYMBOLIC_LINK_H_ - -#include - -#include - -#include "common/app_installer.h" -#include "common/installer_context.h" -#include "common/step/step.h" - -namespace wgt { -namespace filesystem { - -/** - * \brief Step that create symbolic link to application - */ -class StepCreateSymbolicLink : public common_installer::Step { - public: - using Step::Step; - - /** - * \brief Create symbolic link - * - * \return Status::ERROR when failed to create symbolic link, - * Status::OK otherwise - */ - Status process() override; - - /** - * \brief Empty method - * - * \return Status::OK - */ - Status clean() override { return Status::OK; } - - /** - * \brief Delete created symbolic link - * - * \return Status::OK - */ - Status undo() override; - - /** - * \brief Empty method - * - * \return Status::OK - */ - Status precheck() override { return Status::OK; } - - SCOPE_LOG_TAG(SymbolicLink) -}; - -} // namespace filesystem -} // namespace wgt - -#endif // WGT_STEP_STEP_CREATE_SYMBOLIC_LINK_H_ diff --git a/src/wgt/step/step_encrypt_resources.cc b/src/wgt/step/step_encrypt_resources.cc deleted file mode 100644 index 482b324..0000000 --- a/src/wgt/step/step_encrypt_resources.cc +++ /dev/null @@ -1,214 +0,0 @@ -// Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved -// Use of this source code is governed by a apache 2.0 license that can be -// found in the LICENSE file. - -#include "wgt/step/step_encrypt_resources.h" - -#include - -#include -#include - -#include - -#include -#include -#include -#include -#include - -#include "common/utils/file_util.h" - -namespace { - -const std::set encryptSet { ".html", ".htm", ".css", ".js"}; - -} // namespace - - -namespace wgt { -namespace encrypt { - -namespace bf = boost::filesystem; -namespace bs = boost::system; - -common_installer::Step::Status StepEncryptResources::precheck() { - backend_data_ = static_cast(context_->backend_data.get()); - if (!backend_data_) { - LOG(ERROR) << "no backend data"; - return common_installer::Step::Status::ERROR; - } - - input_ = context_->unpacked_dir_path.get(); - - if (input_.empty()) { - LOG(ERROR) << "unpacked_dir_path attribute is empty"; - return Step::Status::INVALID_VALUE; - } - if (!bf::exists(input_)) { - LOG(ERROR) << "unpacked_dir_path (" << input_ << ") path does not exist"; - return Step::Status::INVALID_VALUE; - } - - return common_installer::Step::Status::OK; -} - -common_installer::Step::Status StepEncryptResources::process() { - if (!backend_data_->settings.get().encryption_enabled()) { - LOG(DEBUG) << "no encryption"; - return common_installer::Step::Status::OK; - } - LOG(DEBUG) << "Encrypting"; - - if (!Encrypt(input_)) { - LOG(ERROR) << "Error during encryption"; - return common_installer::Step::Status::ERROR; - } - - return common_installer::Step::Status::OK; -} - -bool StepEncryptResources::Encrypt(const bf::path &src) { - // traversing through src dir (recurrence if subdir found) - // for every file found, check if it should be encrypted (ToBeEncrypted) - // if yes, encrypt it (and replace original one) - // if not, leave it - for (bf::directory_iterator file(src); - file != bf::directory_iterator(); - ++file) { - bs::error_code error_code; - bf::path current(file->path()); - - bool is_dir = bf::is_directory(current, error_code); - if (error_code) - return false; - if (is_dir) { - if (!Encrypt(current)) - return false; - continue; - } - - bool is_sym = bf::is_symlink(current, error_code); - if (error_code) - return false; - if (is_sym) - continue; // TODO(p.sikorski) is it enough? - - // it is regular file (not dir, not symlink) - if (ToBeEncrypted(current)) { - LOG(INFO) << "File for encryption: " << current; - if (!EncryptFile(current)) - return false; - } - } - return true; -} - -bool StepEncryptResources::EncryptFile(const bf::path &src) { - FILE *input = fopen(src.string().c_str(), "rb"); - if (!input) { - LOG(ERROR) << "Cannot open file for encryption: " << src; - return false; - } - - // read size - fseek(input , 0 , SEEK_END); - size_t length = ftell(input); - - // don't encrypt empty files because libwebappenc doesn't support it - if (length == 0) { - fclose(input); - return true; - } - - rewind(input); - - char *input_buffer = new char[length]; - if (length != fread(input_buffer, sizeof(char), length, input)) { - LOG(ERROR) << "Read error, file: " << src; - fclose(input); - delete []input_buffer; - return false; - } - fclose(input); - - unsigned char* encrypted_data = nullptr; - size_t enc_data_len = 0; - // TODO(p.sikorski) check if it is Preloaded - wae_app_type_e enc_type = - context_->request_mode.get() == common_installer::RequestMode::GLOBAL ? - WAE_DOWNLOADED_GLOBAL_APP : WAE_DOWNLOADED_NORMAL_APP; - - - int ret = wae_encrypt_web_application( - context_->pkgid.get().c_str(), - enc_type, - reinterpret_cast(input_buffer), - length, - &encrypted_data, - &enc_data_len); - delete []input_buffer; - if (WAE_ERROR_NONE != ret) { - switch (ret) { - case WAE_ERROR_INVALID_PARAMETER: - LOG(ERROR) << "Error during encrypting: WAE_ERROR_INVALID_PARAMETER"; - break; - case WAE_ERROR_PERMISSION_DENIED: - LOG(ERROR) << "Error during encrypting: WAE_ERROR_PERMISSION_DENIED"; - break; - case WAE_ERROR_NO_KEY: - LOG(ERROR) << "Error during encrypting: WAE_ERROR_NO_KEY"; - break; - case WAE_ERROR_KEY_MANAGER: - LOG(ERROR) << "Error during encrypting: WAE_ERROR_KEY_MANAGER"; - break; - case WAE_ERROR_CRYPTO: - LOG(ERROR) << "Error during encrypting: WAE_ERROR_CRYPTO"; - break; - case WAE_ERROR_UNKNOWN: - LOG(ERROR) << "Error during encrypting: WAE_ERROR_UNKNOWN"; - break; - default: - LOG(ERROR) << "Error during encrypting: UNKNOWN"; - break; - } - return false; - } - - // original file is treated as destination! - FILE *output = fopen(src.string().c_str(), "wb"); - if (!output) { - LOG(ERROR) << "Cannot create encrypted file: " << src; - free(encrypted_data); - return false; - } - - if (enc_data_len != fwrite(reinterpret_cast(encrypted_data), - sizeof(char), - enc_data_len, - output)) { - LOG(ERROR) << "Write error, file: " << src; - free(encrypted_data); - fclose(output); - return false; - } - - - fclose(output); - free(encrypted_data); - return true; -} - -bool StepEncryptResources::ToBeEncrypted(const bf::path &file) { - size_t found_key = file.string().rfind("."); - if (std::string::npos != found_key) { - std::string mimeType = file.string().substr(found_key); - std::transform(mimeType.begin(), mimeType.end(), mimeType.begin(), - ::tolower); - return encryptSet.count(mimeType) > 0; - } - return false; -} - -} // namespace encrypt -} // namespace wgt diff --git a/src/wgt/step/step_encrypt_resources.h b/src/wgt/step/step_encrypt_resources.h deleted file mode 100644 index 9692c05..0000000 --- a/src/wgt/step/step_encrypt_resources.h +++ /dev/null @@ -1,66 +0,0 @@ -// Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved -// Use of this source code is governed by a apache 2.0 license that can be -// found in the LICENSE file. - -#ifndef WGT_STEP_STEP_ENCRYPT_RESOURCES_H_ -#define WGT_STEP_STEP_ENCRYPT_RESOURCES_H_ - -#include - -#include - -#include "common/step/step.h" -#include "wgt/wgt_backend_data.h" - -namespace wgt { -namespace encrypt { - -/** - * \brief Step that encrypt application resources files if flagged to do so - */ -class StepEncryptResources : public common_installer::Step { - public: - using Step::Step; - - /** - * \brief Encrypt files - * - * \return Status::ERROR when error occurred during encryption, - * Status::OK otherwise - */ - Status process() override; - - /** - * \brief Empty method - * - * \return Status::OK - */ - Status clean() override { return Status::OK; } - - /** - * \brief Empty method - * - * \return Status::OK - */ - Status undo() override { return Status::OK; } - - /** - * \brief Check requirements for this step - * - * \return Status::ERROR when manifest data are missing, - * Status::INVALID_VALUE when requirements are not meet, - * Status::OK otherwise - */ - Status precheck() override; - - private: - bool Encrypt(const boost::filesystem::path &src); - bool EncryptFile(const boost::filesystem::path &src); - bool ToBeEncrypted(const boost::filesystem::path &file); - WgtBackendData* backend_data_; - boost::filesystem::path input_; - SCOPE_LOG_TAG(EncryptResources) -}; -} // namespace encrypt -} // namespace wgt -#endif // WGT_STEP_STEP_ENCRYPT_RESOURCES_H_ diff --git a/src/wgt/step/step_generate_xml.cc b/src/wgt/step/step_generate_xml.cc deleted file mode 100644 index fbb5d14..0000000 --- a/src/wgt/step/step_generate_xml.cc +++ /dev/null @@ -1,492 +0,0 @@ -/* 2014, Copyright © Intel Coporation, license APACHE-2.0, see LICENSE file */ -// Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved -// Use of this source code is governed by a apache 2.0 license that can be -// found in the LICENSE file. - -#include "wgt/step/step_generate_xml.h" - -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include -#include - -#include "common/utils/file_util.h" -#include "common/utils/glist_range.h" - -namespace bs = boost::system; -namespace bf = boost::filesystem; - -namespace { - -void WriteUIApplicationAttributes( - xmlTextWriterPtr writer, application_x *app) { - xmlTextWriterWriteAttribute(writer, BAD_CAST "taskmanage", - BAD_CAST "true"); - if (app->nodisplay) - xmlTextWriterWriteAttribute(writer, BAD_CAST "nodisplay", - BAD_CAST app->nodisplay); - if (app->multiple) - xmlTextWriterWriteAttribute(writer, BAD_CAST "multiple", - BAD_CAST app->multiple); - if (app->launch_mode && strlen(app->launch_mode)) - xmlTextWriterWriteAttribute(writer, BAD_CAST "launch_mode", - BAD_CAST app->launch_mode); - if (app->ui_gadget && strlen(app->ui_gadget)) - xmlTextWriterWriteAttribute(writer, BAD_CAST "ui-gadget", - BAD_CAST app->ui_gadget); - if (app->submode && strlen(app->submode)) - xmlTextWriterWriteAttribute(writer, BAD_CAST "submode", - BAD_CAST app->submode); - if (app->submode_mainid && strlen(app->submode_mainid)) - xmlTextWriterWriteAttribute(writer, BAD_CAST "submode-mainid", - BAD_CAST app->submode_mainid); - if (app->indicatordisplay && strlen(app->indicatordisplay)) - xmlTextWriterWriteAttribute(writer, BAD_CAST "indicatordisplay", - BAD_CAST app->indicatordisplay); - if (app->portraitimg && strlen(app->portraitimg)) - xmlTextWriterWriteAttribute(writer, BAD_CAST "portrait-effectimage", - BAD_CAST app->portraitimg); - if (app->landscapeimg && strlen(app->landscapeimg)) - xmlTextWriterWriteAttribute(writer, BAD_CAST "landscape-effectimage", - BAD_CAST app->landscapeimg); - if (app->effectimage_type && strlen(app->effectimage_type)) - xmlTextWriterWriteAttribute(writer, BAD_CAST "effectimage-type", - BAD_CAST app->effectimage_type); - if (app->hwacceleration && strlen(app->hwacceleration)) - xmlTextWriterWriteAttribute(writer, BAD_CAST "hwacceleration", - BAD_CAST app->hwacceleration); -} - -void WriteServiceApplicationAttributes( - xmlTextWriterPtr writer, application_x *app) { - xmlTextWriterWriteAttribute(writer, BAD_CAST "auto-restart", - BAD_CAST(app->autorestart ? app->autorestart : "false")); - xmlTextWriterWriteAttribute(writer, BAD_CAST "on-boot", - BAD_CAST(app->onboot ? app->onboot : "false")); - xmlTextWriterWriteAttribute(writer, BAD_CAST "taskmanage", - BAD_CAST "false"); -} - -void WriteWidgetApplicationAttributes( - xmlTextWriterPtr writer, application_x *app) { - if (app->nodisplay) - xmlTextWriterWriteAttribute(writer, BAD_CAST "nodisplay", - BAD_CAST app->nodisplay); - if (app->multiple) - xmlTextWriterWriteAttribute(writer, BAD_CAST "multiple", - BAD_CAST app->multiple); -} - -} // namespace - -namespace wgt { -namespace pkgmgr { - -common_installer::Step::Status StepGenerateXml::GenerateApplicationCommonXml( - application_x* app, xmlTextWriterPtr writer, AppCompType type) { - xmlTextWriterWriteAttribute(writer, BAD_CAST "appid", BAD_CAST app->appid); - - // binary is a symbolic link named and is located in / - bf::path exec_path = context_->pkg_path.get() - / bf::path("bin") / bf::path(app->appid); - xmlTextWriterWriteAttribute(writer, BAD_CAST "exec", - BAD_CAST exec_path.string().c_str()); - if (app->type) - xmlTextWriterWriteAttribute(writer, BAD_CAST "type", BAD_CAST app->type); - else - xmlTextWriterWriteAttribute(writer, BAD_CAST "type", BAD_CAST "capp"); - - if (app->process_pool && strlen(app->process_pool)) - xmlTextWriterWriteAttribute(writer, BAD_CAST "process-pool", - BAD_CAST app->process_pool); - // app-specific attributes - switch (type) { - case AppCompType::UIAPP: - WriteServiceApplicationAttributes(writer, app); - break; - case AppCompType::SVCAPP: - WriteUIApplicationAttributes(writer, app); - break; - case AppCompType::WIDGETAPP: - WriteWidgetApplicationAttributes(writer, app); - break; - } - - for (label_x* label : GListRange(app->label)) { - xmlTextWriterStartElement(writer, BAD_CAST "label"); - if (label->lang && strcmp(DEFAULT_LOCALE, label->lang) != 0) { - xmlTextWriterWriteAttribute(writer, BAD_CAST "xml:lang", - BAD_CAST label->lang); - } - xmlTextWriterWriteString(writer, BAD_CAST label->name); - xmlTextWriterEndElement(writer); - } - - // icon is renamed to - if (app->icon) { - icon_x* iconx = reinterpret_cast(app->icon->data); - bf::path app_icon = context_->pkg_path.get(); - // TODO(t.iwanek): type should not be used here - if (context_->pkg_type.get() == "wgt") { - app_icon /= "res/wgt"; - } else { - app_icon /= "shared/res"; - } - app_icon /= iconx->text; - bf::path icon = app->appid; - if (app_icon.has_extension()) - icon += app_icon.extension(); - else - icon += bf::path(".png"); - - if (bf::exists(app_icon)) { - xmlTextWriterWriteFormatElement(writer, BAD_CAST "icon", - "%s", BAD_CAST icon.c_str()); - } - } else { - // Default icon setting is role of the platform - LOG(DEBUG) << "Icon was not found in package"; - } - - for (image_x* image : GListRange(app->image)) { - xmlTextWriterStartElement(writer, BAD_CAST "image"); - xmlTextWriterWriteAttribute(writer, BAD_CAST "name", - BAD_CAST image->name); - if (image->lang && strcmp(DEFAULT_LOCALE, image->lang) != 0) { - xmlTextWriterWriteAttribute(writer, BAD_CAST "xml:lang", - - BAD_CAST image->lang); - } - if (image->section) - xmlTextWriterWriteAttribute(writer, BAD_CAST "section", - BAD_CAST image->section); - xmlTextWriterEndElement(writer); - } - - for (appcontrol_x* appc : GListRange(app->appcontrol)) { - xmlTextWriterStartElement(writer, BAD_CAST "app-control"); - - if (appc->operation) { - xmlTextWriterStartElement(writer, BAD_CAST "operation"); - xmlTextWriterWriteAttribute(writer, BAD_CAST "name", - BAD_CAST appc->operation); - xmlTextWriterEndElement(writer); - } - - if (appc->uri) { - xmlTextWriterStartElement(writer, BAD_CAST "uri"); - xmlTextWriterWriteAttribute(writer, BAD_CAST "name", - BAD_CAST appc->uri); - xmlTextWriterEndElement(writer); - } - - if (appc->mime) { - xmlTextWriterStartElement(writer, BAD_CAST "mime"); - xmlTextWriterWriteAttribute(writer, BAD_CAST "name", - BAD_CAST appc->mime); - xmlTextWriterEndElement(writer); - } - - xmlTextWriterEndElement(writer); - } - - for (datacontrol_x* datacontrol : - GListRange(app->datacontrol)) { - xmlTextWriterStartElement(writer, BAD_CAST "datacontrol"); - if (datacontrol->access) { - xmlTextWriterWriteAttribute(writer, BAD_CAST "access", - BAD_CAST datacontrol->access); - } - if (datacontrol->providerid) { - xmlTextWriterWriteAttribute(writer, BAD_CAST "providerid", - BAD_CAST datacontrol->providerid); - } - if (datacontrol->type) { - xmlTextWriterWriteAttribute(writer, BAD_CAST "type", - BAD_CAST datacontrol->type); - } - xmlTextWriterEndElement(writer); - } - - for (metadata_x* meta : GListRange(app->metadata)) { - xmlTextWriterStartElement(writer, BAD_CAST "metadata"); - xmlTextWriterWriteAttribute(writer, BAD_CAST "key", - BAD_CAST meta->key); - if (meta->value) - xmlTextWriterWriteAttribute(writer, BAD_CAST "value", - BAD_CAST meta->value); - xmlTextWriterEndElement(writer); - } - - for (const char* category : GListRange(app->category)) { - xmlTextWriterStartElement(writer, BAD_CAST "category"); - xmlTextWriterWriteAttribute(writer, BAD_CAST "name", BAD_CAST category); - xmlTextWriterEndElement(writer); - } - - for (const char* background_category : GListRange( - app->background_category)) { - xmlTextWriterStartElement(writer, BAD_CAST "background-category"); - xmlTextWriterWriteAttribute(writer, BAD_CAST "value", - BAD_CAST background_category); - xmlTextWriterEndElement(writer); - } - - return Step::Status::OK; -} - -common_installer::Step::Status StepGenerateXml::precheck() { - if (!context_->manifest_data.get()) { - LOG(ERROR) << "manifest_data attribute is empty"; - return Step::Status::INVALID_VALUE; - } - if (context_->pkgid.get().empty()) { - LOG(ERROR) << "pkgid attribute is empty"; - return Step::Status::INVALID_VALUE; } - - if (!context_->manifest_data.get()->application) { - LOG(ERROR) << "No application in package"; - return Step::Status::INVALID_VALUE; - } - // TODO(p.sikorski) check context_->uid.get() - - return Step::Status::OK; -} - -common_installer::Step::Status StepGenerateXml::process() { - bf::path xml_path = bf::path(getUserManifestPath(context_->uid.get())) - / bf::path(context_->pkgid.get()); - xml_path += ".xml"; - context_->xml_path.set(xml_path.string()); - - bs::error_code error; - if (!bf::exists(xml_path.parent_path(), error)) { - if (!common_installer::CreateDir(xml_path.parent_path())) { - LOG(ERROR) << - "Directory for manifest xml is missing and cannot be created"; - return Status::ERROR; - } - } - - xmlTextWriterPtr writer; - - writer = xmlNewTextWriterFilename(context_->xml_path.get().c_str(), 0); - if (!writer) { - LOG(ERROR) << "Failed to create new file"; - return Step::Status::ERROR; - } - - xmlTextWriterStartDocument(writer, nullptr, nullptr, nullptr); - - xmlTextWriterSetIndent(writer, 1); - - // add manifest Element - xmlTextWriterStartElement(writer, BAD_CAST "manifest"); - - xmlTextWriterWriteAttribute(writer, BAD_CAST "xmlns", - BAD_CAST "http://tizen.org/ns/packages"); - xmlTextWriterWriteAttribute(writer, BAD_CAST "package", - BAD_CAST context_->manifest_data.get()->package); - xmlTextWriterWriteAttribute(writer, BAD_CAST "type", - BAD_CAST context_->manifest_data.get()->type); - xmlTextWriterWriteAttribute(writer, BAD_CAST "version", - BAD_CAST context_->manifest_data.get()->version); - xmlTextWriterWriteAttribute(writer, BAD_CAST "api-version", - BAD_CAST context_->manifest_data.get()->api_version); - xmlTextWriterWriteAttribute(writer, BAD_CAST "nodisplay-setting", - BAD_CAST context_->manifest_data.get()->nodisplay_setting); - - for (label_x* label : - GListRange(context_->manifest_data.get()->label)) { - xmlTextWriterStartElement(writer, BAD_CAST "label"); - if (label->lang && strcmp(DEFAULT_LOCALE, label->lang) != 0) { - xmlTextWriterWriteAttribute(writer, BAD_CAST "xml:lang", - BAD_CAST label->lang); - } - xmlTextWriterWriteString(writer, BAD_CAST label->name); - xmlTextWriterEndElement(writer); - } - - for (author_x* author : - GListRange(context_->manifest_data.get()->author)) { - xmlTextWriterStartElement(writer, BAD_CAST "author"); - if (author->email && strlen(author->email)) { - xmlTextWriterWriteAttribute(writer, BAD_CAST "email", - BAD_CAST author->email); - } - if (author->href && strlen(author->href)) { - xmlTextWriterWriteAttribute(writer, BAD_CAST "href", - BAD_CAST author->href); - } - xmlTextWriterWriteString(writer, BAD_CAST author->text); - xmlTextWriterEndElement(writer); - } - - for (description_x* description : - GListRange(context_->manifest_data.get()->description)) { - xmlTextWriterStartElement(writer, BAD_CAST "description"); - if (description->lang && strcmp(DEFAULT_LOCALE, description->lang) != 0) { - xmlTextWriterWriteAttribute(writer, BAD_CAST "xml:lang", - BAD_CAST description->lang); - } - xmlTextWriterWriteString(writer, BAD_CAST description->text); - xmlTextWriterEndElement(writer); - } - - // add application - for (application_x* app : - GListRange(context_->manifest_data.get()->application)) { - AppCompType type; - if (strcmp(app->component_type, "uiapp") == 0) { - type = AppCompType::UIAPP; - xmlTextWriterStartElement(writer, BAD_CAST "ui-application"); - } else if (strcmp(app->component_type, "svcapp") == 0) { - type = AppCompType::SVCAPP; - xmlTextWriterStartElement(writer, BAD_CAST "service-application"); - } else if (strcmp(app->component_type, "widgetapp") == 0) { - type = AppCompType::WIDGETAPP; - xmlTextWriterStartElement(writer, BAD_CAST "widget-application"); - } else { - LOG(ERROR) << "Unknown application component_type"; - xmlFreeTextWriter(writer); - return Status::ERROR; - } - GenerateApplicationCommonXml(app, writer, type); - xmlTextWriterEndElement(writer); - } - - // add privilege element - if (context_->manifest_data.get()->privileges) { - xmlTextWriterStartElement(writer, BAD_CAST "privileges"); - for (const char* priv : - GListRange(context_->manifest_data.get()->privileges)) { - xmlTextWriterWriteFormatElement(writer, BAD_CAST "privilege", - "%s", BAD_CAST priv); - } - xmlTextWriterEndElement(writer); - } - - const auto& accounts = - context_->manifest_plugins_data.get().account_info.get().accounts(); - if (!accounts.empty()) { - xmlTextWriterStartElement(writer, BAD_CAST "account"); - // add account info - for (auto& account : accounts) { - xmlTextWriterStartElement(writer, BAD_CAST "account-provider"); - - xmlTextWriterWriteAttribute(writer, BAD_CAST "appid", - BAD_CAST account.appid.c_str()); - - if (!account.providerid.empty()) - xmlTextWriterWriteAttribute(writer, BAD_CAST "providerid", - BAD_CAST account.providerid.c_str()); - - if (account.multiple_account_support) - xmlTextWriterWriteAttribute(writer, - BAD_CAST "multiple-accounts-support", - BAD_CAST "true"); - for (auto& icon_pair : account.icon_paths) { - xmlTextWriterStartElement(writer, BAD_CAST "icon"); - if (icon_pair.first == "AccountSmall") - xmlTextWriterWriteAttribute(writer, BAD_CAST "section", - BAD_CAST "account-small"); - else - xmlTextWriterWriteAttribute(writer, BAD_CAST "section", - BAD_CAST "account"); - xmlTextWriterWriteString(writer, BAD_CAST icon_pair.second.c_str()); - xmlTextWriterEndElement(writer); - } - - for (auto& name_pair : account.names) { - xmlTextWriterStartElement(writer, BAD_CAST "label"); - if (!name_pair.second.empty()) - xmlTextWriterWriteAttribute(writer, BAD_CAST "xml:lang", - BAD_CAST name_pair.second.c_str()); - xmlTextWriterWriteString(writer, BAD_CAST name_pair.first.c_str()); - xmlTextWriterEndElement(writer); - } - - for (auto& capability : account.capabilities) { - xmlTextWriterWriteFormatElement(writer, BAD_CAST "capability", - "%s", BAD_CAST capability.c_str()); - } - - xmlTextWriterEndElement(writer); - } - xmlTextWriterEndElement(writer); - } - - for (const char* profile : - GListRange(context_->manifest_data.get()->deviceprofile)) { - xmlTextWriterStartElement(writer, BAD_CAST "profile"); - xmlTextWriterWriteAttribute(writer, BAD_CAST "name", - BAD_CAST profile); - xmlTextWriterEndElement(writer); - } - - const auto& shortcuts = - context_->manifest_plugins_data.get().shortcut_info.get(); - if (!shortcuts.empty()) { - xmlTextWriterStartElement(writer, BAD_CAST "shortcut-list"); - for (auto& shortcut : shortcuts) { - xmlTextWriterStartElement(writer, BAD_CAST "shortcut"); - if (!shortcut.app_id.empty()) - xmlTextWriterWriteAttribute(writer, BAD_CAST "appid", - BAD_CAST shortcut.app_id.c_str()); - if (!shortcut.app_id.empty()) - xmlTextWriterWriteAttribute(writer, BAD_CAST "extra_data", - BAD_CAST shortcut.extra_data.c_str()); - if (!shortcut.app_id.empty()) - xmlTextWriterWriteAttribute(writer, BAD_CAST "extra_key", - BAD_CAST shortcut.extra_key.c_str()); - if (!shortcut.icon.empty()) { - xmlTextWriterStartElement(writer, BAD_CAST "icon"); - xmlTextWriterWriteString(writer, BAD_CAST shortcut.icon.c_str()); - xmlTextWriterEndElement(writer); - } - for (auto& label : shortcut.labels) { - xmlTextWriterStartElement(writer, BAD_CAST "label"); - if (!label.first.empty()) - xmlTextWriterWriteAttribute(writer, BAD_CAST "xml:lang", - BAD_CAST label.first.c_str()); - xmlTextWriterWriteString(writer, BAD_CAST label.second.c_str()); - xmlTextWriterEndElement(writer); - } - xmlTextWriterEndElement(writer); - } - xmlTextWriterEndElement(writer); - } - - xmlTextWriterEndElement(writer); - - xmlTextWriterEndDocument(writer); - xmlFreeTextWriter(writer); - - if (pkgmgr_parser_check_manifest_validation( - context_->xml_path.get().c_str()) != 0) { - LOG(ERROR) << "Manifest is not valid"; - return Step::Status::ERROR; - } - - LOG(DEBUG) << "Successfully create manifest xml " - << context_->xml_path.get(); - return Status::OK; -} - -common_installer::Step::Status StepGenerateXml::undo() { - bs::error_code error; - if (bf::exists(context_->xml_path.get())) - bf::remove_all(context_->xml_path.get(), error); - return Status::OK; -} - -} // namespace pkgmgr -} // namespace wgt diff --git a/src/wgt/step/step_generate_xml.h b/src/wgt/step/step_generate_xml.h deleted file mode 100644 index e0c369d..0000000 --- a/src/wgt/step/step_generate_xml.h +++ /dev/null @@ -1,45 +0,0 @@ -/* 2014, Copyright © Intel Coporation, license APACHE-2.0, see LICENSE file */ -// Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved -// Use of this source code is governed by a apache 2.0 license that can be -// found in the LICENSE file. - -#ifndef WGT_STEP_STEP_GENERATE_XML_H_ -#define WGT_STEP_STEP_GENERATE_XML_H_ - -#include - -#include - -#include "common/installer_context.h" -#include "common/step/step.h" - -namespace wgt { -namespace pkgmgr { - -class StepGenerateXml : public common_installer::Step { - public: - using Step::Step; - - Status process() override; - Status clean() override { return Status::OK; } - Status undo() override; - Status precheck() override; - - private: - enum class AppCompType { - UIAPP, - SVCAPP, - WIDGETAPP - }; - - Step::Status GenerateApplicationCommonXml(application_x* app, - xmlTextWriterPtr writer, - AppCompType type); - - SCOPE_LOG_TAG(GenerateXML) -}; - -} // namespace pkgmgr -} // namespace wgt - -#endif // WGT_STEP_STEP_GENERATE_XML_H_ diff --git a/src/wgt/step/step_parse.cc b/src/wgt/step/step_parse.cc deleted file mode 100644 index ef4b1b2..0000000 --- a/src/wgt/step/step_parse.cc +++ /dev/null @@ -1,574 +0,0 @@ -/* 2014, Copyright © Intel Coporation, license APACHE-2.0, see LICENSE file */ -// Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved -// Use of this source code is governed by a apache 2.0 license that can be -// found in the LICENSE file. - -#include "wgt/step/step_parse.h" - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include - -#include - -#include -#include -#include -#include -#include -#include -#include - -#include "common/app_installer.h" -#include "common/installer_context.h" -#include "common/step/step.h" -#include "utils/glist_range.h" -#include "wgt/wgt_backend_data.h" - -namespace { - -const std::string kManifestVersion = "1.0.0"; -const char kTizenPackageXmlNamespace[] = "http://tizen.org/ns/packages"; - -GList* GenerateMetadataListX(const wgt::parse::MetaDataInfo& meta_info) { - GList* list = nullptr; - for (auto& meta : meta_info.metadata()) { - metadata_x* new_meta = - static_cast(calloc(1, sizeof(metadata_x))); - new_meta->key = strdup(meta.first.c_str()); - if (!meta.second.empty()) - new_meta->value = strdup(meta.second.c_str()); - list = g_list_append(list, new_meta); - } - return list; -} - -void SetApplicationXDefaults(application_x* application) { - application->ambient_support = strdup("false"); - application->effectimage_type = strdup("image"); - application->enabled = strdup("true"); - application->guestmode_visibility = strdup("true"); - application->hwacceleration = strdup("default"); - application->indicatordisplay = strdup("true"); - application->launchcondition = strdup("false"); - application->permission_type = strdup("normal"); - application->process_pool = strdup("false"); - application->recentimage = strdup("false"); - application->screenreader = strdup("use-system-setting"); - application->submode = strdup("false"); - application->support_disable = strdup("false"); - application->taskmanage = strdup("true"); - application->ui_gadget = strdup("false"); -} - -} // namespace - -namespace wgt { -namespace parse { - -namespace app_keys = wgt::application_widget_keys; -namespace sc = std::chrono; - -StepParse::StepParse(common_installer::InstallerContext* context, - bool check_start_file) - : Step(context), - check_start_file_(check_start_file) { -} - -std::set StepParse::ExtractPrivileges( - std::shared_ptr perm_info) const { - return perm_info->GetAPIPermissions(); -} - -const std::string& StepParse::GetPackageVersion( - const std::string& manifest_version) { - if (!manifest_version.empty()) - return manifest_version; - return kManifestVersion; -} - -bool StepParse::FillInstallationInfo(manifest_x* manifest) { - manifest->root_path = strdup( - (context_->root_application_path.get() / manifest->package).c_str()); - manifest->installed_time = - strdup(std::to_string(sc::system_clock::to_time_t( - sc::system_clock::now())).c_str()); - return true; -} - -bool StepParse::FillIconPaths(manifest_x* manifest) { - std::shared_ptr icons_info = - std::static_pointer_cast( - parser_->GetManifestData(app_keys::kIconsKey)); - if (icons_info.get()) { - for (auto& application_icon : icons_info->icons()) { - icon_x* icon = reinterpret_cast (calloc(1, sizeof(icon_x))); - icon->text = strdup(application_icon.path().c_str()); - icon->lang = strdup(DEFAULT_LOCALE); - manifest->icon = g_list_append(manifest->icon, icon); - } - } - return true; -} - -bool StepParse::FillWidgetInfo(manifest_x* manifest) { - std::shared_ptr wgt_info = - std::static_pointer_cast(parser_->GetManifestData( - app_keys::kWidgetKey)); - if (!wgt_info.get()) { - LOG(ERROR) << "Widget info manifest data has not been found."; - return false; - } - - const std::string& version = wgt_info->version(); - - manifest->ns = strdup(kTizenPackageXmlNamespace); - manifest->version = strdup(GetPackageVersion(version).c_str()); - - for (auto& item : wgt_info->description_set()) { - description_x* description = reinterpret_cast - (calloc(1, sizeof(description_x))); - description->text = strdup(item.second.c_str()); - description->lang = !item.first.empty() ? - strdup(item.first.c_str()) : strdup(DEFAULT_LOCALE); - manifest->description = g_list_append(manifest->description, description); - } - - for (auto& item : wgt_info->name_set()) { - label_x* label = reinterpret_cast(calloc(1, sizeof(label_x))); - label->name = strdup(item.second.c_str()); - label->text = strdup(item.second.c_str()); - label->lang = !item.first.empty() ? - strdup(item.first.c_str()) : strdup(DEFAULT_LOCALE); - manifest->label = g_list_append(manifest->label, label); - } - - manifest->type = strdup("wgt"); - manifest->appsetting = strdup("false"); - manifest->nodisplay_setting = strdup("false"); - - // For wgt package use the long name - for (auto& item : wgt_info->name_set()) { - application_x* app = - reinterpret_cast(manifest->application->data); - label_x* label = reinterpret_cast(calloc(1, sizeof(label_x))); - label->name = strdup(item.second.c_str()); - label->text = strdup(item.second.c_str()); - label->lang = !item.first.empty() ? - strdup(item.first.c_str()) : strdup(DEFAULT_LOCALE); - app->label = g_list_append(app->label, label); - } - - author_x* author = reinterpret_cast(calloc(1, sizeof(author_x))); - if (!wgt_info->author().empty()) - author->text = strdup(wgt_info->author().c_str()); - if (!wgt_info->author_email().empty()) - author->email = strdup(wgt_info->author_email().c_str()); - if (!wgt_info->author_href().empty()) - author->href = strdup(wgt_info->author_href().c_str()); - author->lang = strdup(DEFAULT_LOCALE); - manifest->author = g_list_append(manifest->author, author); - - std::shared_ptr settings_info = - std::static_pointer_cast( - parser_->GetManifestData( - wgt::application_widget_keys::kTizenSettingKey)); - if (settings_info) { - switch (settings_info->install_location()) { - case wgt::parse::SettingInfo::InstallLocation::AUTO: { - manifest->installlocation = strdup("auto"); - break; - } - case wgt::parse::SettingInfo::InstallLocation::INTERNAL: { - manifest->installlocation = strdup("internal-only"); - break; - } - case wgt::parse::SettingInfo::InstallLocation::EXTERNAL: { - manifest->installlocation = strdup("prefer-external"); - break; - } - } - } else { - manifest->installlocation = strdup("auto"); - } - - return true; -} - -bool StepParse::FillUIApplicationInfo(manifest_x* manifest) { - std::shared_ptr app_info = - std::static_pointer_cast( - parser_->GetManifestData(app_keys::kTizenApplicationKey)); - if (!app_info) { - LOG(ERROR) << "Application info manifest data has not been found."; - return false; - } - // application data - application_x* application = reinterpret_cast( - calloc(1, sizeof(application_x))); - application->component_type = strdup("uiapp"); - application->mainapp = strdup("true"); - application->nodisplay = strdup("false"); - application->multiple = strdup("false"); - application->appid = strdup(app_info->id().c_str()); - SetApplicationXDefaults(application); - application->package = strdup(app_info->package().c_str()); - - application->exec = - strdup((context_->root_application_path.get() / app_info->package() - / "bin" / application->appid).c_str()); - application->type = strdup("webapp"); - application->onboot = strdup("false"); - application->autorestart = strdup("false"); - - application->launch_mode = strdup(app_info->launch_mode().c_str()); - if (manifest->icon) { - icon_x* icon = reinterpret_cast(manifest->icon->data); - icon_x* app_icon = reinterpret_cast(calloc(1, sizeof(icon_x))); - app_icon->text = strdup(icon->text); - app_icon->lang = strdup(icon->lang); - application->icon = g_list_append(application->icon, app_icon); - } - manifest->application = g_list_append(manifest->application, application); - - manifest->package = strdup(app_info->package().c_str()); - manifest->mainapp_id = strdup(app_info->id().c_str()); - return true; -} - -bool StepParse::FillServiceApplicationInfo(manifest_x* manifest) { - std::shared_ptr service_list = - std::static_pointer_cast( - parser_->GetManifestData(app_keys::kTizenServiceKey)); - if (!service_list) - return true; - for (auto& service_info : service_list->services) { - application_x* application = reinterpret_cast - (calloc(1, sizeof(application_x))); - application->component_type = strdup("svcapp"); - application->mainapp = strdup("false"); - application->nodisplay = strdup("false"); - application->multiple = strdup("false"); - application->appid = strdup(service_info.id().c_str()); - application->exec = - strdup((context_->root_application_path.get() / manifest->package - / "bin" / application->appid).c_str()); - application->type = strdup("webapp"); - application->onboot = - service_info.on_boot() ? strdup("true") : strdup("false"); - application->autorestart = - service_info.auto_restart() ? strdup("true") : strdup("false"); - SetApplicationXDefaults(application); - application->package = strdup(manifest->package); - - for (auto& pair : service_info.names()) { - label_x* label = reinterpret_cast(calloc(1, sizeof(label_x))); - label->lang = !pair.first.empty() ? - strdup(pair.first.c_str()) : strdup(DEFAULT_LOCALE); - label->name = strdup(pair.second.c_str()); - label->text = strdup(pair.second.c_str()); - application->label = g_list_append(application->label, label); - } - - if (!service_info.icon().empty()) { - icon_x* icon = reinterpret_cast(calloc(1, sizeof(icon_x))); - icon->text = strdup(service_info.icon().c_str()); - icon->lang = strdup(DEFAULT_LOCALE); - application->icon = g_list_append(application->icon, icon); - } - - // TODO(t.iwanek): what about description, how is it different from name? - - for (auto& category : service_info.categories()) { - application->category = g_list_append(application->category, - strdup(category.c_str())); - } - - for (auto& pair : service_info.metadata_set()) { - metadata_x* item = reinterpret_cast( - calloc(1, sizeof(metadata_x))); - item->key = strdup(pair.first.c_str()); - if (!pair.second.empty()) - item->value = strdup(pair.second.c_str()); - application->metadata = g_list_append(application->metadata, item); - } - - manifest->application = g_list_append(manifest->application, application); - } - return true; -} - -bool StepParse::FillBackgroundCategoryInfo(manifest_x* manifest) { - auto manifest_data = parser_->GetManifestData( - app_keys::kTizenBackgroundCategoryKey); - std::shared_ptr bc_list = - std::static_pointer_cast(manifest_data); - - if (!bc_list) - return true; - - application_x* app = - reinterpret_cast(manifest->application->data); - - for (auto& background_category : bc_list->background_categories) { - app->background_category = g_list_append( - app->background_category, strdup(background_category.value().c_str())); - } - - return true; -} - -bool StepParse::FillAppControl(manifest_x* manifest) { - std::shared_ptr app_info_list = - std::static_pointer_cast( - parser_->GetManifestData(app_keys::kTizenApplicationAppControlsKey)); - - application_x* app = - reinterpret_cast(manifest->application->data); - if (app_info_list) { - for (const auto& control : app_info_list->controls) { - appcontrol_x* app_control = - static_cast(calloc(1, sizeof(appcontrol_x))); - app_control->operation = strdup(control.operation().c_str()); - app_control->mime = strdup(control.mime().c_str()); - app_control->uri = strdup(control.uri().c_str()); - app->appcontrol = g_list_append(app->appcontrol, app_control); - } - } - return true; -} - -bool StepParse::FillPrivileges(manifest_x* manifest) { - std::shared_ptr perm_info = - std::static_pointer_cast(parser_->GetManifestData( - app_keys::kTizenPermissionsKey)); - std::set privileges; - if (perm_info) - privileges = ExtractPrivileges(perm_info); - - for (auto& priv : privileges) { - manifest->privileges = - g_list_append(manifest->privileges, strdup(priv.c_str())); - } - return true; -} - -bool StepParse::FillCategories(manifest_x* manifest) { - std::shared_ptr category_info = - std::static_pointer_cast(parser_->GetManifestData( - app_keys::kTizenCategoryKey)); - if (!category_info) - return true; - - application_x* app = - reinterpret_cast(manifest->application->data); - // there is one app atm - for (auto& category : category_info->categories) { - app->category = g_list_append(app->category, strdup(category.c_str())); - } - return true; -} - -bool StepParse::FillMetadata(manifest_x* manifest) { - std::shared_ptr meta_info = - std::static_pointer_cast(parser_->GetManifestData( - app_keys::kTizenMetaDataKey)); - if (!meta_info) - return true; - - for (application_x* app : GListRange(manifest->application)) { - app->metadata = GenerateMetadataListX(*meta_info); - } - return true; -} - -bool StepParse::FillAccounts(manifest_x* manifest) { - std::shared_ptr account_info = - std::static_pointer_cast(parser_->GetManifestData( - app_keys::kAccountKey)); - if (!account_info) - return true; - common_installer::AccountInfo info; - for (auto& account : account_info->accounts()) { - common_installer::SingleAccountInfo single_info; - single_info.capabilities = account.capabilities; - single_info.icon_paths = account.icon_paths; - single_info.multiple_account_support = account.multiple_account_support; - single_info.names = account.names; - // wgt can contain only one app so this assumes mainapp_id is valid here - single_info.appid = manifest->mainapp_id; - info.set_account(single_info); - } - context_->manifest_plugins_data.get().account_info.set(info); - return true; -} - -bool StepParse::FillExtraManifestInfo(manifest_x* manifest) { - return FillAccounts(manifest); -} - -bool StepParse::FillManifestX(manifest_x* manifest) { - if (!FillIconPaths(manifest)) - return false; - if (!FillUIApplicationInfo(manifest)) - return false; - if (!FillWidgetInfo(manifest)) - return false; - if (!FillInstallationInfo(manifest)) - return false; - if (!FillPrivileges(manifest)) - return false; - if (!FillAppControl(manifest)) - return false; - if (!FillCategories(manifest)) - return false; - if (!FillMetadata(manifest)) - return false; - // TODO(t.iwanek): fix adding ui application element - // for now adding application service is added here because rest of code - // assumes that there is one application at manifest->application - // so this must execute last - if (!FillServiceApplicationInfo(manifest)) - return false; - if (!FillBackgroundCategoryInfo(manifest)) - return false; - if (!FillExtraManifestInfo(manifest)) - return false; - return true; -} - -bool StepParse::LocateConfigFile() { - return StepParse::Check(context_->unpacked_dir_path.get()); -} - -common_installer::Step::Status StepParse::process() { - if (!LocateConfigFile()) { - LOG(ERROR) << "No config.xml"; - return common_installer::Step::Status::ERROR; - } - - parser_.reset(new wgt::parse::WidgetConfigParser()); - if (!parser_->ParseManifest(config_)) { - LOG(ERROR) << "[Parse] Parse failed. " << parser_->GetErrorMessage(); - return common_installer::Step::Status::ERROR; - } - if (check_start_file_) { - if (!parser_->HasValidStartFile()) { - LOG(ERROR) << parser_->GetErrorMessage(); - return common_installer::Step::Status::ERROR; - } - if (!parser_->HasValidServicesStartFiles()) { - LOG(ERROR) << parser_->GetErrorMessage(); - return common_installer::Step::Status::ERROR; - } - } - - manifest_x* manifest = - static_cast(calloc(1, sizeof(manifest_x))); - if (!FillManifestX(manifest)) { - LOG(ERROR) << "[Parse] Storing manifest_x failed. " - << parser_->GetErrorMessage(); - return common_installer::Step::Status::ERROR; - } - - // Copy data from ManifestData to InstallerContext - std::shared_ptr info = - std::static_pointer_cast( - parser_->GetManifestData( - wgt::application_widget_keys::kTizenApplicationKey)); - std::shared_ptr wgt_info = - std::static_pointer_cast( - parser_->GetManifestData( - wgt::application_widget_keys::kTizenWidgetKey)); - - std::string name; - const auto& name_set = wgt_info->name_set(); - if (name_set.find("") != name_set.end()) - name = name_set.find("")->second; - if (name_set.begin() != name_set.end()) - name = name_set.begin()->second; - - std::string short_name; - const auto& short_name_set = wgt_info->short_name_set(); - if (short_name_set.find("") != short_name_set.end()) - short_name = short_name_set.find("")->second; - if (short_name_set.begin() != short_name_set.end()) - short_name = short_name_set.begin()->second; - - const std::string& package_version = wgt_info->version(); - const std::string& required_api_version = info->required_version(); - - manifest->api_version = strdup(required_api_version.c_str()); - context_->pkgid.set(manifest->package); - - // write pkgid for recovery file - if (context_->recovery_info.get().recovery_file) { - context_->recovery_info.get().recovery_file->set_pkgid(manifest->package); - context_->recovery_info.get().recovery_file->WriteAndCommitFileContent(); - } - - std::shared_ptr perm_info = - std::static_pointer_cast( - parser_->GetManifestData( - wgt::application_widget_keys::kTizenPermissionsKey)); - parser::PermissionSet permissions; - if (perm_info) - permissions = perm_info->GetAPIPermissions(); - - std::unique_ptr backend_data(new WgtBackendData()); - - std::shared_ptr settings_info = - std::static_pointer_cast( - parser_->GetManifestData( - wgt::application_widget_keys::kTizenSettingKey)); - if (settings_info) - backend_data->settings.set(*settings_info); - - context_->backend_data.set(backend_data.release()); - - LOG(DEBUG) << " Read data -[ "; - LOG(DEBUG) << "App id: " << info->id(); - LOG(DEBUG) << " package = " << info->package(); - LOG(DEBUG) << " id = " << info->id(); - LOG(DEBUG) << " name = " << name; - LOG(DEBUG) << " short_name = " << short_name; - LOG(DEBUG) << " aplication version = " << package_version; - LOG(DEBUG) << " api_version = " << info->required_version(); - LOG(DEBUG) << " launch_mode = " << info->launch_mode(); - LOG(DEBUG) << " privileges -["; - for (const auto& p : permissions) { - LOG(DEBUG) << " " << p; - } - LOG(DEBUG) << " ]-"; - LOG(DEBUG) << "]-"; - - context_->manifest_data.set(manifest); - return common_installer::Step::Status::OK; -} - -bool StepParse::Check(const boost::filesystem::path& widget_path) { - boost::filesystem::path config = widget_path; - config /= "config.xml"; - - LOG(DEBUG) << "config.xml path: " << config; - - if (!boost::filesystem::exists(config)) - return false; - - config_ = config; - return true; -} - -} // namespace parse -} // namespace wgt diff --git a/src/wgt/step/step_parse.h b/src/wgt/step/step_parse.h deleted file mode 100644 index c157aa0..0000000 --- a/src/wgt/step/step_parse.h +++ /dev/null @@ -1,100 +0,0 @@ -// Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved -// Use of this source code is governed by a apache 2.0 license that can be -// found in the LICENSE file. - -#ifndef WGT_STEP_STEP_PARSE_H_ -#define WGT_STEP_STEP_PARSE_H_ - -#include - -#include -#include -#include - -#include -#include -#include - -#include "common/app_installer.h" -#include "common/installer_context.h" -#include "common/step/step.h" - -namespace wgt { -namespace parse { - -/** - * \brief This step parse manifest.xml document - */ -class StepParse : public common_installer::Step { - public: - /** - * \brief Explicit constructor - * - * \param context Installer context - * \param check_start_file Flag if start file should be validated - */ - explicit StepParse(common_installer::InstallerContext* context, - bool check_start_file); - - /** - * \brief - */ - Status process() override; - - /** - * \brief Empty method - * - * \return Status::OK - */ - Status clean() override { return Status::OK; } - - /** - * \brief Empty method - * - * \return Status::OK - */ - Status undo() override { return Status::OK; } - - /** - * \brief Empty method - * - * \return Status::OK - */ - Status precheck() override { return Status::OK; } - - protected: - virtual bool LocateConfigFile(); - bool Check(const boost::filesystem::path& widget_path); - - boost::filesystem::path config_; - - private: - std::set ExtractPrivileges( - std::shared_ptr perm_info) const; - - const std::string& GetPackageVersion(const std::string& manifest_version); - - bool FillInstallationInfo(manifest_x* manifest); - bool FillIconPaths(manifest_x* manifest); - bool FillWidgetInfo(manifest_x* manifest); - bool FillUIApplicationInfo(manifest_x* manifest); - bool FillServiceApplicationInfo(manifest_x* manifest); - bool FillAppControl(manifest_x* manifest); - bool FillPrivileges(manifest_x* manifest); - bool FillCategories(manifest_x* manifest); - bool FillMetadata(manifest_x* manifest); - bool FillExtraManifestInfo(manifest_x* manifest); - bool FillAccounts(manifest_x* manifest); - bool FillBackgroundCategoryInfo(manifest_x* manifest); - bool FillManifestX(manifest_x* manifest); - - std::unique_ptr parser_; - bool check_start_file_; - - SCOPE_LOG_TAG(Parse) -}; - -} // namespace parse -} // namespace wgt - -#endif // WGT_STEP_STEP_PARSE_H_ diff --git a/src/wgt/step/step_parse_recovery.cc b/src/wgt/step/step_parse_recovery.cc deleted file mode 100644 index 23de8b6..0000000 --- a/src/wgt/step/step_parse_recovery.cc +++ /dev/null @@ -1,56 +0,0 @@ -// Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved -// Use of this source code is governed by an apache-2.0 license that can be -// found in the LICENSE file. - -#include "wgt/step/step_parse_recovery.h" - -#include "common/backup_paths.h" -#include "common/installer_context.h" - -namespace { - -const char kResWgtPath[] = "res/wgt"; - -} - -namespace wgt { -namespace parse { - -StepParseRecovery::StepParseRecovery( - common_installer::InstallerContext* context) - : StepParse(context, false) { -} - -common_installer::Step::Status StepParseRecovery::process() { - (void) StepParse::process(); - return Status::OK; -} - -common_installer::Step::Status StepParseRecovery::precheck() { - if (context_->root_application_path.get().empty()) { - LOG(ERROR) << "Root path of packages in not set"; - return Status::ERROR; - } - if (context_->pkgid.get().empty()) { - LOG(WARNING) << "Pkgid is not set. Parsing skipped"; - return Status::OK; - } - return Status::OK; -} - -bool StepParseRecovery::LocateConfigFile() { - context_->pkg_path.set( - context_->root_application_path.get() / context_->pkgid.get()); - - if (Check(common_installer::GetBackupPathForPackagePath( - context_->pkg_path.get()) / kResWgtPath)) - return true; - - if (Check(context_->pkg_path.get() / kResWgtPath)) - return true; - - return false; -} - -} // namespace parse -} // namespace wgt diff --git a/src/wgt/step/step_parse_recovery.h b/src/wgt/step/step_parse_recovery.h deleted file mode 100644 index b5ed147..0000000 --- a/src/wgt/step/step_parse_recovery.h +++ /dev/null @@ -1,63 +0,0 @@ -// Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved -// Use of this source code is governed by an apache-2.0 license that can be -// found in the LICENSE file. - -#ifndef WGT_STEP_STEP_PARSE_RECOVERY_H_ -#define WGT_STEP_STEP_PARSE_RECOVERY_H_ - -#include - -#include "wgt/step/step_parse.h" - -namespace wgt { -namespace parse { -/** - * \brief The StepParseRecovery class - * Retrievies package information from config.xml during RECOVERY. - * - * Step is used in recovery mode. - * - * Parse config.xml file by guessing possible locations: - * - backup package directory - * - package installation directory - * to get information about widget package to be recovered. - * - */ -class StepParseRecovery : public StepParse { - public: - /** - * \brief Explicit constructor - * - * \param context installer context - */ - explicit StepParseRecovery(common_installer::InstallerContext* context); - - /** - * \brief Parse config.xml - * - * \return Status::OK - */ - Status process() override; - - /** - * \brief Validate requirements for this step - * - * \return Status::ERROR when root path of packages is missing, - * Status::OK otherwise - */ - Status precheck() override; - - /** - * \brief Locate config.xml file - * - * \return true if config.xml is found - */ - bool LocateConfigFile() override; - - SCOPE_LOG_TAG(ParseRecovery) -}; - -} // namespace parse -} // namespace wgt - -#endif // WGT_STEP_STEP_PARSE_RECOVERY_H_ diff --git a/src/wgt/step/step_rds_modify.cc b/src/wgt/step/step_rds_modify.cc deleted file mode 100644 index 2bf3ef2..0000000 --- a/src/wgt/step/step_rds_modify.cc +++ /dev/null @@ -1,226 +0,0 @@ -// Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved -// Use of this source code is governed by a apache 2.0 license that can be -// found in the LICENSE file. - -#include "wgt/step/step_rds_modify.h" - -#include - -#include - -#include "common/utils/file_util.h" - -namespace wgt { -namespace rds { - -namespace bf = boost::filesystem; -namespace bs = boost::system; -namespace cu = common_installer; - -StepRDSModify::StepRDSModify(common_installer::InstallerContext* context) - : Step(context), - backend_data_(nullptr) {} - -common_installer::Step::Status StepRDSModify::precheck() { - if (context_->unpacked_dir_path.get().empty()) { - LOG(ERROR) << "unpacked dir path is not set"; - return common_installer::Step::Status::ERROR; - } - if (!bf::exists(context_->unpacked_dir_path.get())) { - LOG(ERROR) << "unpacked_dir_path (" - << context_->unpacked_dir_path.get() - << ") path does not exist"; - return common_installer::Step::Status::ERROR; - } - if (context_->pkgid.get().empty()) { - LOG(ERROR) << "pkgid is not set"; - return common_installer::Step::Status::ERROR; - } - if (!context_->manifest_data.get()) { - LOG(ERROR) << "no manifest info available"; - return common_installer::Step::Status::ERROR; - } - // TODO(w.kosowicz): check if config of installed app was encrypted - backend_data_ = static_cast(context_->backend_data.get()); - if (!backend_data_) { - LOG(ERROR) << "no backend data"; - return common_installer::Step::Status::ERROR; - } - return common_installer::Step::Status::OK; -} - -common_installer::Step::Status StepRDSModify::process() { - LOG(INFO) << "entered process of step modify"; - if (!SetUpTempBackupDir()) { - LOG(ERROR) << "unable to setup temp directory"; - return common_installer::Step::Status::ERROR; - } - context_->pkg_path.set( - context_->root_application_path.get() /context_->pkgid.get()); - bf::path install_path = context_->pkg_path.get() / "res" / "wgt"; - bf::path unzip_path = context_->unpacked_dir_path.get(); - if (!AddFiles(unzip_path, install_path) || - !ModifyFiles(unzip_path, install_path) || - !DeleteFiles(install_path)) { - LOG(ERROR) << "error during file operation"; - return common_installer::Step::Status::ERROR; - } - return common_installer::Step::Status::OK; -} - -common_installer::Step::Status StepRDSModify::undo() { - RestoreFiles(); - return common_installer::Step::Status::OK; -} - -common_installer::Step::Status StepRDSModify::clean() { - if (bf::exists(backup_temp_dir_)) - bf::remove_all(backup_temp_dir_); - return common_installer::Step::Status::OK; -} - -bool StepRDSModify::AddFiles(bf::path unzip_path, bf::path install_path) { - LOG(INFO) << "about to add files"; - bs::error_code error; - for (const auto& file : backend_data_->files_to_add.get()) { - if (!PerformBackup(file, Operation::ADD)) { - LOG(ERROR) << "unable to perform backup of added file"; - return false; - } - bf::path temp_install_path(install_path / file); - if (bf::is_directory(temp_install_path)) { - if (!bf::exists(temp_install_path) && - (!cu::CreateDir(temp_install_path))) { - LOG(ERROR) << "unable to create dir for temp backup data"; - return false; - } - } else { - if (!bf::exists(temp_install_path.parent_path()) && - !cu::CreateDir(temp_install_path.parent_path())) { - LOG(ERROR) << "unable to create dir for temp backup data"; - return false; - } - bf::path temp_unzip_path(unzip_path / file); - bf::copy_file(temp_unzip_path, temp_install_path, error); - if (error) { - LOG(ERROR) << "unable to add file " << error.message(); - return false; - } - } - } - return true; -} - -bool StepRDSModify::ModifyFiles(bf::path unzip_path, bf::path install_path) { - LOG(INFO) << "about to modify files"; - bs::error_code error; - for (const auto& file : backend_data_->files_to_modify.get()) { - bf::path temp_install_path(install_path / file); - bf::path temp_unzip_path(unzip_path / file); - if (!PerformBackup(file, Operation::MODIFY)) { - LOG(ERROR) << "unable to perform backup of to be modified file"; - return false; - } - bf::copy_file(temp_unzip_path, temp_install_path, - bf::copy_option::overwrite_if_exists, error); - if (error) { - LOG(ERROR) << "unable to modify file " << error.message(); - return false; - } - } - return true; -} - -bool StepRDSModify::DeleteFiles(bf::path install_path) { - LOG(INFO) << "about to delete files"; - bs::error_code error; - for (const auto& file : backend_data_->files_to_delete.get()) { - if (!PerformBackup(file, Operation::DELETE)) { - LOG(ERROR) << "unable to perform backup of to be deleted file"; - return false; - } - bf::remove(install_path / file, error); - if (error) { - LOG(ERROR) <<"unable to delete files " << error.message(); - return false; - } - } - return true; -} - -bool StepRDSModify::SetUpTempBackupDir() { - LOG(INFO) << "about to setup tmp backup dir"; - bs::error_code error; - backup_temp_dir_ = "/tmp/" / - bf::unique_path("%%%%-%%%%-%%%%-%%%%", error); - if (error || !cu::CreateDir(backup_temp_dir_)) { - LOG(ERROR) << "unable to create backup data temp dir"; - return false; - } - - return true; -} - -bool StepRDSModify::PerformBackup(std::string relative_path, - Operation operation) { - if (backup_temp_dir_.empty()) - return false; - if (operation == Operation::DELETE || operation == Operation::MODIFY) { - bf::path app_path = context_->pkg_path.get() / "res" / "wgt"; - bf::path source_path = app_path / relative_path; - if (bf::is_directory(source_path)) { - if (!cu::CreateDir(backup_temp_dir_ / relative_path)) { - LOG(ERROR) << "unable to create dir for temp backup data"; - return false; - } - } else { - bs::error_code error; - bf::path tmp_dest_path = backup_temp_dir_ / relative_path; - if (!bf::exists((tmp_dest_path).parent_path()) && - (!cu::CreateDir((tmp_dest_path).parent_path()))) { - LOG(ERROR) << "unable to create dir for temp backup data"; - return false; - } - bf::copy_file(source_path, tmp_dest_path, error); - if (error) { - LOG(ERROR) << "unable to backup file: " - << source_path << " : " << error.message(); - return false; - } - } - } - success_modifications_.push_back(std::make_pair(relative_path, operation)); - return true; -} - -void StepRDSModify::RestoreFiles() { - LOG(ERROR) << "error occured about to restore files"; - bf::path app_path(context_->pkg_path.get()); - for (std::pair& modification : - success_modifications_) { - bf::path source_path(backup_temp_dir_ / modification.first); - bf::path destination_path(app_path / modification.first); - if (modification.second == Operation::ADD) { - if (bf::is_directory(source_path)) { - bf::remove_all(destination_path); - } else { - bf::remove(destination_path); - } - } else if (modification.second == Operation::MODIFY) { - bf::copy_file(source_path, destination_path, - bf::copy_option::overwrite_if_exists); - } else { - if (bf::is_directory(source_path)) { - cu::CreateDir(destination_path); - } else { - bf::copy_file(source_path, destination_path, - bf::copy_option::overwrite_if_exists); - } - } - } - // after files are restore delete temporary location - bf::remove_all(backup_temp_dir_); -} - -} // namespace rds -} // namespace wgt diff --git a/src/wgt/step/step_rds_modify.h b/src/wgt/step/step_rds_modify.h deleted file mode 100644 index ed3fa58..0000000 --- a/src/wgt/step/step_rds_modify.h +++ /dev/null @@ -1,87 +0,0 @@ -// Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved -// Use of this source code is governed by a apache 2.0 license that can be -// found in the LICENSE file. - -#ifndef WGT_STEP_STEP_RDS_MODIFY_H_ -#define WGT_STEP_STEP_RDS_MODIFY_H_ - -#include -#include -#include -#include - -#include "common/step/step.h" -#include "wgt/wgt_backend_data.h" - -namespace wgt { -namespace rds { - -/** - * \brief Step that apply RDS modification during reinstallation process - */ -class StepRDSModify : public common_installer::Step { - public: - /** - * \brief Explicit constructor - * - * \param context Installer context - */ - explicit StepRDSModify(common_installer::InstallerContext* context); - - /** - * \brief - * - * \return - */ - Status process() override; - - /** - * \brief Remove files from temporary location - * - * \return Status::OK - */ - Status clean() override; - - /** - * \brief Restore files to the state from before RDS installation - * - * \return Status::OK - */ - Status undo() override; - - /** - * \brief - * - * \return Status::ERROR when manifest is missing, pkgid is missing, - * or when path to the unpacked directory is missing or not exist, - * Status::OK otherwise - */ - Status precheck() override; - - private: - enum class Operation { - ADD, - MODIFY, - DELETE - }; - - bool AddFiles(boost::filesystem::path unzip_path, - boost::filesystem::path install_path); - bool ModifyFiles(boost::filesystem::path unzip_path, - boost::filesystem::path install_path); - bool DeleteFiles(boost::filesystem::path install_path); - bool SetUpTempBackupDir(); - void DeleteTempBackupDir(); - bool PerformBackup(std::string relative_path, Operation operation); - void RestoreFiles(); - - WgtBackendData* backend_data_; - std::vector> success_modifications_; - boost::filesystem::path backup_temp_dir_; - std::vector files_to_modify_; - std::vector files_to_add_; - std::vector files_to_delete_; -}; -} // namespace rds -} // namespace wgt -#endif // WGT_STEP_STEP_RDS_MODIFY_H_ diff --git a/src/wgt/step/step_rds_parse.cc b/src/wgt/step/step_rds_parse.cc deleted file mode 100644 index b98900e..0000000 --- a/src/wgt/step/step_rds_parse.cc +++ /dev/null @@ -1,50 +0,0 @@ -// Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved -// Use of this source code is governed by a apache 2.0 license that can be -// found in the LICENSE file. - -#include "wgt/step/step_rds_parse.h" - -#include - -#include - -#include "wgt/rds_parser.h" -#include "wgt/wgt_backend_data.h" - - -namespace wgt { -namespace rds { - -namespace bf = boost::filesystem; - -common_installer::Step::Status StepRDSParse::precheck() { - bf::path rdsPath(context_->unpacked_dir_path.get() / ".rds_delta"); - if (!bf::exists(rdsPath)) { - LOG(ERROR) << "no rds_delta file"; - return common_installer::Step::Status::ERROR; - } - rds_file_path_ = rdsPath; - return common_installer::Step::Status::OK; -} - -common_installer::Step::Status StepRDSParse::process() { - wgt::rds_parser::RDSParser parser(rds_file_path_.native()); - if (!parser.Parse()) { - LOG(ERROR) << "parsing of rds delta failed"; - return common_installer::Step::Status::ERROR; - } - - WgtBackendData* backend_data = - static_cast(context_->backend_data.get()); - if (!backend_data) { - LOG(ERROR) << "no wgt backend data available"; - return common_installer::Step::Status::ERROR; - } - backend_data->files_to_modify.set(parser.files_to_modify()); - backend_data->files_to_add.set(parser.files_to_add()); - backend_data->files_to_delete.set(parser.files_to_delete()); - return common_installer::Step::Status::OK; -} - -} // namespace rds -} // namespace wgt diff --git a/src/wgt/step/step_rds_parse.h b/src/wgt/step/step_rds_parse.h deleted file mode 100644 index 4a57040..0000000 --- a/src/wgt/step/step_rds_parse.h +++ /dev/null @@ -1,61 +0,0 @@ -// Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved -// Use of this source code is governed by a apache 2.0 license that can be -// found in the LICENSE file. - -#ifndef WGT_STEP_STEP_RDS_PARSE_H_ -#define WGT_STEP_STEP_RDS_PARSE_H_ - -#include "common/step/step.h" - -#include -#include -#include - -namespace wgt { -namespace rds { - -/** - * \brief This step parse .rds_delta file - * - * This is to prepare RDS installation process - */ -class StepRDSParse : public common_installer::Step { - public: - using Step::Step; - - /** - * \brief Parse .rds_delta file - * - * \return Status::ERROR when wgt backend data are missing, - * Status::OK otherwise - */ - Status process() override; - - /** - * \brief Empty method - * - * \return Status::OK - */ - Status clean() override { return Status::OK; } - - /** - * \brief Empty method - * - * \return Status::OK - */ - Status undo() override { return Status::OK; } - - /** - * \brief Validate if .rds_delta file exist - * - * \return Status::Error if file not exist, - * Status::OK otherwise - */ - Status precheck() override; - - private: - boost::filesystem::path rds_file_path_; -}; -} // namespace rds -} // namespace wgt -#endif // WGT_STEP_STEP_RDS_PARSE_H_ diff --git a/src/wgt/step/step_remove_encryption_data.cc b/src/wgt/step/step_remove_encryption_data.cc deleted file mode 100644 index 452f32b..0000000 --- a/src/wgt/step/step_remove_encryption_data.cc +++ /dev/null @@ -1,54 +0,0 @@ -// Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved -// Use of this source code is governed by a apache 2.0 license that can be -// found in the LICENSE file. - -#include "wgt/step/step_remove_encryption_data.h" - -#include - -#include - -namespace wgt { -namespace encrypt { - -common_installer::Step::Status StepRemoveEncryptionData::clean() { - wae_app_type_e enc_type = - context_->request_mode.get() == common_installer::RequestMode::GLOBAL ? - WAE_DOWNLOADED_GLOBAL_APP : WAE_DOWNLOADED_NORMAL_APP; - - // There is no check, if application was encrypted or not - // (it is not saved anywhere in tizen manifest) - // so, if WAE_ERROR_NO_KEY error, then application was not encrypted - int ret = wae_remove_app_dek(context_->pkgid.get().c_str(), enc_type); - if (WAE_ERROR_NONE == ret || WAE_ERROR_NO_KEY == ret) { - LOG(DEBUG) << "Encryption data removed (if existed)"; - return common_installer::Step::Status::OK; - } - - switch (ret) { - case WAE_ERROR_INVALID_PARAMETER: - LOG(ERROR) << "Error while removing encryption data: " - "WAE_ERROR_INVALID_PARAMETER"; - break; - case WAE_ERROR_PERMISSION_DENIED: - LOG(ERROR) << "Error while removing encryption data: " - "WAE_ERROR_PERMISSION_DENIED"; - break; - case WAE_ERROR_KEY_MANAGER: - LOG(ERROR) << "Error while removing encryption data: " - "WAE_ERROR_KEY_MANAGER"; - break; - case WAE_ERROR_UNKNOWN: - LOG(ERROR) << "Error while removing encryption data: " - "WAE_ERROR_UNKNOWN"; - break; - default: - LOG(ERROR) << "Error while removing encryption data: " - "UNKNOWN"; - break; - } - return common_installer::Step::Status::ERROR; -} - -} // namespace encrypt -} // namespace wgt diff --git a/src/wgt/step/step_remove_encryption_data.h b/src/wgt/step/step_remove_encryption_data.h deleted file mode 100644 index 16f1086..0000000 --- a/src/wgt/step/step_remove_encryption_data.h +++ /dev/null @@ -1,57 +0,0 @@ -// Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved -// Use of this source code is governed by a apache 2.0 license that can be -// found in the LICENSE file. - -#ifndef WGT_STEP_STEP_REMOVE_ENCRYPTION_DATA_H_ -#define WGT_STEP_STEP_REMOVE_ENCRYPTION_DATA_H_ - -#include - -#include "common/step/step.h" - -namespace wgt { -namespace encrypt { - -/** - * This step remove encryption keys used for encryption during installation - * - * This step is called during uninstallation process - */ -class StepRemoveEncryptionData : public common_installer::Step { - public: - using Step::Step; - - /** - * \brief Empty method - the actual work is done in clean() to delay it - * - * \return Status::OK - */ - Status process() override { return Status::OK; } - - /** - * \brief Remove encryption keys from database - * - * \return Status::ERROR in case of failure, - * Status::OK otherwise - */ - Status clean() override; - - /** - * \brief Empty method - * - * \return Status::OK - */ - Status undo() override { return Status::OK; } - - /** - * \brief Empty method - * - * \return Status::OK - */ - Status precheck() override { return Status::OK; } - - SCOPE_LOG_TAG(RemoveEncryptionData) -}; -} // namespace encrypt -} // namespace wgt -#endif // WGT_STEP_STEP_REMOVE_ENCRYPTION_DATA_H_ diff --git a/src/wgt/step/step_wgt_copy_storage_directories.cc b/src/wgt/step/step_wgt_copy_storage_directories.cc deleted file mode 100644 index b6ca609..0000000 --- a/src/wgt/step/step_wgt_copy_storage_directories.cc +++ /dev/null @@ -1,172 +0,0 @@ -// Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved -// Use of this source code is governed by an apache-2.0 license that can be -// found in the LICENSE file. - -#include "wgt/step/step_wgt_copy_storage_directories.h" - -#include -#include -#include - -#include "common/utils/file_util.h" - -namespace bf = boost::filesystem; -namespace bs = boost::system; - -namespace { - -const char kDataLocation[] = "data"; -const char kSharedLocation[] = "shared"; -const char kSharedDataLocation[] = "shared/data"; -const char kSharedTrustedLocation[] = "shared/trusted"; -const char kResWgtSubPath[] = "res/wgt"; -const char kTemporaryData[] = "tmp"; -} // namespace - -namespace wgt { -namespace filesystem { - -common_installer::Step::Status StepWgtCopyStorageDirectories::process() { - Status status = CreatePrivateTmpDir(); - if (status != Status::OK) - return status; - if (!CacheDir()) - return Status::ERROR; - - int version = context_->manifest_data.get()->api_version[0] - '0'; - if (version < 3) { - LOG(DEBUG) << "Shared directory coping for tizen 2.x"; - return StepCopyStorageDirectories::process(); - } - - LOG(DEBUG) << "Shared directory coping for tizen 3.x"; - status = CopySharedDirectory(); - if (status != Status::OK) - return status; - - return CopyDataDirectory(); -} - -common_installer::Step::Status StepWgtCopyStorageDirectories::undo() { - int version = context_->manifest_data.get()->api_version[0] - '0'; - if (version < 3) { - LOG(DEBUG) << "Shared directory coping for tizen 2.x"; - return StepCopyStorageDirectories::undo(); - } - - UndoSharedDirectory(); - UndoDataDirectory(); - return Status::OK; -} - -void StepWgtCopyStorageDirectories::UndoSharedDirectory() { - if (!MoveAppStorage(context_->pkg_path.get(), - backup_path_, - kSharedDataLocation)) { - LOG(ERROR) << - "Failed to undo moving of shared/data directory for widget in update"; - } - - if (!MoveAppStorage(context_->pkg_path.get(), - backup_path_, - kSharedTrustedLocation)) { - LOG(ERROR) << "Failed to undo moving of shared/trusted directory" - << "for widget in update"; - } -} - -void StepWgtCopyStorageDirectories::UndoDataDirectory() { - if (!MoveAppStorage(context_->pkg_path.get(), - backup_path_, - kDataLocation)) { - LOG(ERROR) - << "Failed to undo moving of private directory for widget in update"; - } -} - -common_installer::Step::Status -StepWgtCopyStorageDirectories::HandleWgtSharedDirectory() { - bf::path res_wgt_path = context_->pkg_path.get() / kResWgtSubPath; - bf::path shared_source = res_wgt_path / kSharedLocation; - bf::path shared_destination = context_->pkg_path.get() / kSharedLocation; - - // Move shared if exist in wgt - if (bf::exists(shared_source)) { - if (!common_installer::MoveDir(shared_source, shared_destination)) { - LOG(ERROR) << "Failed to move shared data from res/wgt to shared"; - return Status::ERROR; - } - } - - // Create shared directory if not present yet - if (!bf::exists(shared_destination)) { - bs::error_code error_code; - bf::create_directory(shared_destination, error_code); - if (error_code) { - LOG(ERROR) << "Failed to create shared storage directory"; - return Status::ERROR; - } - } - - // Symlink created shared directory - bs::error_code error_code; - bf::create_symlink(shared_destination, shared_source, error_code); - if (error_code) { - LOG(ERROR) << "Failed to create symbolic link for shared dir" - << boost::system::system_error(error_code).what(); - return Status::ERROR; - } - return Status::OK; -} - -common_installer::Step::Status -StepWgtCopyStorageDirectories::CopySharedDirectory() { - Status status = HandleWgtSharedDirectory(); - if (status != Status::OK) - return status; - - if (!MoveAppStorage(backup_path_, - context_->pkg_path.get(), - kSharedDataLocation)) { - LOG(ERROR) << - "Failed to restore shared/data directory for widget in update"; - return Status::ERROR; - } - - if (!MoveAppStorage(backup_path_, - context_->pkg_path.get(), - kSharedTrustedLocation)) { - LOG(ERROR) << - "Failed to restore shared/trusted directory for widget in update"; - return Status::ERROR; - } - - return Status::OK; -} - -common_installer::Step::Status -StepWgtCopyStorageDirectories::CopyDataDirectory() { - if (!MoveAppStorage(backup_path_, - context_->pkg_path.get(), - kDataLocation)) { - LOG(ERROR) << "Failed to restore private directory for widget in update"; - return Status::ERROR; - } - return Status::OK; -} - -common_installer::Step::Status -StepWgtCopyStorageDirectories::CreatePrivateTmpDir() { - bs::error_code error_code; - bf::path tmp_path = context_->pkg_path.get() / kTemporaryData; - bf::create_directory(tmp_path, error_code); - if (error_code) { - LOG(ERROR) << "Failed to create private temporary directory for package"; - return Status::ERROR; - } - return Status::OK; -} - -} // namespace filesystem -} // namespace wgt - diff --git a/src/wgt/step/step_wgt_copy_storage_directories.h b/src/wgt/step/step_wgt_copy_storage_directories.h deleted file mode 100644 index 3977a33..0000000 --- a/src/wgt/step/step_wgt_copy_storage_directories.h +++ /dev/null @@ -1,58 +0,0 @@ -// Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved -// Use of this source code is governed by an apache-2.0 license that can be -// found in the LICENSE file. - -#ifndef WGT_STEP_STEP_WGT_COPY_STORAGE_DIRECTORIES_H_ -#define WGT_STEP_STEP_WGT_COPY_STORAGE_DIRECTORIES_H_ - -#include - -#include "common/step/step_copy_storage_directories.h" - -namespace wgt { -namespace filesystem { - -/** - * \brief Update installation (WGT). - * Responsible for coping shared and data directories. - * It extends StepCopyStorageDirectories (it adds distinction between - * 2.x and 3.x shared dir handling - */ -class StepWgtCopyStorageDirectories - : public common_installer::filesystem::StepCopyStorageDirectories { - public: - using StepCopyStorageDirectories::StepCopyStorageDirectories; - - /** - * \brief Create shared and private directories, - * and copy/restore widget files to appropriate directory - * - * \return Status::ERROR when failed to create temporary location, - * private temporary location, or failed to restore - * shared/private directory for widget, - * Status::OK otherwise - */ - Status process() override; - - /** - * \brief Move files from shared/private directories back to source directory - * - * \return Status::OK - */ - Status undo() override; - - private: - Status CopySharedDirectory(); - Status CopyDataDirectory(); - Status HandleWgtSharedDirectory(); - void UndoSharedDirectory(); - void UndoDataDirectory(); - Status CreatePrivateTmpDir(); - - SCOPE_LOG_TAG(CopyWgtStorageDirectories) -}; - -} // namespace filesystem -} // namespace wgt - -#endif // WGT_STEP_STEP_WGT_COPY_STORAGE_DIRECTORIES_H_ diff --git a/src/wgt/step/step_wgt_create_icons.cc b/src/wgt/step/step_wgt_create_icons.cc deleted file mode 100644 index f62588c..0000000 --- a/src/wgt/step/step_wgt_create_icons.cc +++ /dev/null @@ -1,22 +0,0 @@ -// Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved -// Use of this source code is governed by an apache-2.0 license that can be -// found in the LICENSE file. - -#include "wgt/step/step_wgt_create_icons.h" - -namespace { - -const char kResWgt[] = "res/wgt"; - -} - -namespace wgt { -namespace filesystem { - -boost::filesystem::path StepWgtCreateIcons::GetIconRoot() const { - return context_->pkg_path.get() / kResWgt; -} - -} // namespace filesystem -} // namespace wgt - diff --git a/src/wgt/step/step_wgt_create_icons.h b/src/wgt/step/step_wgt_create_icons.h deleted file mode 100644 index d8fe7a5..0000000 --- a/src/wgt/step/step_wgt_create_icons.h +++ /dev/null @@ -1,36 +0,0 @@ -// Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved -// Use of this source code is governed by an apache-2.0 license that can be -// found in the LICENSE file. - -#ifndef WGT_STEP_STEP_WGT_CREATE_ICONS_H_ -#define WGT_STEP_STEP_WGT_CREATE_ICONS_H_ - -#include - -#include "common/step/step_create_icons.h" - -namespace wgt { -namespace filesystem { - -/** - * \brief This step return path to widget icon - */ -class StepWgtCreateIcons - : public common_installer::filesystem::StepCreateIcons { - public: - using StepCreateIcons::StepCreateIcons; - - /** - * \brief Return path to widget icon - * - * \return path to widget icon - */ - boost::filesystem::path GetIconRoot() const override; - - SCOPE_LOG_TAG(WgtCreateIcons) -}; - -} // namespace filesystem -} // namespace wgt - -#endif // WGT_STEP_STEP_WGT_CREATE_ICONS_H_ diff --git a/src/wgt/step/step_wgt_create_storage_directories.cc b/src/wgt/step/step_wgt_create_storage_directories.cc deleted file mode 100644 index 02256a5..0000000 --- a/src/wgt/step/step_wgt_create_storage_directories.cc +++ /dev/null @@ -1,102 +0,0 @@ -// Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved -// Use of this source code is governed by an apache 2.0 license that can be -// found in the LICENSE file. - -#include "wgt/step/step_wgt_create_storage_directories.h" - -#include -#include -#include - -#include "common/utils/file_util.h" - -namespace bf = boost::filesystem; -namespace bs = boost::system; - -namespace { - -const char kSharedLocation[] = "shared"; -const char kResWgtSubPath[] = "res/wgt"; -const char kTemporaryData[] = "tmp"; - -} // namespace - -namespace wgt { -namespace filesystem { - -common_installer::Step::Status StepWgtCreateStorageDirectories::process() { - if (!PrivateDir()) - return Status::ERROR; - - char version = context_->manifest_data.get()->api_version[0]; - - if ((version-'0') < 3) { - LOG(DEBUG) << "Shared directory preparation for tizen 2.x"; - if (!ShareDir()) - return Status::ERROR; - } else { - LOG(DEBUG) << "Shared directory preparation for tizen 3.x"; - if (!ShareDirFor3x()) - return Status::ERROR; - } - - if (!SubShareDir()) - return Status::ERROR; - - if (!CreatePrivateTmpDir()) - return Status::ERROR; - - if (!CacheDir()) - return Status::ERROR; - - return Status::OK; -} - -bool StepWgtCreateStorageDirectories::ShareDirFor2x() { - bs::error_code error_code; - bf::path shared_path = context_->pkg_path.get() / kSharedLocation; - bf::create_directory(shared_path, error_code); - if (error_code) { - LOG(ERROR) << "Failed to create shared directory for widget"; - return false; - } - return true; -} - -bool StepWgtCreateStorageDirectories::ShareDirFor3x() { - bf::path res_wgt_path = context_->pkg_path.get() / kResWgtSubPath; - if (!bf::exists(res_wgt_path / kSharedLocation)) { - if (!ShareDir()) - return false; - } else { - bf::path src = res_wgt_path / kSharedLocation; - bf::path dst = context_->pkg_path.get() / kSharedLocation; - if (!common_installer::MoveDir(src, dst)) { - LOG(ERROR) << "Failed to move shared data from res/wgt to shared"; - return false; - } - - bs::error_code error_code; - bf::create_symlink(dst, src, error_code); - if (error_code) { - LOG(ERROR) << "Failed to create symbolic link for shared dir" - << boost::system::system_error(error_code).what(); - return false; - } - } // else - return true; -} - -bool StepWgtCreateStorageDirectories::CreatePrivateTmpDir() { - bs::error_code error_code; - bf::path tmp_path = context_->pkg_path.get() / kTemporaryData; - bf::create_directory(tmp_path, error_code); - if (error_code) { - LOG(ERROR) << "Failed to create private temporary directory for package"; - return false; - } - return true; -} - -} // namespace filesystem -} // namespace wgt diff --git a/src/wgt/step/step_wgt_create_storage_directories.h b/src/wgt/step/step_wgt_create_storage_directories.h deleted file mode 100644 index 44015c1..0000000 --- a/src/wgt/step/step_wgt_create_storage_directories.h +++ /dev/null @@ -1,77 +0,0 @@ -// Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved -// Use of this source code is governed by an apache 2.0 license that can be -// found in the LICENSE file. - -#ifndef WGT_STEP_STEP_WGT_CREATE_STORAGE_DIRECTORIES_H_ -#define WGT_STEP_STEP_WGT_CREATE_STORAGE_DIRECTORIES_H_ - -#include - -#include "common/step/step_create_storage_directories.h" - -namespace wgt { -namespace filesystem { - -/** - * \brief Installation (WGT). - * Responsible for creating shared and data directories. - * It extends StepCreateStorageDirectories (it adds distinction between - * 2.x and 3.x shared dir handling - * - * process method implements creation of shared and data directories. - * Depending on tizen required version it can also move "shared" resources - * from ./res/wgt/shared to ./shared dir (and create symlink back - * to ./res/wgt/shared). - * - * StepWgtCreateStorageDirectories works on following directory: - * * TZ_SYS_RW/PKGID (/usr/apps/PKGID) - * * TZ_SER_APPS/PKGID (/{HOME}/apps_rw/PKGID) - */ -class StepWgtCreateStorageDirectories : - public common_installer::filesystem::StepCreateStorageDirectories { - public: - using StepCreateStorageDirectories::StepCreateStorageDirectories; - - /** - * \brief Create shared and private directories - * - * \return Status::ERROR when failed to create temporary location, or - * private temporary location - * Status::OK otherwise - */ - Status process() override; - - /** - * \brief Empty method - * - * \return Status::OK - */ - Status clean() override { return Status::OK; } - - /** - * \brief Empty method - * - * \return Status::OK - */ - Status undo() override { return Status::OK; } - - /** - * \brief Empty method - * - * \return Status::OK - */ - Status precheck() override { return Status::OK; } - - private: - bool ShareDirFor2x(); - bool ShareDirFor3x(); - - bool CreatePrivateTmpDir(); - - SCOPE_LOG_TAG(CreateWgtStorageDirectories) -}; - -} // namespace filesystem -} // namespace wgt - -#endif // WGT_STEP_STEP_WGT_CREATE_STORAGE_DIRECTORIES_H_ diff --git a/src/wgt/step/step_wgt_resource_directory.cc b/src/wgt/step/step_wgt_resource_directory.cc deleted file mode 100644 index 26332e4..0000000 --- a/src/wgt/step/step_wgt_resource_directory.cc +++ /dev/null @@ -1,44 +0,0 @@ -// Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved -// Use of this source code is governed by a apache 2.0 license that can be -// found in the LICENSE file. - -#include "wgt/step/step_wgt_resource_directory.h" - -#include - -#include "common/utils/file_util.h" - -namespace bf = boost::filesystem; -namespace bs = boost::system; - -namespace wgt { -namespace filesystem { - -common_installer::Step::Status StepWgtResourceDirectory::process() { - bf::path temp_path = context_->unpacked_dir_path.get(); - temp_path += ".temp"; - bf::path resource_path = context_->unpacked_dir_path.get() / "res/wgt"; - - if (!common_installer::MoveDir(context_->unpacked_dir_path.get(), - temp_path)) { - LOG(ERROR) << "Failed to move: " << context_->unpacked_dir_path.get() - << " to: " << temp_path; - return Status::ERROR; - } - bs::error_code error; - bf::create_directories(resource_path.parent_path(), error); - if (error) { - LOG(ERROR) << "Failed to create proper directory structure in widget"; - return Status::ERROR; - } - if (!common_installer::MoveDir(temp_path, resource_path)) { - LOG(ERROR) << "Failed to move: " << temp_path << " to: " << resource_path; - return Status::ERROR; - } - - LOG(INFO) << "Widget content moved to res/wgt subdirectory"; - return Status::OK; -} - -} // namespace filesystem -} // namespace wgt diff --git a/src/wgt/step/step_wgt_resource_directory.h b/src/wgt/step/step_wgt_resource_directory.h deleted file mode 100644 index 3ff8289..0000000 --- a/src/wgt/step/step_wgt_resource_directory.h +++ /dev/null @@ -1,62 +0,0 @@ -// Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved -// Use of this source code is governed by a apache 2.0 license that can be -// found in the LICENSE file. - -#ifndef WGT_STEP_STEP_WGT_RESOURCE_DIRECTORY_H_ -#define WGT_STEP_STEP_WGT_RESOURCE_DIRECTORY_H_ - -#include - -#include "common/app_installer.h" -#include "common/installer_context.h" -#include "common/step/step.h" - -namespace wgt { -namespace filesystem { - -/** - * \brief This step fixes unpacked directory structure so that all widget - * content is moved from root path to res/wgt before we copy whole directory in - * StepCopy - */ -class StepWgtResourceDirectory : public common_installer::Step { - public: - using Step::Step; - - /** - * \brief Create directory structure and copy content of widget package - * - * \return Status::ERROR when failed to create proper directory structure or - * move source directory to destination directory, - * Status::OK otherwise - */ - Status process() override; - - /** - * \brief Empty method - * - * \return Status::OK - */ - Status clean() override { return Status::OK; } - - /** - * \brief Empty method - * - * \return Status::OK - */ - Status undo() override { return Status::OK; } - - /** - * \brief Empty method - * - * \return Status::OK - */ - Status precheck() override { return Status::OK; } - - SCOPE_LOG_TAG(CreateWgtResourceDirectory) -}; - -} // namespace filesystem -} // namespace wgt - -#endif // WGT_STEP_STEP_WGT_RESOURCE_DIRECTORY_H_ diff --git a/src/wgt/wgt_app_query_interface.cc b/src/wgt/wgt_app_query_interface.cc deleted file mode 100644 index cbd921a..0000000 --- a/src/wgt/wgt_app_query_interface.cc +++ /dev/null @@ -1,100 +0,0 @@ -// Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved -// Use of this source code is governed by an apache 2.0 license that can be -// found in the LICENSE file. - -#include "wgt/wgt_app_query_interface.h" - -#include -#include - -#include -#include -#include - -#include -#include -#include -#include -#include - -#include -#include -#include - -#include "common/pkgmgr_registration.h" -#include "common/request.h" -#include "common/utils/file_util.h" - -namespace bf = boost::filesystem; -namespace bs = boost::system; -namespace ci = common_installer; - -namespace { - -std::string GetInstallationPackagePath(int argc, char** argv) { - std::string path; - for (int i = 0; i < argc; ++i) { - if (!strcmp(argv[i], "-i")) { - if (i + 1 < argc) { - path = argv[i + 1]; - break; - } - } - } - return path; -} - -std::string GetPkgIdFromPath(const std::string& path) { - bf::path tmp_path = common_installer::GenerateTmpDir("/tmp"); - bs::error_code code; - bf::create_directories(tmp_path, code); - if (code) - return {}; - if (!common_installer::ExtractToTmpDir(path.c_str(), tmp_path, - "config.xml")) { - bf::remove_all(tmp_path, code); - return {}; - } - bf::path config_path = tmp_path / "config.xml"; - std::vector handlers = { - new wgt::parse::WidgetHandler(), - new wgt::parse::TizenApplicationHandler() - }; - std::unique_ptr registry( - new parser::ManifestHandlerRegistry(handlers)); - std::unique_ptr parser( - new parser::ManifestParser(std::move(registry))); - if (!parser->ParseManifest(config_path)) { - bf::remove_all(tmp_path, code); - return {}; - } - auto info = std::static_pointer_cast( - parser->GetManifestData( - wgt::application_widget_keys::kTizenApplicationKey)); - if (!info) { - bf::remove_all(tmp_path, code); - return {}; - } - std::string pkg_id = info->package(); - - bf::remove_all(tmp_path, code); - return pkg_id; -} - -} // namespace - -namespace wgt { - -bool WgtAppQueryInterface::IsAppInstalledByArgv(int argc, char** argv) { - std::string path = GetInstallationPackagePath(argc, argv); - if (path.empty()) { - // not the installaton - return false; - } - std::string pkg_id = GetPkgIdFromPath(path); - if (pkg_id.empty()) - return false; - return ci::IsPackageInstalled(pkg_id, ci::GetRequestMode()); -} - -} // namespace wgt diff --git a/src/wgt/wgt_app_query_interface.h b/src/wgt/wgt_app_query_interface.h deleted file mode 100644 index c717b14..0000000 --- a/src/wgt/wgt_app_query_interface.h +++ /dev/null @@ -1,33 +0,0 @@ -// Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved -// Use of this source code is governed by an apache 2.0 license that can be -// found in the LICENSE file. - -#ifndef WGT_WGT_APP_QUERY_INTERFACE_H_ -#define WGT_WGT_APP_QUERY_INTERFACE_H_ - -#include "common/app_query_interface.h" - -namespace wgt { - -/** - * \brief Helper functionalities used before - * configuring app-installer steps. - * Eg. it is used to check, if package is to be installed or updated - */ -class WgtAppQueryInterface : public common_installer::AppQueryInterface { - public: - /** - * \brief method for checking if package is installed based - * on argv - * - * \param argc main() argc argument passed to the backend - * \param argv main() argv argument passed to the backend - * - * \return true if package is installed - */ - bool IsAppInstalledByArgv(int argc, char** argv) override; -}; - -} // namespace wgt - -#endif // WGT_WGT_APP_QUERY_INTERFACE_H_ diff --git a/src/wgt/wgt_backend.cc b/src/wgt/wgt_backend.cc deleted file mode 100644 index 32fb062..0000000 --- a/src/wgt/wgt_backend.cc +++ /dev/null @@ -1,23 +0,0 @@ -/* 2014, Copyright © Intel Coporation, license APACHE-2.0, see LICENSE file */ -// Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved -// Use of this source code is governed by a apache 2.0 license that can be -// found in the LICENSE file. - -#include - -#include "common/pkgmgr_interface.h" -#include "wgt/wgt_app_query_interface.h" -#include "wgt/wgt_installer.h" - -namespace ci = common_installer; - -int main(int argc, char** argv) { - wgt::WgtAppQueryInterface query_interface; - auto pkgmgr = ci::PkgMgrInterface::Create(argc, argv, &query_interface); - if (!pkgmgr) { - LOG(ERROR) << "Options of pkgmgr installer cannot be parsed"; - return EINVAL; - } - wgt::WgtInstaller installer(pkgmgr); - return (installer.Run() == ci::AppInstaller::Result::OK) ? 0 : 1; -} diff --git a/src/wgt/wgt_backend_data.h b/src/wgt/wgt_backend_data.h deleted file mode 100644 index cb7c650..0000000 --- a/src/wgt/wgt_backend_data.h +++ /dev/null @@ -1,47 +0,0 @@ -// Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved -// Use of this source code is governed by a apache 2.0 license that can be -// found in the LICENSE file. - -#ifndef WGT_WGT_BACKEND_DATA_H_ -#define WGT_WGT_BACKEND_DATA_H_ - -#include - -#include -#include - -#include "common/installer_context.h" -#include "common/utils/property.h" - -namespace wgt { - -/** - * \brief Class that is used within specific backends to keep additional - * information regarding package - */ -class WgtBackendData : public common_installer::BackendData { - public: - /** - * \brief Property of vector of files to add - */ - Property> files_to_add; - - /** - * \brief Property of vector of files to modify - */ - Property> files_to_modify; - - /** - * \brief Property of vector of files to delete - */ - Property> files_to_delete; - - /** - * \brief Property of SettingInfo - */ - Property settings; -}; - -} // namespace wgt - -#endif // WGT_WGT_BACKEND_DATA_H_ diff --git a/src/wgt/wgt_installer.cc b/src/wgt/wgt_installer.cc deleted file mode 100644 index 00a0c21..0000000 --- a/src/wgt/wgt_installer.cc +++ /dev/null @@ -1,179 +0,0 @@ -// Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved -// Use of this source code is governed by an apache-2.0 license that can be -// found in the LICENSE file. - -#include "wgt/wgt_installer.h" - -#include - -#include "common/pkgmgr_interface.h" -#include "common/step/step_configure.h" -#include "common/step/step_backup_manifest.h" -#include "common/step/step_backup_icons.h" -#include "common/step/step_copy.h" -#include "common/step/step_copy_backup.h" -#include "common/step/step_copy_storage_directories.h" -#include "common/step/step_delta_patch.h" -#include "common/step/step_fail.h" -#include "common/step/step_kill_apps.h" -#include "common/step/step_open_recovery_file.h" -#include "common/step/step_parse.h" -#include "common/step/step_privilege_compatibility.h" -#include "common/step/step_register_app.h" -#include "common/step/step_recover_application.h" -#include "common/step/step_recover_files.h" -#include "common/step/step_recover_icons.h" -#include "common/step/step_recover_manifest.h" -#include "common/step/step_recover_security.h" -#include "common/step/step_recover_storage_directories.h" -#include "common/step/step_remove_icons.h" -#include "common/step/step_remove_files.h" -#include "common/step/step_remove_temporary_directory.h" -#include "common/step/step_revoke_security.h" -#include "common/step/step_register_security.h" -#include "common/step/step_rollback_deinstallation_security.h" -#include "common/step/step_rollback_installation_security.h" -#include "common/step/step_old_manifest.h" -#include "common/step/step_check_signature.h" -#include "common/step/step_unregister_app.h" -#include "common/step/step_unzip.h" -#include "common/step/step_update_app.h" -#include "common/step/step_update_security.h" -#include "common/step/step_check_old_certificate.h" - -#include "wgt/step/step_add_default_privileges.h" -#include "wgt/step/step_check_settings_level.h" -#include "wgt/step/step_check_wgt_background_category.h" -#include "wgt/step/step_create_symbolic_link.h" -#include "wgt/step/step_encrypt_resources.h" -#include "wgt/step/step_generate_xml.h" -#include "wgt/step/step_parse.h" -#include "wgt/step/step_parse_recovery.h" -#include "wgt/step/step_rds_modify.h" -#include "wgt/step/step_rds_parse.h" -#include "wgt/step/step_remove_encryption_data.h" -#include "wgt/step/step_wgt_copy_storage_directories.h" -#include "wgt/step/step_wgt_create_icons.h" -#include "wgt/step/step_wgt_create_storage_directories.h" -#include "wgt/step/step_wgt_resource_directory.h" - -namespace ci = common_installer; - -namespace wgt { - -WgtInstaller::WgtInstaller(ci::PkgMgrPtr pkgrmgr) - : AppInstaller("wgt", pkgrmgr) { - /* treat the request */ - switch (pkgmgr_->GetRequestType()) { - case ci::RequestType::Install : { - AddStep(pkgmgr_); - AddStep(); - AddStep(true); - AddStep(); - AddStep(); - AddStep(); - AddStep(); - AddStep(); - AddStep(); - AddStep(); - AddStep(); - AddStep(); - AddStep(); - AddStep(); - AddStep(); - AddStep(); - AddStep(); - break; - } - case ci::RequestType::Update: { - AddStep(pkgmgr_); - AddStep(); - AddStep(true); - AddStep(); - AddStep(); - AddStep(); - AddStep(); - AddStep(); - AddStep(); - AddStep(); - AddStep(); - AddStep(); - AddStep(); - AddStep(); - AddStep(); - AddStep(); - AddStep(); - AddStep(); - AddStep(); - AddStep(); - break; - } - case ci::RequestType::Uninstall: { - AddStep(pkgmgr_); - AddStep(); - AddStep(); - AddStep(); - AddStep(); - AddStep(); - AddStep(); - AddStep(); - AddStep(); - AddStep(); - break; - } - case ci::RequestType::Reinstall: { - AddStep(pkgmgr_); - AddStep(false); - AddStep(); - AddStep(); - AddStep(); - AddStep(); - AddStep(); - break; - } - case ci::RequestType::Delta: { - AddStep(pkgmgr_); - AddStep(); - // TODO(t.iwanek): manifest is parsed twice... - AddStep(false); // start file may not have changed - AddStep("res/wgt/"); - AddStep(true); - AddStep(); - AddStep(); - AddStep(); - AddStep(); - AddStep(); - AddStep(); - AddStep(); - AddStep(); - AddStep(); - AddStep(); - AddStep(); - AddStep(); - AddStep(); - AddStep(); - AddStep(); - AddStep(); - AddStep(); - break; - } - case ci::RequestType::Recovery: { - AddStep(pkgmgr_); - AddStep(); - AddStep(); - AddStep(); - AddStep(); - AddStep(); - AddStep(); - AddStep(); - AddStep(); - AddStep(); - break; - } - default: { - AddStep(); - } - } -} - -} // namespace wgt diff --git a/src/wgt/wgt_installer.h b/src/wgt/wgt_installer.h deleted file mode 100644 index 47a119f..0000000 --- a/src/wgt/wgt_installer.h +++ /dev/null @@ -1,31 +0,0 @@ -// Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved -// Use of this source code is governed by an apache-2.0 license that can be -// found in the LICENSE file. - -#ifndef WGT_WGT_INSTALLER_H_ -#define WGT_WGT_INSTALLER_H_ - -#include "common/app_installer.h" - -namespace wgt { - -/** - * \brief The WgtInstaller class - * Subclass of AppInstaller class dedicated for handling wgt request - * - * Performs all types of requests of wgt packages and sets required sequence of - * steps - */ -class WgtInstaller : public common_installer::AppInstaller { - public: - /** - * \brief Explicit constructor - * - * \param pkgmgr pointer to pkgmgr - */ - explicit WgtInstaller(common_installer::PkgMgrPtr pkgrmgr); -}; - -} // namespace wgt - -#endif // WGT_WGT_INSTALLER_H_