diff options
47 files changed, 964 insertions, 344 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index c3c524f..2126276 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -70,7 +70,7 @@ ADD_DEFINITIONS("-Wall") # Generate all warnings ADD_DEFINITIONS("-Wextra") # Generate even more extra warnings ADD_DEFINITIONS("-Wno-variadic-macros") # Inhibit variadic macros warnings (needed for ORM) ADD_DEFINITIONS("-Wno-deprecated") # No warnings about deprecated features -ADD_DEFINITIONS("-std=c++0x") # No warnings about deprecated features +ADD_DEFINITIONS("-std=c++0x") # accept C++11x standard #ADD_DEFINITIONS("-DWRT_SMACK_ENABLED") ############################# Targets names ################################### diff --git a/debian/changelog b/debian/changelog index ff1aa77..4a47ced 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,3 +1,15 @@ +wrt-installer (0.0.54) unstable; urgency=low + + * Parsing XML namespace from config.xml bug fix. + * code clean up + * TaskDbUpdate splitted into TaskDbUpdate and TaskFileManipulation + * Widget paths refactor + + * Git : framework/web/wrt-installer + * Tag : wrt-installer_0.0.54 + + -- Tae-Jeong Lee <taejeong.lee@samsung.com> Fri, 31 Aug 2012 20:38:33 +0900 + wrt-installer (0.0.53) unstable; urgency=low * [Installer] Add encrypt task diff --git a/packaging/wrt-installer.spec b/packaging/wrt-installer.spec index 1f49c19..653c2de 100644 --- a/packaging/wrt-installer.spec +++ b/packaging/wrt-installer.spec @@ -1,7 +1,7 @@ -#sbs-git:slp/pkgs/w/wrt-installer wrt-installer 0.0.53 +#sbs-git:slp/pkgs/w/wrt-installer wrt-installer 0.0.54 Name: wrt-installer Summary: Installer for tizen Webruntime -Version: 0.0.53 +Version: 0.0.54 Release: 1 Group: Development/Libraries License: Apache License, Version 2.0 diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index b25090b..559fa55 100755 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -52,7 +52,6 @@ SET(INSTALLER_SOURCES ${INSTALLER_CONFIG_PARSER}/ignoring_parser.cpp ${INSTALLER_CONFIG_PARSER}/deny_all_parser.cpp ${INSTALLER_CONFIG_PARSER}/libiriwrapper.cpp - ${INSTALLER_CONFIG_PARSER}/WidgetConfigurationManager.cpp ${INSTALLER_JOBS}/job.cpp ${INSTALLER_JOBS}/plugin_install/job_plugin_install.cpp ${INSTALLER_JOBS}/plugin_install/plugin_install_task.cpp @@ -64,6 +63,7 @@ SET(INSTALLER_SOURCES ${INSTALLER_JOBS}/widget_install/task_unzip.cpp ${INSTALLER_JOBS}/widget_install/task_widget_config.cpp ${INSTALLER_JOBS}/widget_install/task_db_update.cpp + ${INSTALLER_JOBS}/widget_install/task_file_manipulation.cpp ${INSTALLER_JOBS}/widget_install/task_smack.cpp ${INSTALLER_JOBS}/widget_install/task_ace_check.cpp ${INSTALLER_JOBS}/widget_install/task_manifest_file.cpp @@ -90,6 +90,7 @@ SET(INSTALLER_SOURCES ${INSTALLER_SRC_DIR}/misc/wac_widget_id.cpp ${INSTALLER_SRC_DIR}/misc/feature_logic.cpp ${INSTALLER_SRC_DIR}/misc/libxml_utils.cpp + ${INSTALLER_SRC_DIR}/misc/widget_location.cpp ${INSTALLER_SRC_DIR}/pkg-manager/pkgmgr_signal.cpp ) diff --git a/src/configuration_parser/element_parser.h b/src/configuration_parser/element_parser.h index 50a74bb..dc843b6 100644 --- a/src/configuration_parser/element_parser.h +++ b/src/configuration_parser/element_parser.h @@ -34,6 +34,7 @@ struct XmlAttribute { + DPL::String prefix; DPL::String name; DPL::String value; DPL::String ns; diff --git a/src/configuration_parser/parser_runner.cpp b/src/configuration_parser/parser_runner.cpp index 53c1f4b..6de0c0d 100644 --- a/src/configuration_parser/parser_runner.cpp +++ b/src/configuration_parser/parser_runner.cpp @@ -228,11 +228,13 @@ class ParserRunner::Impl XmlAttribute attribute; attribute.ns = GetAttributeNamespace(); + attribute.prefix = GetNamePrefix(); attribute.name = GetNameWithoutNamespace(); attribute.value = GetValue(); attribute.lang = GetLanguageTag(); LogDebug("Attribute name: " << attribute.name << ", value: " << attribute.value << + ", prefix: " << attribute.prefix << ", namespace: " << attribute.ns << ", lang: " << attribute.lang); parser->Accept(attribute); @@ -252,7 +254,8 @@ class ParserRunner::Impl DPL::String ret_value; const xmlChar* value = xmlTextReaderConstValue(m_reader); if (value) { - ret_value = DPL::FromUTF8String(reinterpret_cast<const char*>(value)); + ret_value = + DPL::FromUTF8String(reinterpret_cast<const char*>(value)); } return ret_value; @@ -263,7 +266,8 @@ class ParserRunner::Impl DPL::String ret_value; const xmlChar* value = xmlTextReaderGetAttributeNo(m_reader, pos); if (value) { - ret_value = DPL::FromUTF8String(reinterpret_cast<const char*>(value)); + ret_value = + DPL::FromUTF8String(reinterpret_cast<const char*>(value)); } xmlFree(const_cast<xmlChar*>(value)); @@ -275,7 +279,8 @@ class ParserRunner::Impl DPL::String ret_value; const xmlChar* value = xmlTextReaderLookupNamespace(m_reader, NULL); if (value) { - ret_value = DPL::FromUTF8String(reinterpret_cast<const char*>(value)); + ret_value = + DPL::FromUTF8String(reinterpret_cast<const char*>(value)); } xmlFree(const_cast<xmlChar*>(value)); @@ -287,7 +292,20 @@ class ParserRunner::Impl DPL::String ret_value; const xmlChar* value = xmlTextReaderConstName(m_reader); if (value) { - ret_value = DPL::FromUTF8String(reinterpret_cast<const char*>(value)); + ret_value = + DPL::FromUTF8String(reinterpret_cast<const char*>(value)); + } + + return ret_value; + } + + DPL::String GetNamePrefix() const + { + DPL::String ret_value; + const xmlChar* value = xmlTextReaderPrefix(m_reader); + if (value) { + ret_value = + DPL::FromUTF8String(reinterpret_cast<const char*>(value)); } return ret_value; @@ -298,7 +316,8 @@ class ParserRunner::Impl DPL::String ret_value; const xmlChar* value = xmlTextReaderLocalName(m_reader); if (value) { - ret_value = DPL::FromUTF8String(reinterpret_cast<const char*>(value)); + ret_value = + DPL::FromUTF8String(reinterpret_cast<const char*>(value)); } return ret_value; @@ -310,7 +329,8 @@ class ParserRunner::Impl const xmlChar* value = xmlTextReaderConstNamespaceUri(m_reader); if (value) { - ret_value = DPL::FromUTF8String(reinterpret_cast<const char*>(value)); + ret_value = + DPL::FromUTF8String(reinterpret_cast<const char*>(value)); } return ret_value; @@ -321,7 +341,8 @@ class ParserRunner::Impl DPL::String ret_value; const xmlChar* value = xmlTextReaderConstXmlLang(m_reader); if (value) { - ret_value = DPL::FromUTF8String(reinterpret_cast<const char*>(value)); + ret_value = + DPL::FromUTF8String(reinterpret_cast<const char*>(value)); } return ret_value; diff --git a/src/configuration_parser/widget_parser.cpp b/src/configuration_parser/widget_parser.cpp index b602d02..4d4262e 100755 --- a/src/configuration_parser/widget_parser.cpp +++ b/src/configuration_parser/widget_parser.cpp @@ -1552,8 +1552,7 @@ void WidgetParser::Accept(const XmlAttribute& attribute) } //Any other value consider as a namespace definition - } else if (attribute.name == L"xmlns" || - attribute.ns == m_nameSpaces[L"xmlns"]) { + } else if (attribute.name == L"xmlns" || attribute.prefix == L"xmlns") { LogInfo("Namespace domain: " << attribute.name); LogInfo("Namespace value: " << attribute.value); m_nameSpaces[attribute.name] = attribute.value; diff --git a/src/jobs/job.cpp b/src/jobs/job.cpp index 70fef1a..64903b2 100644 --- a/src/jobs/job.cpp +++ b/src/jobs/job.cpp @@ -73,7 +73,7 @@ void Job::Resume() m_paused = false; // Trigger next steps - CONTROLLER_POST_EVENT(InstallerController, + CONTROLLER_POST_EVENT(Logic::InstallerController, InstallerControllerEvents::NextStepEvent(this)); } diff --git a/src/jobs/widget_install/job_widget_install.cpp b/src/jobs/widget_install/job_widget_install.cpp index 24db446..059a957 100755 --- a/src/jobs/widget_install/job_widget_install.cpp +++ b/src/jobs/widget_install/job_widget_install.cpp @@ -30,6 +30,7 @@ #include <dpl/assert.h> #include <dpl/sstream.h> #include <dpl/wrt-dao-ro/common_dao_types.h> +#include <dpl/utils/file_utils.h> #include "root_parser.h" #include "widget_parser.h" #include "parser_runner.h" @@ -38,6 +39,7 @@ #include <widget_install/task_certify.h> #include <widget_install/task_widget_config.h> #include <widget_install/task_db_update.h> +#include <widget_install/task_file_manipulation.h> #include <widget_install/task_ace_check.h> #include <widget_install/task_smack.h> #include <widget_install/task_manifest_file.h> @@ -130,9 +132,9 @@ JobWidgetInstall::JobWidgetInstall(std::string const &widgetPath, m_exceptionCaught(Exceptions::Success) { // Check installation type (config.xml or widget.wgt) - m_installerContext.browserRequest = hasExtension(widgetPath, XML_EXTENSION); + bool browserRequest = hasExtension(widgetPath, XML_EXTENSION); - LogInfo("Hosted app installation: " << m_installerContext.browserRequest); + LogInfo("Hosted app installation: " << browserRequest); struct timeval tv; gettimeofday(&tv, NULL); @@ -146,17 +148,25 @@ JobWidgetInstall::JobWidgetInstall(std::string const &widgetPath, m_installerContext.widgetHandle = handle; m_installerContext.m_quiet = m_jobStruct.m_quiet; - m_installerContext.widgetConfig.pType = checkPackageType(widgetPath); + if(!browserRequest) + { + m_installerContext.widgetConfig.pType = checkPackageType(widgetPath); + } + else + { + m_installerContext.widgetConfig.pType = WrtDB::PKG_TYPE_TIZEN_WEBAPP; + } + LogDebug("widgetPath:" << widgetPath); - ConfigParserData configData = getWidgetDataFromXML(widgetPath, - m_installerContext.browserRequest, + ConfigParserData configData = getWidgetDataFromXML(widgetPath, browserRequest, m_installerContext.widgetConfig.pType); WidgetUpdateInfo update = detectWidgetUpdate(configData); + bool needEncryption = detectResourceEncryption(configData); + // Configure installation - ConfigureResult result = ConfigureInstallation(widgetPath, - m_installerContext.browserRequest, update); + ConfigureResult result = ConfigureInstallation(widgetPath, update); if (!setTizenId(configData)) { result = ConfigureResult::Failed; } else { @@ -164,6 +174,8 @@ JobWidgetInstall::JobWidgetInstall(std::string const &widgetPath, LogInfo("WidgetHandle: " << m_installerContext.widgetHandle); LogInfo("Tizen Id: " << m_installerContext.widgetConfig.pkgname); + configureWidgetLocation(widgetPath, browserRequest); + // send start signal of pkgmgr PkgmgrSignalSingleton::Instance().setPkgname( DPL::ToUTF8String( @@ -172,22 +184,25 @@ JobWidgetInstall::JobWidgetInstall(std::string const &widgetPath, PKGMGR_START_KEY, PKGMGR_START_INSTALL); } - if (result == ConfigureResult::Ok) { LogInfo("Configure installation succeeded"); AddTask(new TaskRecovery(m_installerContext)); // Create installation tasks - if (!m_installerContext.browserRequest) { + if (!m_installerContext.locations->browserRequest()) { AddTask(new TaskUnzip(m_installerContext)); } AddTask(new TaskWidgetConfig(m_installerContext)); + if (m_installerContext.locations->browserRequest()) { + AddTask(new TaskPrepareFiles(m_installerContext)); + } AddTask(new TaskCertify(m_installerContext)); if (needEncryption) { AddTask(new TaskEncryptResource(m_installerContext)); } AddTask(new TaskDbUpdate(m_installerContext)); + AddTask(new TaskFileManipulation(m_installerContext)); // TODO: Update progress information for this task AddTask(new TaskPrivateStorage(m_installerContext)); @@ -206,10 +221,13 @@ JobWidgetInstall::JobWidgetInstall(std::string const &widgetPath, LogInfo("Configure installation updated"); LogInfo("Widget Update"); - if (!m_installerContext.browserRequest) { + if (!m_installerContext.locations->browserRequest()) { AddTask(new TaskUnzip(m_installerContext)); } AddTask(new TaskWidgetConfig(m_installerContext)); + if (m_installerContext.locations->browserRequest()) { + AddTask(new TaskPrepareFiles(m_installerContext)); + } AddTask(new TaskCertify(m_installerContext)); AddTask(new TaskUpdateFiles(m_installerContext)); @@ -339,9 +357,24 @@ DPL::Optional<WidgetHandle> JobWidgetInstall::getNewWidgetHandle() const return m_installerContext.widgetHandle; } +void JobWidgetInstall::configureWidgetLocation(const std::string & widgetPath, bool browserRequest) +{ + Try + { + m_installerContext.locations = WidgetLocation(DPL::ToUTF8String(*m_installerContext.widgetConfig.pkgname), + widgetPath, browserRequest, m_installerContext.widgetConfig.pType); + } + Catch(FileUtils::CreateDirectoryException) + { + LogError("Failed to create temporary path for widget"); + ReThrowMsg(FileUtils::CreateDirectoryException, "Failed to create temporary path for widget"); + } + + LogInfo("widgetSource " << widgetPath); +} + JobWidgetInstall::ConfigureResult JobWidgetInstall::ConfigureInstallation( const std::string &widgetSource, - bool fromBrowser, const WidgetUpdateInfo &update) { LogInfo( @@ -401,20 +434,6 @@ JobWidgetInstall::ConfigureResult JobWidgetInstall::ConfigureInstallation( LogInfo("Whether widget policy allow proceed: " << canProceed); // Init installer context - m_installerContext.widgetSource = widgetSource; - m_installerContext.tempWidgetPath = std::string(); - - // setup config xml path - if (fromBrowser) { - LogInfo("widgetSource " << widgetSource); - size_t slash = widgetSource.find_last_of("\\/"); - if (std::string::npos != slash) { - m_installerContext.tempWidgetPath = widgetSource.substr(0, slash+1); - } else { - m_installerContext.tempWidgetPath = "."; - } - } - m_installerContext.installStep = InstallerContext::INSTALL_START; m_installerContext.job = this; m_installerContext.existingWidgetInfo = update.existingWidgetInfo; diff --git a/src/jobs/widget_install/job_widget_install.h b/src/jobs/widget_install/job_widget_install.h index 23b5b26..6230d17 100644 --- a/src/jobs/widget_install/job_widget_install.h +++ b/src/jobs/widget_install/job_widget_install.h @@ -46,7 +46,7 @@ class JobWidgetInstall : InstallerContext m_installerContext; - //TODO move it to base class of all jobs + //TODO move it to base class of all jobs -> make it base template class?? Exceptions::Type m_exceptionCaught; std::string m_exceptionMessage; WidgetUpdateInfo m_widgetUpdateInfo; @@ -57,7 +57,6 @@ class JobWidgetInstall : }; ConfigureResult ConfigureInstallation(const std::string &widgetSource, - bool fromBrowser, const WidgetUpdateInfo &update); static WrtDB::ConfigParserData getWidgetDataFromXML( const std::string &widgetSource, @@ -69,6 +68,7 @@ class JobWidgetInstall : const OptionalWidgetVersion &incomingVersion) const; bool setTizenId(const WrtDB::ConfigParserData &configInfo); void displayWidgetInfo(); + void configureWidgetLocation(const std::string & widgetPath, bool browserRequest); WrtDB::PackagingType checkPackageType( const std::string &widgetSorce); diff --git a/src/jobs/widget_install/manifest.cpp b/src/jobs/widget_install/manifest.cpp index e828d78..039bbb4 100644 --- a/src/jobs/widget_install/manifest.cpp +++ b/src/jobs/widget_install/manifest.cpp @@ -108,7 +108,6 @@ void writeAttribute(xmlTextWriterPtr writer, const char * name, const char * bod } } -//TODO shouldn't XML file creation happen here? If no, this method is not needed void Manifest::generate(DPL::String filename) { xmlTextWriterPtr writer; diff --git a/src/jobs/widget_install/task_ace_check.cpp b/src/jobs/widget_install/task_ace_check.cpp index 3962441..192247f 100644 --- a/src/jobs/widget_install/task_ace_check.cpp +++ b/src/jobs/widget_install/task_ace_check.cpp @@ -95,7 +95,7 @@ void TaskAceCheck::StepAceCheck() void TaskAceCheck::StepProcessAceResponse() { - if (m_context.browserRequest) { + if (m_context.locations->browserRequest()) { return; } diff --git a/src/jobs/widget_install/task_certify.cpp b/src/jobs/widget_install/task_certify.cpp index 2c2e7b5..ab6d26c 100755 --- a/src/jobs/widget_install/task_certify.cpp +++ b/src/jobs/widget_install/task_certify.cpp @@ -175,7 +175,7 @@ void TaskCertify::stepSignature() { LogInfo("enter"); - std::string widgetPath = m_contextData.tempWidgetRoot + "/"; + std::string widgetPath = m_contextData.locations->getTemporaryRootDir() + "/"; SignatureFileInfoSet signatureFiles; SignatureFinder signatureFinder(widgetPath); diff --git a/src/jobs/widget_install/task_commons.h b/src/jobs/widget_install/task_commons.h index 76306db..940c710 100644 --- a/src/jobs/widget_install/task_commons.h +++ b/src/jobs/widget_install/task_commons.h @@ -27,6 +27,8 @@ namespace Jobs { namespace WidgetInstall { +//TODO make directory like jobs common? + void removeTemporaryDir(const std::string& path); std::string createTempPath(); diff --git a/src/jobs/widget_install/task_db_update.cpp b/src/jobs/widget_install/task_db_update.cpp index 4804bce..5b02a95 100644 --- a/src/jobs/widget_install/task_db_update.cpp +++ b/src/jobs/widget_install/task_db_update.cpp @@ -19,8 +19,7 @@ * @version 1.0 * @brief Implementation file for installer task database updating */ -#include <time.h> -#include <sys/stat.h> +//#include <time.h> #include <widget_install/task_db_update.h> #include <widget_install/job_widget_install.h> #include <widget_install/widget_install_errors.h> @@ -33,7 +32,6 @@ #include <dpl/assert.h> #include <dpl/wrt-dao-ro/global_config.h> #include <string> -//#include <widget_controller.h> #include <Ecore_File.h> #include <sstream> @@ -46,46 +44,8 @@ TaskDbUpdate::TaskDbUpdate(InstallerContext& context) : m_context(context) { AddStep(&TaskDbUpdate::StepDbUpdate); - AddStep(&TaskDbUpdate::StepCreateDirs); - AddStep(&TaskDbUpdate::StepRenamePath); - AddAbortStep(&TaskDbUpdate::StepAbortDBUpdate); - AddAbortStep(&TaskDbUpdate::StepAbortRenamePath); -} - -void TaskDbUpdate::StepCreateDirs() -{ - std::ostringstream widgetPath; - DPL::OptionalString pkgname = m_context.widgetConfig.pkgname; - if (pkgname.IsNull()) { - ThrowMsg(Exceptions::InternalError, "No Package name exists."); - } - - widgetPath << GlobalConfig::GetUserInstalledWidgetPath() << "/"; - widgetPath << pkgname << "/"; - - std::string widgetBinPath = widgetPath.str(); - std::string widgetSrcPath = widgetPath.str(); - - _WrtMakeDir(widgetPath.str().c_str(), 0755, WRT_FILEUTILS_RECUR); - - // If pakcage type is widget with osp service, we don't need to make bin - // and src directory - if (m_context.widgetConfig.pType == PKG_TYPE_TIZEN_WITHSVCAPP) { - LogDebug("Doesn't need to create resource directory"); - } else { - LogDebug("Create resource directory"); - widgetBinPath += GlobalConfig::GetUserWidgetExecPath(); - _WrtMakeDir(widgetBinPath.c_str(), 0755, WRT_FILEUTILS_RECUR); - - widgetSrcPath += GlobalConfig::GetWidgetSrcPath(); - _WrtMakeDir(widgetSrcPath.c_str(), 0755, WRT_FILEUTILS_RECUR); - } - - m_context.job->UpdateProgress( - InstallerContext::INSTALL_DIR_CREATE, - "Widget Directory Created"); } void TaskDbUpdate::StepDbUpdate() @@ -139,45 +99,6 @@ void TaskDbUpdate::StepDbUpdate() "Widget DB UPDATE Finished"); } -void TaskDbUpdate::StepRenamePath() -{ - DPL::OptionalString pkgname = m_context.widgetConfig.pkgname; - if (pkgname.IsNull()) { - ThrowMsg(Exceptions::InternalError, "No Package name exists."); - } - - if (!_WrtUtilRemoveDir(m_context.installPath.c_str())) { - _WrtUtilChangeDir(GlobalConfig::GetUserInstalledWidgetPath()); - ThrowMsg(Exceptions::RemovingFolderFailure, - "Error occurs during removing existing folder"); - } - - if (m_context.widgetConfig.pType == PKG_TYPE_TIZEN_WITHSVCAPP) { - LogDebug("Copy file from temp directory to " << - m_context.installPath); - - if (rename(m_context.tempWidgetPath.c_str(), - m_context.installPath.c_str()) < 0) { - ThrowMsg(Exceptions::UnknownError, - "Error occurs during renaming widget folder"); - } - } else { - LogDebug("Copy file from temp directory to " << - m_context.installPath); - - if (!m_context.browserRequest) { - if (rename(m_context.tempWidgetRoot.c_str(), m_context.installPath.c_str()) < 0) { - ThrowMsg(Exceptions::UnknownError, - "Error occurs during renaming widget folder"); - } - } - } - - m_context.job->UpdateProgress( - InstallerContext::INSTALL_RENAME_PATH, - "Widget Rename path Finished"); -} - void TaskDbUpdate::StepAbortDBUpdate() { LogWarning("[DB Update Task] Aborting... (DB Clean)"); @@ -196,26 +117,5 @@ void TaskDbUpdate::StepAbortDBUpdate() } } -void TaskDbUpdate::StepAbortRenamePath() -{ - LogDebug("[Rename Widget Path] Aborting.... (Rename path)"); - Assert(!!m_context.widgetHandle); - std::ostringstream widgetPath; - widgetPath << GlobalConfig::GetUserInstalledWidgetPath() << "/"; - widgetPath << *m_context.widgetConfig.pkgname; - - struct stat fileInfo; - if (stat(widgetPath.str().c_str(), &fileInfo) != 0) { - LogError("Failed to get widget file path : " <<widgetPath.str()); - return; - } - - if (rename(widgetPath.str().c_str(), - m_context.tempWidgetPath.c_str()) < 0) { - LogError("Failed to rename"); - //Ignoring failures in Abort - } - LogDebug("Rename widget path sucessful!"); -} } //namespace WidgetInstall } //namespace Jobs diff --git a/src/jobs/widget_install/task_db_update.h b/src/jobs/widget_install/task_db_update.h index 59e9c37..3f76680 100644 --- a/src/jobs/widget_install/task_db_update.h +++ b/src/jobs/widget_install/task_db_update.h @@ -34,12 +34,9 @@ class TaskDbUpdate : private: InstallerContext& m_context; - void StepCreateDirs(); void StepDbUpdate(); - void StepRenamePath(); void StepAbortDBUpdate(); - void StepAbortRenamePath(); public: TaskDbUpdate(InstallerContext& context); diff --git a/src/jobs/widget_install/task_encrypt_resource.cpp b/src/jobs/widget_install/task_encrypt_resource.cpp index 6414eb7..91cef03 100644 --- a/src/jobs/widget_install/task_encrypt_resource.cpp +++ b/src/jobs/widget_install/task_encrypt_resource.cpp @@ -77,13 +77,7 @@ void TaskEncryptResource::StepEncryptResource() m_resEnc->CreateEncryptionKey(DPL::ToUTF8String(*m_context. widgetConfig.pkgname)); - if (m_context.widgetConfig.pType == PKG_TYPE_TIZEN_WITHSVCAPP) { - tempInstalledPath = m_context.tempWidgetPath; - } else { - tempInstalledPath = m_context.tempWidgetRoot; - } - - EncryptDirectory(tempInstalledPath); + EncryptDirectory(m_context.locations->getTemporaryRootDir()); } void TaskEncryptResource::EncryptDirectory(std::string path) @@ -173,8 +167,8 @@ void TaskEncryptResource::EncryptFile(const std::string &fileName) } std::string realPath = fileName; - realPath.replace(0, tempInstalledPath.length(), - m_context.installPath); + realPath.replace(0, m_context.locations->getTemporaryRootDir().length(), + m_context.locations->getPackageInstallationDir()); WrtDB::EncryptedFileInfo info; info.fileName = DPL::FromUTF8String(realPath); diff --git a/src/jobs/widget_install/task_file_manipulation.cpp b/src/jobs/widget_install/task_file_manipulation.cpp new file mode 100644 index 0000000..1bf51a8 --- /dev/null +++ b/src/jobs/widget_install/task_file_manipulation.cpp @@ -0,0 +1,129 @@ +/* + * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +/** + * @file task_db_update.cpp + * @author Lukasz Wrzosek(l.wrzosek@samsung.com) + * @version 1.0 + * @brief Implementation file for installer task database updating + */ +#include <sys/stat.h> +#include <widget_install/task_file_manipulation.h> +#include <widget_install/job_widget_install.h> +#include <widget_install/widget_install_errors.h> +#include <widget_install/widget_install_context.h> +#include <dpl/utils/wrt_utility.h> +#include <dpl/foreach.h> +#include <dpl/log/log.h> +#include <dpl/assert.h> +#include <string> + +using namespace WrtDB; + +namespace Jobs { +namespace WidgetInstall { +TaskFileManipulation::TaskFileManipulation(InstallerContext& context) : + DPL::TaskDecl<TaskFileManipulation>(this), + m_context(context) +{ + AddStep(&TaskFileManipulation::StepCreateDirs); + AddStep(&TaskFileManipulation::StepRenamePath); + + AddAbortStep(&TaskFileManipulation::StepAbortRenamePath); +} + +void TaskFileManipulation::StepCreateDirs() +{ + std::string widgetPath; + DPL::OptionalString pkgname = m_context.widgetConfig.pkgname; + if (pkgname.IsNull()) { + ThrowMsg(Exceptions::InternalError, "No Package name exists."); + } + + widgetPath = m_context.locations->getPackageInstallationDir(); + + std::string widgetBinPath = m_context.locations->getBinaryDir(); + std::string widgetSrcPath = m_context.locations->getSourceDir(); + + _WrtMakeDir(widgetPath.c_str(), 0755, WRT_FILEUTILS_RECUR); + + // If package type is widget with osp service, we don't need to make bin + // and src directory + if (m_context.widgetConfig.pType == PKG_TYPE_TIZEN_WITHSVCAPP) { + LogDebug("Doesn't need to create resource directory"); + } else { + LogDebug("Create resource directory"); + _WrtMakeDir(widgetBinPath.c_str(), 0755, WRT_FILEUTILS_RECUR); + _WrtMakeDir(widgetSrcPath.c_str(), 0755, WRT_FILEUTILS_RECUR); + } + + m_context.job->UpdateProgress( + InstallerContext::INSTALL_DIR_CREATE, + "Widget Directory Created"); +} + +void TaskFileManipulation::StepRenamePath() +{ + std::string instDir; + DPL::OptionalString pkgname = m_context.widgetConfig.pkgname; + if (pkgname.IsNull()) { + ThrowMsg(Exceptions::InternalError, "No Package name exists."); + } + + if (m_context.widgetConfig.pType == PKG_TYPE_TIZEN_WITHSVCAPP) { + instDir = m_context.locations->getPackageInstallationDir(); + } else { + instDir = m_context.locations->getSourceDir(); + } + + LogDebug("Copy file from temp directory to " << instDir); + if (!_WrtUtilRemoveDir(instDir.c_str())) { + ThrowMsg(Exceptions::RemovingFolderFailure, + "Error occurs during removing existing folder"); + } + + if (!(rename(m_context.locations->getTemporaryPackageDir().c_str(), instDir.c_str()) == 0)) { + ThrowMsg(Exceptions::UnknownError, + "Error occurs during renaming widget folder"); + } + + m_context.job->UpdateProgress( + InstallerContext::INSTALL_RENAME_PATH, + "Widget Rename path Finished"); +} + +void TaskFileManipulation::StepAbortRenamePath() +{ + LogDebug("[Rename Widget Path] Aborting.... (Rename path)"); + Assert(!!m_context.widgetHandle); + std::string widgetPath; + if (m_context.widgetConfig.pType == PKG_TYPE_TIZEN_WITHSVCAPP) { + widgetPath = m_context.locations->getPackageInstallationDir(); + } else { + widgetPath = m_context.locations->getSourceDir(); + } + struct stat fileInfo; + if (stat(widgetPath.c_str(), &fileInfo) != 0) { + LogError("Failed to get widget file path : " << widgetPath); + return; + } + + if (!(rename(widgetPath.c_str(), m_context.locations->getTemporaryPackageDir().c_str()) == 0)) { + LogError("Failed to rename"); + } + LogDebug("Rename widget path sucessful!"); +} +} //namespace WidgetInstall +} //namespace Jobs diff --git a/src/jobs/widget_install/task_file_manipulation.h b/src/jobs/widget_install/task_file_manipulation.h new file mode 100644 index 0000000..162dbbf --- /dev/null +++ b/src/jobs/widget_install/task_file_manipulation.h @@ -0,0 +1,48 @@ +/* + * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +/* + * @file task_db_update.h + * @author Lukasz Wrzosek(l.wrzosek@samsung.com) + * @version 1.0 + * @brief Header file for installer task database updating + */ +#ifndef INSTALLER_CORE_JOS_WIDGET_INSTALL_TASK_FILE_MANIPULATION_H +#define INSTALLER_CORE_JOS_WIDGET_INSTALL_TASK_FILE_MANIPULATION_UPDATE_H + +#include <dpl/task.h> + +class InstallerContext; + +namespace Jobs { +namespace WidgetInstall { +class TaskFileManipulation : + public DPL::TaskDecl<TaskFileManipulation> +{ + private: + InstallerContext& m_context; + + void StepCreateDirs(); + void StepRenamePath(); + + void StepAbortRenamePath(); + + public: + TaskFileManipulation(InstallerContext& context); +}; +} //namespace WidgetInstall +} //namespace Jobs + +#endif // INSTALLER_CORE_JOS_WIDGET_INSTALL_FILE_MANIPULATION_H diff --git a/src/jobs/widget_install/task_install_ospsvc.cpp b/src/jobs/widget_install/task_install_ospsvc.cpp index 0a26435..cb7f1fa 100644 --- a/src/jobs/widget_install/task_install_ospsvc.cpp +++ b/src/jobs/widget_install/task_install_ospsvc.cpp @@ -54,8 +54,7 @@ void TaskInstallOspsvc::StepInstallOspService() LogInfo("Step: installation for osp service"); std::ostringstream commStr; - commStr << OSP_INSTALL_STR << GlobalConfig::GetUserInstalledWidgetPath(); - commStr << "/" << m_context.widgetConfig.pkgname; + commStr << OSP_INSTALL_STR << m_context.locations->getPackageInstallationDir(); //commStr << " 2>&1"; LogDebug("osp install command : " << commStr.str()); diff --git a/src/jobs/widget_install/task_manifest_file.cpp b/src/jobs/widget_install/task_manifest_file.cpp index e6a8dce..d9104bf 100644 --- a/src/jobs/widget_install/task_manifest_file.cpp +++ b/src/jobs/widget_install/task_manifest_file.cpp @@ -131,10 +131,7 @@ void TaskManifestFile::stepCreateExecFile() ThrowMsg(Exceptions::InternalError, "No Package name exists."); } - real_path << GlobalConfig::GetUserInstalledWidgetPath() << "/"; - real_path << pkgname << "/"; - real_path << GlobalConfig::GetUserWidgetExecPath() << "/" << - m_context.widgetHandle; + real_path << m_context.locations->getBinaryDir() << "/" << m_context.widgetHandle; std::string clientExeStr = GlobalConfig::GetWrtClientExec(); LogInfo("link -s " << clientExeStr << " " << real_path.str()); @@ -175,14 +172,8 @@ void TaskManifestFile::stepCopyIconFiles() std::ostringstream targetFile; if (!!src) { - if (m_context.browserRequest) { - size_t pos = m_context.widgetSource.rfind("/"); - sourceFile << m_context.widgetSource.substr(0, pos+1); - } else { - sourceFile << GlobalConfig::GetUserInstalledWidgetPath() << "/"; - sourceFile << pkgname << "/"; - sourceFile << GlobalConfig::GetWidgetSrcPath() << "/"; - } + + sourceFile << m_context.locations->getSourceDir() << "/"; if (!i.empty()) { sourceFile << "locales/" << i << "/"; @@ -193,9 +184,11 @@ void TaskManifestFile::stepCopyIconFiles() targetFile << GlobalConfig::GetUserWidgetDesktopIconPath() << "/"; targetFile << getIconTargetFilename(i); - if (m_context.browserRequest) { - m_context.installedIconPath = targetFile.str(); + if (m_context.locations->browserRequest()) + { + m_context.locations->setIconTargetFilenameForLocale(targetFile.str()); } + } else { //Use WRT default (not from the widget) only if widget default (not // localized) doesn't exist. @@ -256,8 +249,7 @@ void TaskManifestFile::stepBackupIconFiles() { LogDebug("Backup Icon Files"); - backup_dir << GlobalConfig::GetUserInstalledWidgetPath(); - backup_dir << "/" << m_context.widgetConfig.pkgname; + backup_dir << m_context.locations->getPackageInstallationDir(); backup_dir << "/" << "backup" << "/"; backupIconFiles(); @@ -354,6 +346,7 @@ void TaskManifestFile::stepFinalize() LogInfo("Finished ManifestFile step"); } + void TaskManifestFile::saveLocalizedKey(std::ofstream &file, const DPL::String& key, const DPL::String& languageTag) @@ -593,8 +586,7 @@ void TaskManifestFile::setWidgetExecPath(UiApplication & uiApp) } std::ostringstream path; - path << GlobalConfig::GetUserInstalledWidgetPath() << "/" << *pkgname << "/"; - path << GlobalConfig::GetUserWidgetExecPath() << "/" << *m_context.widgetHandle; + path << m_context.locations->getBinaryDir() << "/" << *m_context.widgetHandle; uiApp.setExec(DPL::FromASCIIString(path.str())); } @@ -717,7 +709,9 @@ void TaskManifestFile::setWidgetIcons(UiApplication & uiApp) } } -void TaskManifestFile::generateWidgetIcon(UiApplication & uiApp, const DPL::OptionalString& tag, const DPL::String& language, int iconId, const WrtDB::WidgetDAOReadOnly::WidgetIconList & list, bool & defaultIconSaved) +void TaskManifestFile::generateWidgetIcon(UiApplication & uiApp, const DPL::OptionalString& tag, + const DPL::String& language, int iconId, const WrtDB::WidgetDAOReadOnly::WidgetIconList & list, + bool & defaultIconSaved) { DPL::String locale; if (!!tag) @@ -738,7 +732,8 @@ void TaskManifestFile::generateWidgetIcon(UiApplication & uiApp, const DPL::Opti } if (!!src) { DPL::String iconText; - iconText += /*DPL::FromASCIIString(GlobalConfig::GetUserWidgetDesktopIconPath()) + L"/" +*/ getIconTargetFilename(language); + iconText += getIconTargetFilename(language); + if(!locale.empty()) { uiApp.addIcon(IconType(iconText,locale)); @@ -772,10 +767,11 @@ void TaskManifestFile::setWidgetManifest(Manifest & manifest) void TaskManifestFile::setWidgetOtherInfo(UiApplication & uiApp) { uiApp.setNodisplay(false); - //TODO(t.iwanek): - //There is no "X-TIZEN-PackageType=wgt", there is not field in manifest + //TODO + //There is no "X-TIZEN-PackageType=wgt" //There is no X-TIZEN-PackageID in manifest "X-TIZEN-PackageID=" << DPL::ToUTF8String(*widgetID).c_str() //There is no Comment in pkgmgr "Comment=Widget application" + //that were in desktop file } void TaskManifestFile::setAppServiceInfo(UiApplication & uiApp) diff --git a/src/jobs/widget_install/task_manifest_file.h b/src/jobs/widget_install/task_manifest_file.h index d06b3d2..57c44f4 100644 --- a/src/jobs/widget_install/task_manifest_file.h +++ b/src/jobs/widget_install/task_manifest_file.h @@ -101,11 +101,11 @@ class TaskManifestFile : //for widget update void backupIconFiles(); void getFileList(const char* path, std::list<std::string> &list); + DPL::String getIconTargetFilename(const DPL::String& languageTag) const; static void saveLocalizedKey(std::ofstream &file, const DPL::String& key, const DPL::String& languageTag); - DPL::String getIconTargetFilename(const DPL::String& languageTag) const; static const char * encoding; diff --git a/src/jobs/widget_install/task_prepare_files.cpp b/src/jobs/widget_install/task_prepare_files.cpp index 50c1a58..9395094 100644 --- a/src/jobs/widget_install/task_prepare_files.cpp +++ b/src/jobs/widget_install/task_prepare_files.cpp @@ -41,19 +41,7 @@ TaskPrepareFiles::TaskPrepareFiles(InstallerContext &installerContext) : m_installerContext(installerContext) { // Install steps - AddStep(&TaskPrepareFiles::StepCreateTempPath); AddStep(&TaskPrepareFiles::StepCopyFiles); - - AddAbortStep(&TaskPrepareFiles::StepAbort); -} - -void TaskPrepareFiles::StepCreateTempPath() -{ - /* - * Config.xml and all icons will be copied to another location so the path - * has to be updated. - */ - m_installerContext.tempWidgetPath = createTempPath(); } void TaskPrepareFiles::CopyFile(const std::string& source) @@ -68,7 +56,7 @@ void TaskPrepareFiles::CopyFile(const std::string& source) if(last != std::string::npos) { filename = source.substr( last+1 ); } - std::string target = m_installerContext.tempWidgetPath + '/' + filename; + std::string target = m_installerContext.locations->getTemporaryPackageDir() + '/' + filename; LogDebug("source " << source); LogDebug("target " << target); @@ -100,25 +88,22 @@ void TaskPrepareFiles::CopyFile(const std::string& source) void TaskPrepareFiles::StepCopyFiles() { - CopyFile(m_installerContext.widgetSource); + CopyFile(m_installerContext.locations->getWidgetSource()); - size_t last = m_installerContext.widgetSource.find_last_of("\\/"); + size_t last = m_installerContext.locations->getWidgetSource().find_last_of("\\/"); std::string sourceDir = ""; if (last != std::string::npos) { - sourceDir = m_installerContext.widgetSource.substr(0,last+1); + sourceDir = m_installerContext.locations->getWidgetSource().substr(0,last+1); } + LogDebug("Icons copy..."); FOREACH(it, m_installerContext.widgetConfig.configInfo.iconsList) { std::ostringstream os; + LogDebug("Coping: " << sourceDir << DPL::ToUTF8String(it->src)); os << sourceDir << DPL::ToUTF8String(it->src); CopyFile(os.str()); } } -void TaskPrepareFiles::StepAbort() -{ - removeTemporaryDir(m_installerContext.tempWidgetPath); -} - } // namespace WidgetInstall } // namespace Jobs diff --git a/src/jobs/widget_install/task_prepare_files.h b/src/jobs/widget_install/task_prepare_files.h index 27ad5d6..7db10cf 100644 --- a/src/jobs/widget_install/task_prepare_files.h +++ b/src/jobs/widget_install/task_prepare_files.h @@ -39,9 +39,7 @@ private: void CopyFile(const std::string& source); // Steps - void StepCreateTempPath(); void StepCopyFiles(); - void StepAbort(); public: explicit TaskPrepareFiles(InstallerContext &installerContext); diff --git a/src/jobs/widget_install/task_private_storage.cpp b/src/jobs/widget_install/task_private_storage.cpp index b88211c..7b5cb85 100644 --- a/src/jobs/widget_install/task_private_storage.cpp +++ b/src/jobs/widget_install/task_private_storage.cpp @@ -66,8 +66,7 @@ void TaskPrivateStorage::StepCreateDirectory() std::ostringstream widgetPath; DPL::OptionalString pkgname = m_context.widgetConfig.pkgname; if(!pkgname.IsNull()) { - widgetPath << GlobalConfig::GetUserInstalledWidgetPath() << "/"; - widgetPath << pkgname << "/"; + widgetPath << m_context.locations->getPackageInstallationDir() << "/"; } else { ThrowMsg(Exceptions::InternalError, "No Package name exists."); } diff --git a/src/jobs/widget_install/task_recovery.cpp b/src/jobs/widget_install/task_recovery.cpp index d6eba3d..6ff2218 100644 --- a/src/jobs/widget_install/task_recovery.cpp +++ b/src/jobs/widget_install/task_recovery.cpp @@ -55,16 +55,15 @@ void TaskRecovery::StepCreateCheckFile() { LogInfo("Step: create information file for recovery"); - std::string fileName; - size_t pos = m_context.widgetSource.rfind("/"); + size_t pos = m_context.locations->getWidgetSource().rfind("/"); std::ostringstream infoPath; infoPath << GlobalConfig::GetTempInstallInfoPath(); infoPath << "/"; - infoPath << m_context.widgetSource.substr(pos+1); + infoPath << m_context.locations->getWidgetSource().substr(pos+1); FILE *temp = fopen(infoPath.str().c_str(), "w+"); if (temp != NULL) { - fputs(m_context.widgetSource.c_str(), temp); + fputs(m_context.locations->getWidgetSource().c_str(), temp); fsync(temp->_fileno); fclose(temp); diff --git a/src/jobs/widget_install/task_remove_backup.cpp b/src/jobs/widget_install/task_remove_backup.cpp index d94c4cc..77e0f4d 100644 --- a/src/jobs/widget_install/task_remove_backup.cpp +++ b/src/jobs/widget_install/task_remove_backup.cpp @@ -73,8 +73,7 @@ void TaskRemoveBackupFiles::StepDeleteDB() void TaskRemoveBackupFiles::StepRemoveBackupFiles() { std::ostringstream backupDir; - backupDir << GlobalConfig::GetUserInstalledWidgetPath(); - backupDir << "/" << m_context.widgetConfig.pkgname << "/" << "backup"; + backupDir << m_context.locations->getBackupDir(); if (_WrtUtilRemoveDir(backupDir.str().c_str())) { LogDebug("Success to remove backup files : " << backupDir.str()); @@ -84,12 +83,11 @@ void TaskRemoveBackupFiles::StepRemoveBackupFiles() "Error occurs during removing existing folder"); } - if (_WrtUtilRemoveDir(m_context.tempWidgetPath.c_str())) { - LogDebug("Success to remove temp directory : " << - m_context.tempWidgetPath); + std::string tmp = m_context.locations->getTemporaryPackageDir(); + if (_WrtUtilRemoveDir(tmp.c_str())) { + LogDebug("Success to remove temp directory : " << tmp); } else { - LogDebug("Failed to remove temp directory : " << - m_context.tempWidgetPath); + LogDebug("Failed to remove temp directory : " << tmp); ThrowMsg(Exceptions::RemoveBackupFailed, "Error occurs during removing existing folder"); } diff --git a/src/jobs/widget_install/task_unzip.cpp b/src/jobs/widget_install/task_unzip.cpp index dd9bdc8..c5f63d3 100644 --- a/src/jobs/widget_install/task_unzip.cpp +++ b/src/jobs/widget_install/task_unzip.cpp @@ -70,12 +70,9 @@ TaskUnzip::TaskUnzip(InstallerContext &installerContext) : m_installerContext(installerContext) { // Install steps - AddStep(&TaskUnzip::StepCreateTempPath); AddStep(&TaskUnzip::StepUnzipPrepare); AddStep(&TaskUnzip::StepUnzipProgress); AddStep(&TaskUnzip::StepUnzipFinished); - - AddAbortStep(&TaskUnzip::StepAbort); } void TaskUnzip::ExtractFile(DPL::ZipInput::File *input, @@ -98,45 +95,18 @@ void TaskUnzip::ExtractFile(DPL::ZipInput::File *input, } } -void TaskUnzip::StepCreateTempPath() -{ - // Step succedded, save temporary widget path - m_installerContext.tempWidgetPath = createTempPath(); - std::ostringstream path; - - if (m_installerContext.widgetConfig.pType == PKG_TYPE_TIZEN_WITHSVCAPP) { - std::ostringstream tempRoot; - tempRoot << m_installerContext.tempWidgetPath; - tempRoot << "/" << GlobalConfig::GetWidgetSrcPath(); - m_installerContext.tempWidgetRoot = tempRoot.str(); - - path << GlobalConfig::GetUserInstalledWidgetPath() << "/"; - path << m_installerContext.widgetConfig.pkgname; - } else { - m_installerContext.tempWidgetRoot = m_installerContext.tempWidgetPath; - path << GlobalConfig::GetUserInstalledWidgetPath() << "/"; - path << m_installerContext.widgetConfig.pkgname << "/"; - path << GlobalConfig::GetWidgetSrcPath(); - } - m_installerContext.installPath = path.str(); - - m_installerContext.job->UpdateProgress( - InstallerContext::INSTALL_CREATE_TEMPDIR, - "Create temporary directory for unzip"); -} - void TaskUnzip::StepUnzipPrepare() { LogInfo("Prepare to unzip..."); Try { - m_zip.Reset(new DPL::ZipInput(m_installerContext.widgetSource)); + m_zip.Reset(new DPL::ZipInput(m_installerContext.locations->getWidgetSource())); LogInfo("Widget package comment: " << m_zip->GetGlobalComment()); // Widget package must not be empty if (m_zip->empty()) { - ThrowMsg(Exceptions::ZipEmpty, m_installerContext.widgetSource); + ThrowMsg(Exceptions::ZipEmpty, m_installerContext.locations->getWidgetSource()); } // Set iterator to first file @@ -144,7 +114,7 @@ void TaskUnzip::StepUnzipPrepare() } Catch(DPL::ZipInput::Exception::OpenFailed) { - ReThrowMsg(Exceptions::OpenZipFailed, m_installerContext.widgetSource); + ReThrowMsg(Exceptions::OpenZipFailed, m_installerContext.locations->getWidgetSource()); } } @@ -164,7 +134,7 @@ void TaskUnzip::StepUnzipProgress() if (fileName[fileName.size() - 1] == '/') { // This is path - std::string newPath = m_installerContext.tempWidgetPath + "/" + + std::string newPath = m_installerContext.locations->getTemporaryPackageDir() + "/" + fileName.substr(0, fileName.size() - 1); LogPedantic("Path to extract: " << newPath); @@ -173,7 +143,7 @@ void TaskUnzip::StepUnzipProgress() } else { // This is regular file std::string fileExtractPath = - m_installerContext.tempWidgetPath + "/" + fileName; + m_installerContext.locations->getTemporaryPackageDir() + "/" + fileName; LogPedantic("File to extract: " << fileExtractPath); @@ -223,9 +193,5 @@ void TaskUnzip::StepUnzipFinished() LogInfo("Unzip finished"); } -void TaskUnzip::StepAbort() -{ - removeTemporaryDir(m_installerContext.tempWidgetPath); -} } //namespace WidgetInstall } //namespace Jobs diff --git a/src/jobs/widget_install/task_unzip.h b/src/jobs/widget_install/task_unzip.h index 9cb8339..13ec3c8 100644 --- a/src/jobs/widget_install/task_unzip.h +++ b/src/jobs/widget_install/task_unzip.h @@ -51,12 +51,9 @@ class TaskUnzip : void EncryptionFile(const std::string &fileName); // Steps - void StepCreateTempPath(); - void StepUnzipPrepare(); void StepUnzipProgress(); void StepUnzipFinished(); - void StepAbort(); public: TaskUnzip(InstallerContext &installerContext); diff --git a/src/jobs/widget_install/task_update_files.cpp b/src/jobs/widget_install/task_update_files.cpp index 446c043..9e29493 100644 --- a/src/jobs/widget_install/task_update_files.cpp +++ b/src/jobs/widget_install/task_update_files.cpp @@ -71,13 +71,7 @@ void TaskUpdateFiles::StepCreateBackupFolder() LogDebug("StepCreateBackupFolder"); std::ostringstream backDirPath; - backDirPath << GlobalConfig::GetUserInstalledWidgetPath() << "/"; - DPL::OptionalString pkgname = m_context.widgetConfig.pkgname; - - backDirPath << pkgname; - m_pkgPath = backDirPath.str(); - - backDirPath << "/" << GetWidgetBackupDirPath() << "/"; + backDirPath << m_context.locations->getBackupDir(); m_srcBuPath = backDirPath.str() + GlobalConfig::GetWidgetSrcPath(); LogDebug("backup resource directory path : " << m_srcBuPath); if(!_WrtMakeDir(m_srcBuPath.c_str(), 0755, WRT_FILEUTILS_RECUR)) { @@ -142,8 +136,8 @@ void TaskUpdateFiles::StepResourceFilesBackup() ReadDirList(pkgSrc, resList, strlen(pkgSrc.c_str())+1); - std::string tempSrc = m_context.tempWidgetPath; - ReadDirList(tempSrc, tempList, strlen(m_context.tempWidgetPath.c_str())+1); + std::string tempSrc = m_context.locations->getTemporaryPackageDir(); + ReadDirList(tempSrc, tempList, strlen(tempSrc.c_str())+1); FOREACH(it, tempList) { std::set<std::string>::iterator res; @@ -279,9 +273,7 @@ void TaskUpdateFiles::StepAbortCreateBackupFolder() { LogDebug("StepAbortCreateBackupFolder"); std::ostringstream path; - path << GlobalConfig::GetUserInstalledWidgetPath() << "/"; - path << m_context.widgetConfig.pkgname << "/"; - path << GetWidgetBackupDirPath(); + path << m_context.locations->getBackupDir(); LogDebug("Remove backup directory : " << path.str()); if(!_WrtUtilRemoveDir(path.str().c_str())) { diff --git a/src/jobs/widget_install/task_widget_config.cpp b/src/jobs/widget_install/task_widget_config.cpp index c86edaf..0e22985 100755 --- a/src/jobs/widget_install/task_widget_config.cpp +++ b/src/jobs/widget_install/task_widget_config.cpp @@ -19,25 +19,34 @@ * @version 1.0 * @brief Implementation file for installer task widget config */ -#include <string> + #include <sstream> -#include <dpl/foreach.h> +#include <string> +#include <sys/stat.h> +#include <dirent.h> + #include <dpl/errno_string.h> -#include <dpl/wrt-dao-rw/feature_dao.h> -#include <dpl/wrt-dao-ro/global_config.h> +#include <dpl/foreach.h> +#include <dpl/localization/w3c_file_localization.h> +#include <dpl/singleton_impl.h> +#include <dpl/utils/file_utils.h> +#include <dpl/utils/mime_type_utils.h> +#include <dpl/utils/wrt_global_settings.h> #include <dpl/utils/wrt_utility.h> -#include <root_parser.h> -#include <widget_parser.h> -#include <parser_runner.h> +#include <dpl/wrt-dao-ro/global_config.h> +#include <dpl/wrt-dao-rw/feature_dao.h> + #include <libiriwrapper.h> -#include <widget_install/task_widget_config.h> +#include <parser_runner.h> +#include <root_parser.h> + #include <widget_install/job_widget_install.h> -#include <widget_install/widget_install_errors.h> +#include <widget_install/task_widget_config.h> #include <widget_install/widget_install_context.h> -#include <dpl/utils/file_utils.h> -#include <dpl/utils/mime_type_utils.h> -#include <sys/stat.h> -#include <dpl/utils/wrt_global_settings.h> +#include <widget_install/widget_install_errors.h> +#include <widget_parser.h> +#include <wrt_error.h> + namespace { // anonymous const WidgetHandle WIDGET_HANDLE_START_VALUE = 1000; @@ -45,7 +54,13 @@ const DPL::String BR = DPL::FromUTF8String("<br>"); const std::string WIDGET_NOT_COMPATIBLE = "This widget is " "not compatible with WRT.<br><br>"; const std::string QUESTION = "Do you want to install it anyway?"; -} // namespace anonymous + +const char *const DEFAULT_LANGUAGE = "default"; +const size_t MAX_WIDGET_PATH_SIZE = 1024; + +const char *const WRT_WIDGET_CONFIG_FILE_NAME = "config.xml"; +} + namespace Jobs { namespace WidgetInstall { @@ -80,19 +95,12 @@ void TaskWidgetConfig::StepProcessConfigurationFile() { Try { - std::string path; - LogInfo("path: " << m_installContext.tempWidgetRoot); - if (m_installContext.browserRequest) { - path = m_installContext.widgetSource; - } else { - path = m_installContext.tempWidgetRoot; - } + std::string path = m_installContext.locations->getConfigurationDir(); + LogInfo("path: " << path); - WidgetConfigurationManagerSingleton::Instance().processFile( - path, - m_installContext.widgetConfig); + processFile(path, m_installContext.widgetConfig); } - Catch(WidgetConfigurationManager::Exception::ProcessFailed) + Catch(Exception::ConfigParseFailed) { LogError("Parsing failed."); ReThrow(Exceptions::WidgetConfigFileInvalid); @@ -102,7 +110,7 @@ void TaskWidgetConfig::StepProcessConfigurationFile() // To get widget type for distribute WAC, TIZEN WebApp setApplicationType(); } - Catch(WidgetConfigurationManager::Exception::ProcessFailed) + Catch(Exception::ConfigParseFailed) { LogError("Config.xml has more than one namespace"); ReThrow(Exceptions::WidgetConfigFileInvalid); @@ -119,7 +127,7 @@ void TaskWidgetConfig::ReadLocaleFolders() //Adding default locale m_localeFolders.insert(L""); - std::string localePath = m_installContext.tempWidgetRoot + "/locales"; + std::string localePath = m_installContext.locations->getConfigurationDir() + "/locales"; DIR* localeDir = opendir(localePath.c_str()); if (!localeDir) { LogDebug("No /locales directory in the widget package."); @@ -203,7 +211,7 @@ void TaskWidgetConfig::ProcessStartFile(const DPL::OptionalString& path, DPL::String relativePath = pathPrefix + *path; DPL::String absolutePath = DPL::FromUTF8String( - m_installContext.tempWidgetRoot) + L"/" + relativePath; + m_installContext.locations->getConfigurationDir()) + L"/" + relativePath; // get property data from packaged app if (FileUtils::FileExists(absolutePath)) { @@ -314,18 +322,8 @@ void TaskWidgetConfig::ProcessIcon(const WrtDB::ConfigParserData::Icon& icon) } DPL::String relativePath = pathPrefix + icon.src; - DPL::String absolutePath; - - if (m_installContext.browserRequest) { - // in case of browser installation - size_t pos = m_installContext.widgetSource.rfind("/"); - absolutePath = DPL::FromUTF8String( - m_installContext.widgetSource.substr(0, pos)); - } else { - absolutePath = DPL::FromUTF8String( - m_installContext.tempWidgetRoot); - } - absolutePath += L"/" + relativePath; + DPL::String absolutePath = DPL::FromUTF8String( + m_installContext.locations->getConfigurationDir()) + L"/" + relativePath; if (FileUtils::FileExists(absolutePath)) { DPL::String type = MimeTypeUtils::identifyFileMimeType(absolutePath); @@ -633,5 +631,201 @@ bool TaskWidgetConfig::isTizenWebApp() const return ret; } +bool TaskWidgetConfig::parseConfigurationFileBrowser(WrtDB::ConfigParserData& configInfo, + const std::string& _currentPath, int* pErrCode) +{ + ParserRunner parser; + Try + { + parser.Parse(_currentPath, ElementParserPtr(new + RootParser< + WidgetParser>( + configInfo, + DPL::FromUTF32String( + L"widget")))); + } + Catch(ElementParser::Exception::Base) + { + LogDebug("Invalid widget configuration file!"); + *pErrCode = WRT_WM_ERR_INVALID_ARCHIVE; + return false; + } + return true; +} + +bool TaskWidgetConfig::parseConfigurationFileWidget(WrtDB::ConfigParserData& configInfo, + const std::string& _currentPath, int* pErrCode) +{ + ParserRunner parser; + + //TODO: rewrite this madness + char cfgAbsPath[MAX_WIDGET_PATH_SIZE + 1] = { 0 }; + DIR* dir = NULL; + struct dirent* ptr = NULL; + + dir = opendir(_currentPath.c_str()); + if (dir == NULL) { + *pErrCode = WRT_ERR_UNKNOWN; + return false; + } + bool has_config_xml = false; + errno = 0; + while ((ptr = readdir(dir)) != NULL) { //Find configuration file, based on its name + if (ptr->d_type == DT_REG) { + if (!strcmp(ptr->d_name, WRT_WIDGET_CONFIG_FILE_NAME)) { + _WrtUtilSetAbsolutePath(cfgAbsPath, + _currentPath.c_str(), ptr->d_name); + //Parse widget configuration file + LogDebug("Found config: " << cfgAbsPath); + + Try + { + parser.Parse(cfgAbsPath, ElementParserPtr(new + RootParser< + WidgetParser>( + configInfo, + DPL + :: + FromUTF32String( + L"widget")))); + } + Catch(ElementParser::Exception::Base) + { + LogDebug("Invalid widget configuration file!"); + // _rethrown_exception.Dump(); + *pErrCode = WRT_WM_ERR_INVALID_ARCHIVE; + closedir(dir); + return false; + } + + has_config_xml = true; + break; + } + } + } + closedir(dir); + + //We must have config.xml so leaveing if we doesn't + if (!has_config_xml) { + LogDebug("Invalid archive"); + *pErrCode = WRT_WM_ERR_INVALID_ARCHIVE; + return false; + } + return true; +} + +bool TaskWidgetConfig::locateAndParseConfigurationFile( + const std::string& _currentPath, + WrtDB::WidgetRegisterInfo& pWidgetConfigInfo, + const std::string& baseFolder, + int* pErrCode) +{ + using namespace WrtDB; + + if (!pErrCode) { + return false; + } + + ConfigParserData& configInfo = pWidgetConfigInfo.configInfo; + + // check if this installation from browser, or not. + size_t pos = _currentPath.rfind("/"); + std::ostringstream infoPath; + infoPath << _currentPath.substr(pos+1); + + std::string language = ""; + + if (infoPath.str() != WRT_WIDGET_CONFIG_FILE_NAME) { + if (_currentPath.empty() || baseFolder.empty()) { + *pErrCode = WRT_ERR_INVALID_ARG; + return false; + } + // in case of general installation using wgt archive + if(!parseConfigurationFileWidget(configInfo, _currentPath, pErrCode)) + { + return false; + } + } else { + // in case of browser installation + if(!parseConfigurationFileBrowser(configInfo, _currentPath, pErrCode)) + { + return false; + } + } + + char *tmp_language; + if (!_WrtUtilStringToLower(baseFolder.c_str(), &tmp_language)) { + *pErrCode = WRT_ERR_UNKNOWN; + return false; + } + + if (!tmp_language) { + *pErrCode = WRT_ERR_UNKNOWN; + return false; + } + language = tmp_language; + free(tmp_language); + + if(!fillWidgetConfig(pWidgetConfigInfo, configInfo)) + { + *pErrCode = WRT_WM_ERR_INVALID_ARCHIVE; + return false; + } + return true; +} + +bool TaskWidgetConfig::fillWidgetConfig(WrtDB::WidgetRegisterInfo& pWidgetConfigInfo, + WrtDB::ConfigParserData& configInfo) +{ + if (!!configInfo.widget_id) { + if (!pWidgetConfigInfo.guid) { + pWidgetConfigInfo.guid = configInfo.widget_id; + } else { + if (pWidgetConfigInfo.guid != configInfo.widget_id) { + LogDebug("Invalid archive"); + return false; + } + } + } + if (!!configInfo.tizenId) { + if (!pWidgetConfigInfo.pkgname) { + pWidgetConfigInfo.pkgname = configInfo.tizenId; + } else { + if (pWidgetConfigInfo.pkgname != configInfo.tizenId) { + LogDebug("Invalid archive - Tizen ID not same error"); + return false; + } + } + } + if (!!configInfo.version) { + if (!pWidgetConfigInfo.version) { + pWidgetConfigInfo.version = configInfo.version; + } else { + if (pWidgetConfigInfo.version != configInfo.version) { + LogDebug("Invalid archive"); + return false; + } + } + } + if (!!configInfo.minVersionRequired) { + pWidgetConfigInfo.minVersion = configInfo.minVersionRequired; + } else if (!!configInfo.tizenMinVersionRequired) { + pWidgetConfigInfo.minVersion = configInfo.tizenMinVersionRequired; + } + return true; +} + +void TaskWidgetConfig::processFile(const std::string& path, + WrtDB::WidgetRegisterInfo &widgetConfiguration) +{ + int pErrCode; + + if (!locateAndParseConfigurationFile(path, widgetConfiguration, + DEFAULT_LANGUAGE, &pErrCode)) { + LogWarning("Widget archive: Failed while parsing config file"); + ThrowMsg(Exception::ConfigParseFailed, path); + } +} + } //namespace WidgetInstall } //namespace Jobs diff --git a/src/jobs/widget_install/task_widget_config.h b/src/jobs/widget_install/task_widget_config.h index 12525a6..632128e 100755 --- a/src/jobs/widget_install/task_widget_config.h +++ b/src/jobs/widget_install/task_widget_config.h @@ -14,7 +14,7 @@ * limitations under the License. */ /* - * @file task_widget_config.cpp + * @file task_widget_config.h * @author Przemyslaw Dobrowolski (p.dobrowolsk@samsung.com) * @version 1.0 * @brief Implementation file for installer task widget config @@ -22,13 +22,18 @@ #ifndef INSTALLER_CORE_JOS_WIDGET_INSTALL_TASK_WIDGET_CONFIG_H #define INSTALLER_CORE_JOS_WIDGET_INSTALL_TASK_WIDGET_CONFIG_H -#include <WidgetConfigurationManager.h> +#include <set> +#include <list> + #include <dpl/task.h> #include <dpl/task_list.h> #include <dpl/string.h> -#include <wrt_error.h> +#include <dpl/optional.h> +#include <dpl/wrt-dao-ro/config_parser_data.h> +#include <dpl/wrt-dao-ro/widget_dao_read_only.h> #include <dpl/wrt-dao-ro/global_config.h> -#include <set> + +#include <wrt_error.h> #include <wrt_common_types.h> #include <widget_install/widget_install_popup.h> @@ -49,6 +54,15 @@ class TaskWidgetConfig : public WidgetInstallPopup { private: + class Exception + { + public: + DECLARE_EXCEPTION_TYPE(DPL::Exception, Base) + DECLARE_EXCEPTION_TYPE(Base, ConfigParseFailed) + }; + + typedef std::list<std::pair<DPL::String, DPL::String> > StringPairList; + InstallerContext& m_installContext; WrtDB::LocaleSet m_localeFolders; std::set<DPL::String> m_processedIconSet; @@ -89,7 +103,26 @@ class TaskWidgetConfig : bool isTizenWebApp() const; bool parseVersionString(const std::string &version, long &majorVersion, long &minorVersion, long µVersion) const; + /** + * This method is used to process the config.xml of widget, get + * the corresponding configuration to pWidgetConfigInfo + * + * @param[in] path Specified the widget archive file path (absolute path). + * @return Configuration information of widget + */ + void processFile(const std::string& path, + WrtDB::WidgetRegisterInfo &wConfig); + bool locateAndParseConfigurationFile(const std::string& currentPath, + WrtDB::WidgetRegisterInfo& pWidgetConfigInfo, + const std::string& baseFolder, + int* pErrCode); + bool parseConfigurationFileBrowser(WrtDB::ConfigParserData& configInfo, + const std::string& _currentPath, int* pErrCode); + bool parseConfigurationFileWidget(WrtDB::ConfigParserData& configInfo, + const std::string& _currentPath, int* pErrCode); + bool fillWidgetConfig(WrtDB::WidgetRegisterInfo& pWidgetConfigInfo, + WrtDB::ConfigParserData& configInfo); public: TaskWidgetConfig(InstallerContext& installTaskContext); }; diff --git a/src/jobs/widget_install/widget_install_context.h b/src/jobs/widget_install/widget_install_context.h index 3716488..607505a 100755 --- a/src/jobs/widget_install/widget_install_context.h +++ b/src/jobs/widget_install/widget_install_context.h @@ -29,6 +29,7 @@ #include <widget_install/wac_security.h> #include <feature_logic.h> #include <widget_install/widget_update_info.h> +#include <widget_location.h> namespace Jobs { namespace WidgetInstall { @@ -85,12 +86,9 @@ struct InstallerContext } InstallStep; // Installation state variables - std::string widgetSource; ///< Source widget zip file/widget url - std::string tempWidgetPath; ///< Unpacked widget temporary path - bool browserRequest; ///< Browser Request - std::string installedIconPath; ///< Installed icon path WrtDB::WidgetRegisterInfo widgetConfig; ///< WidgetConfigInfo DPL::Optional<WrtDB::DbWidgetHandle> widgetHandle; + DPL::Optional<WidgetLocation> locations; Jobs::WidgetInstall::WacSecurity wacSecurity;///< Widget Domain information. InstallStep installStep; ///< current step of installation Jobs::WidgetInstall::JobWidgetInstall *job; @@ -107,9 +105,6 @@ struct InstallerContext RequestedDevCapsMap staticPermittedDevCaps; std::string installInfo; ///<For recovery> bool m_quiet; - - std::string tempWidgetRoot; ///< temporary widget root path - std::string installPath; ///< widget install path }; #endif // INSTALLER_CONTEXT_H diff --git a/src/jobs/widget_uninstall/job_widget_uninstall.cpp b/src/jobs/widget_uninstall/job_widget_uninstall.cpp index fb55919..9c6a0de 100644 --- a/src/jobs/widget_uninstall/job_widget_uninstall.cpp +++ b/src/jobs/widget_uninstall/job_widget_uninstall.cpp @@ -13,6 +13,9 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + +#include <dpl/utils/file_utils.h> + #include <widget_uninstall/job_widget_uninstall.h> #include <widget_uninstall/widget_uninstall_errors.h> #include <widget_uninstall/task_check.h> @@ -65,9 +68,12 @@ JobWidgetUninstall::JobWidgetUninstall(WidgetHandle widgetHandle, m_context.uninstallStep = UninstallerContext::UNINSTALL_START; m_context.job = this; - Try { + Try + { WrtDB::WidgetDAOReadOnly dao(widgetHandle); m_context.pkgname = DPL::ToUTF8String(*dao.getPkgname()); + m_context.locations = WidgetLocation(m_context.pkgname); + LogInfo("Widget model exists. Pkg name: " << m_context.pkgname); AddTask(new TaskSmack(m_context)); @@ -85,7 +91,9 @@ JobWidgetUninstall::JobWidgetUninstall(WidgetHandle widgetHandle, PKGMGR_START_KEY, PKGMGR_START_UNINSTALL); } - + } Catch(FileUtils::CreateDirectoryException) { + LogError("Failed to create temporary path for widget"); + AddTask(new UninstallerTaskFail(false)); } Catch (WidgetDAOReadOnly::Exception::WidgetNotExist) { AddTask(new UninstallerTaskFail(true)); } Catch (WidgetDAOReadOnly::Exception::Base) { diff --git a/src/jobs/widget_uninstall/task_remove_files.cpp b/src/jobs/widget_uninstall/task_remove_files.cpp index 8463b34..b747b7e 100644 --- a/src/jobs/widget_uninstall/task_remove_files.cpp +++ b/src/jobs/widget_uninstall/task_remove_files.cpp @@ -22,6 +22,7 @@ #include <widget_uninstall/task_remove_files.h> #include <widget_uninstall/job_widget_uninstall.h> +#include <widget_uninstall/uninstaller_context.h> #include <dpl/wrt-dao-ro/widget_dao_read_only.h> #include <dpl/wrt-dao-ro/widget_config.h> @@ -140,8 +141,7 @@ void TaskRemoveFiles::StepPrepare() std::ostringstream widgetDir; - widgetDir << GlobalConfig::GetUserInstalledWidgetPath() << "/"; - widgetDir << m_context.pkgname << "/"; + widgetDir << m_context.locations->getPackageInstallationDir() << "/"; uninstRootDir = widgetDir.str(); ReadDir(uninstRootDir, filesList); diff --git a/src/jobs/widget_uninstall/task_remove_files.h b/src/jobs/widget_uninstall/task_remove_files.h index 902fac9..496bee9 100644 --- a/src/jobs/widget_uninstall/task_remove_files.h +++ b/src/jobs/widget_uninstall/task_remove_files.h @@ -23,9 +23,11 @@ #ifndef WRT_SRC_INSTALLER_CORE_JOB_WIDGET_UNINSTALL_TASK_REMOVE_FILES_H_ #define WRT_SRC_INSTALLER_CORE_JOB_WIDGET_UNINSTALL_TASK_REMOVE_FILES_H_ -#include <dpl/task.h> +//forward declaration +struct UninstallerContext; -#include <widget_uninstall/uninstaller_context.h> //TODO forward decl +#include <dpl/task.h> +#include <dpl/log/log.h> #include <string> diff --git a/src/jobs/widget_uninstall/uninstaller_context.h b/src/jobs/widget_uninstall/uninstaller_context.h index 2b65907..d6e9d52 100644 --- a/src/jobs/widget_uninstall/uninstaller_context.h +++ b/src/jobs/widget_uninstall/uninstaller_context.h @@ -25,6 +25,7 @@ #include <string> #include <widget_uninstall/widget_uninstaller_struct.h> +#include <widget_location.h> namespace Jobs { namespace WidgetUninstall { @@ -57,6 +58,9 @@ struct UninstallerContext ///< flag that indicates whether installer finishes //to remove files completely. bool removeFinished; + + DPL::Optional<WidgetLocation> locations; + UninstallStep uninstallStep; ///< current step of installation Jobs::WidgetUninstall::JobWidgetUninstall *job; std::string pkgname; diff --git a/src/logic/installer_controller.cpp b/src/logic/installer_controller.cpp index 1141b76..754a886 100644 --- a/src/logic/installer_controller.cpp +++ b/src/logic/installer_controller.cpp @@ -16,7 +16,11 @@ #include "installer_controller.h" #include <dpl/log/log.h> #include <dpl/singleton_impl.h> -IMPLEMENT_SINGLETON(InstallerController) + +IMPLEMENT_SINGLETON(Logic::InstallerController) + +namespace Logic +{ InstallerController::InstallerController() { @@ -98,3 +102,6 @@ void InstallerController::OnEventReceived( { m_installerLogic.Terminate(); } + +} //Logic + diff --git a/src/logic/installer_controller.h b/src/logic/installer_controller.h index 3693f9a..e611d0c 100644 --- a/src/logic/installer_controller.h +++ b/src/logic/installer_controller.h @@ -70,6 +70,9 @@ DECLARE_GENERIC_EVENT_0(TerminateEvent) } // namespace InstallerEvents + +namespace Logic { + /** * @brief Controls Widget installation * @@ -130,7 +133,7 @@ class InstallerController : public DPL::Event::Controller<InstallerControllerEve private: // Embedded logic - InstallerLogic m_installerLogic; + Logic::InstallerLogic m_installerLogic; InstallerController(); @@ -141,4 +144,6 @@ class InstallerController : public DPL::Event::Controller<InstallerControllerEve typedef DPL::Singleton<InstallerController> InstallerControllerSingleton; +} + #endif // INSTALLER_CONTROLLER_H diff --git a/src/logic/installer_logic.cpp b/src/logic/installer_logic.cpp index f798eb2..607ec92 100644 --- a/src/logic/installer_logic.cpp +++ b/src/logic/installer_logic.cpp @@ -27,6 +27,8 @@ using namespace WrtDB; +namespace Logic { + InstallerLogic::InstallerLogic() : m_NextHandle(0) { @@ -255,3 +257,5 @@ bool InstallerLogic::resolvePluginDependencies(PluginHandle handle) return true; } +} + diff --git a/src/logic/installer_logic.h b/src/logic/installer_logic.h index 0314036..5490841 100644 --- a/src/logic/installer_logic.h +++ b/src/logic/installer_logic.h @@ -24,7 +24,7 @@ #include <plugin_install/plugin_installer_struct.h> #include <job.h> -//TODO create namespace +namespace Logic { class InstallerLogic { @@ -74,4 +74,6 @@ class InstallerLogic friend class InstallerController; }; +} + #endif // INSTALLER_LOGIC_H diff --git a/src/misc/libxml_utils.cpp b/src/misc/libxml_utils.cpp index a252699..61aa5cc 100644 --- a/src/misc/libxml_utils.cpp +++ b/src/misc/libxml_utils.cpp @@ -48,7 +48,7 @@ void LibxmlUtils::init() isInitialized = true; LogDebug("Libxml have been initialized"); } - LogDebug("Libxml already inited"); + LogDebug("Libxml already initialized"); } diff --git a/src/misc/widget_location.cpp b/src/misc/widget_location.cpp new file mode 100644 index 0000000..3427433 --- /dev/null +++ b/src/misc/widget_location.cpp @@ -0,0 +1,153 @@ +/* + * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +/* + * @file widget_location.cpp + * @author Iwanek Tomasz (t.iwanek@smasung.com) + */ +#include "widget_location.h" + +#include <dpl/utils/wrt_utility.h> +#include <dpl/wrt-dao-ro/global_config.h> +#include <dpl/assert.h> +#include <dpl/log/log.h> +#include <dpl/sstream.h> +#include <dpl/localization/localization_utils.h> + +#include <widget_install/task_commons.h> + + +WidgetLocation::DirectoryDeletor::DirectoryDeletor() +{ + m_dirpath = Jobs::WidgetInstall::createTempPath(); +} + +WidgetLocation::DirectoryDeletor::~DirectoryDeletor() +{ + LogDebug("Removing widget installation temporary directory: " << m_dirpath.c_str()); + _WrtUtilRemoveDir(m_dirpath.c_str()); +} + +std::string WidgetLocation::DirectoryDeletor::getTempPath() const +{ + return m_dirpath; +} + +WidgetLocation::WidgetLocation() : m_browser(false) +{ +} + +WidgetLocation::WidgetLocation(const std::string & widgetname) : m_pkgname(widgetname), m_browser(false) +{ +} + +WidgetLocation::~WidgetLocation() +{ +} + +WidgetLocation::WidgetLocation(const std::string & widgetname, + std::string sourcePath, + bool browserRequest, + WrtDB::PkgType t): + m_pkgname(widgetname), + m_widgetSource(sourcePath), + m_browser(browserRequest), + m_type(t), + m_temp(new WidgetLocation::DirectoryDeletor()) +{ +} + +std::string WidgetLocation::getInstallationDir() const +{ + return std::string(WrtDB::GlobalConfig::GetUserInstalledWidgetPath()); +} + +std::string WidgetLocation::getPackageInstallationDir() const +{ + return std::string(WrtDB::GlobalConfig::GetUserInstalledWidgetPath()) + "/" + + m_pkgname; +} + +std::string WidgetLocation::getSourceDir() const +{ + return std::string(WrtDB::GlobalConfig::GetUserInstalledWidgetPath()) + "/" + + m_pkgname + "/" + WrtDB::GlobalConfig::GetWidgetSrcPath(); +} + +std::string WidgetLocation::getBinaryDir() const +{ + return std::string(WrtDB::GlobalConfig::GetUserInstalledWidgetPath()) + "/" + + m_pkgname + "/" + WrtDB::GlobalConfig::GetUserWidgetExecPath(); +} + +std::string WidgetLocation::getBackupDir() const +{ + return getPackageInstallationDir() + "/backup"; +} + +std::string WidgetLocation::getTemporaryPackageDir() const +{ + return m_temp->getTempPath(); +} + +bool WidgetLocation::browserRequest() const +{ + return m_browser; +} + +std::string WidgetLocation::getTemporaryRootDir() const +{ + if(m_type == WrtDB::PKG_TYPE_TIZEN_WITHSVCAPP) + { + return getTemporaryPackageDir() + "/" + WrtDB::GlobalConfig::GetWidgetSrcPath(); + } + else + { + return getTemporaryPackageDir(); + } +} + +std::string WidgetLocation::getConfigurationDir() const +{ + if(m_browser) + { + std::string path = "."; + int index = m_widgetSource.find_last_of("\\/"); + if (index != std::string::npos) + { + path = m_widgetSource.substr(0, index); + } + return path; + } + else + { + return getTemporaryRootDir(); + } +} + +std::string WidgetLocation::getInstalledIconPath() const +{ + return m_iconPath; +} + +std::string WidgetLocation::getWidgetSource() const +{ + return m_widgetSource; +} + +void WidgetLocation::setIconTargetFilenameForLocale(const std::string & icon) +{ + m_iconPath = icon; +} diff --git a/src/misc/widget_location.h b/src/misc/widget_location.h new file mode 100644 index 0000000..2c3a636 --- /dev/null +++ b/src/misc/widget_location.h @@ -0,0 +1,163 @@ +/* + * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +/* + * @file widget_location.h + * @author Iwanek Tomasz (t.iwanek@smasung.com) + */ +#ifndef WRT_INSTALLER_SRC_MISC_WIDGET_LOCATION_H +#define WRT_INSTALLER_SRC_MISC_WIDGET_LOCATION_H + +#include <string> + +#include <dpl/shared_ptr.h> +#include <dpl/wrt-dao-ro/common_dao_types.h> + +/** + * @brief The WidgetLocation class + * + * Object that stores locations of several files/directories according + * to package name + * + * Current package layout (of installed package) is following: + * + * /opt/apps/[package_name] + * \_____________ /data + * \_____________ /bin + * \_____________ /bin/[id_of_installed_package] + * \_____________ /res/wgt/ + * \___ config.xml + * \___ [widgets_archive_content] + * + * 1) Normal Widget + * Developer provides content of res/wgt directory (package contains that directory as root). + * + * 2) For OSP Service Hybrid App is actually a bit different: + * Root is OSP Service directory, WebApp content is located in [root]/res/wgt + * + * Temporary directory is directory when widget is placed at the begining + * of installation process. After parsing process of config.xml, destination directory is created. + */ +class WidgetLocation +{ + class DirectoryDeletor + { + public: + DirectoryDeletor(); + ~DirectoryDeletor(); + std::string getTempPath() const; + private: + std::string m_dirpath; + }; + +public: + DECLARE_EXCEPTION_TYPE(DPL::Exception, Base) + DECLARE_EXCEPTION_TYPE(Base, NoTemporaryPath) + /** + * @brief WidgetLocation + * + * Creates useless object. Needed by DPL::Optional + */ + WidgetLocation(); + /** + * @brief WidgetLocation Builds paths for widget location during uninstallation + * + * Uninstallation process needs only installed package directory. + * + * @param widgetname name of widget + */ + WidgetLocation(const std::string & widgetname); + /** + * @brief WidgetLocation Builds paths for widget location during installation + * + * @param widgetname name of widget + * @param browserRequest is browser Request + * @param sourcePath given source path + * @param t declaraced type of widget if type is needed + * + * In destruction removes temporary directory + */ + WidgetLocation(const std::string & widgetname, std::string sourcePath, + bool browserRequest = false, WrtDB::PkgType t = WrtDB::PKG_TYPE_TIZEN_WEBAPP); + ~WidgetLocation(); + + // Installed paths + std::string getInstallationDir() const; // /opt/apps + std::string getPackageInstallationDir() const; // /opt/apps/[package] + std::string getSourceDir() const; // /opt/apps/[package]/res/wgt + std::string getBinaryDir() const; // /opt/apps/[package]/bin + std::string getBackupDir() const; // /opt/apps/[package]/backup + + bool browserRequest() const; + + // Temporary paths + /** + * @brief getTemporaryRootDir + * @return value of root for developer's provide package (root of unpacked .wgt file) + */ + std::string getTemporaryPackageDir() const; + /** + * @brief getTemporaryRootDir + * + * Value of this will differs according to type of installed widget. + * + * @return value of root for content in temporary directory to be copied into 'res/wgt' + */ + std::string getTemporaryRootDir() const; + /** + * @brief getConfigurationDir Returns rott directory for configuration requirements + * + * 1) For packed widgets it is just root of unpacked sources + * 2) For browser installation it is directory name of widget passed to installer + * + * @return configuration directory + */ + std::string getConfigurationDir() const; + + //icons + /** + * @brief setIconTargetFilenameForLocale set installed ion path according to locale + * @param icon path of application icon + */ + void setIconTargetFilenameForLocale(const std::string &icon); + /** + * @brief getIconTargetFilename gets icon path suffix for locale + * @param languageTag language tag + * @return value of suffix of path + */ + DPL::String getIconTargetFilename(const DPL::String& languageTag) const; + /** + * @brief getIconTargetFilename gets icon full path + * @param languageTag language tag + * @return value of full path + */ + std::string getInstalledIconPath() const; + + /** + * @brief getWidgetSourcePath return widget's source path given to installer + * @return value of source path + */ + std::string getWidgetSource() const; + +private: + std::string m_widgetSource; // Source widget zip file/widget url + bool m_browser; // is browser request installation + std::string m_pkgname; //name of package + std::string m_iconPath; //installed icon path + WrtDB::PkgType m_type; + DPL::SharedPtr<DirectoryDeletor> m_temp; //directory +}; + +#endif // WRT_INSTALLER_SRC_MISC_WIDGET_LOCATION_H diff --git a/src/wrt-installer/CMakeLists.txt b/src/wrt-installer/CMakeLists.txt index 4d49b74..a47d772 100644 --- a/src/wrt-installer/CMakeLists.txt +++ b/src/wrt-installer/CMakeLists.txt @@ -55,7 +55,6 @@ ADD_EXECUTABLE(${TARGET_INSTALLER} ${WRT_INSTALLER_SOURCES} ) -ADD_DEFINITIONS("-DSEPARATE_INSTALLER_FOR_DAO") # TODO do not use ifdefs! ADD_DEFINITIONS(${WRT_INSTALLER_DEPS_CFLAGS}) TARGET_LINK_LIBRARIES(${TARGET_INSTALLER} diff --git a/src/wrt-installer/installer_main_thread.cpp b/src/wrt-installer/installer_main_thread.cpp index f7799a2..911b3cb 100755 --- a/src/wrt-installer/installer_main_thread.cpp +++ b/src/wrt-installer/installer_main_thread.cpp @@ -67,11 +67,11 @@ void InstallerMainThread::DetachDatabases() void InstallerMainThread::TouchArchitecture() { // Touch controller - InstallerControllerSingleton::Instance().Touch(); + Logic::InstallerControllerSingleton::Instance().Touch(); } void InstallerMainThread::TouchArchitectureOnlyInstaller() { // Touch controller - InstallerControllerSingleton::Instance().Touch(); + Logic::InstallerControllerSingleton::Instance().Touch(); } diff --git a/src/wrt-installer/wrt_installer_api.cpp b/src/wrt-installer/wrt_installer_api.cpp index d3ed72e..43a6234 100755 --- a/src/wrt-installer/wrt_installer_api.cpp +++ b/src/wrt-installer/wrt_installer_api.cpp @@ -280,13 +280,13 @@ extern "C" // Installer init CONTROLLER_POST_SYNC_EVENT( - InstallerController, + Logic::InstallerController, InstallerControllerEvents:: InitializeEvent()); // Install deferred widget packages CONTROLLER_POST_EVENT( - InstallerController, + Logic::InstallerController, InstallerControllerEvents:: InstallDeferredWidgetPackagesEvent()); @@ -316,7 +316,7 @@ extern "C" // Installer termination CONTROLLER_POST_SYNC_EVENT( - InstallerController, + Logic::InstallerController, InstallerControllerEvents:: TerminateEvent()); @@ -349,7 +349,7 @@ extern "C" LogInfo("[WRT-API] INSTALL WIDGET: " << path); // Post installation event CONTROLLER_POST_EVENT( - InstallerController, + Logic::InstallerController, InstallerControllerEvents::InstallWidgetEvent( path, WidgetInstallationStruct( InstallerCallbacksTranslate::installFinishedCallback, @@ -372,7 +372,7 @@ extern "C" LogInfo("[WRT-API] UNINSTALL WIDGET: " << widget_handle); // Post uninstallation event CONTROLLER_POST_EVENT( - InstallerController, + Logic::InstallerController, InstallerControllerEvents::UninstallWidgetEvent( widget_handle, WidgetUninstallationStruct( @@ -401,7 +401,7 @@ extern "C" user_param, status_cb, progress_cb); CONTROLLER_POST_EVENT( - InstallerController, + Logic::InstallerController, InstallerControllerEvents::InstallPluginEvent( std::string(pluginDir), PluginInstallerStruct( @@ -550,7 +550,7 @@ extern "C" } CONTROLLER_POST_SYNC_EVENT( - InstallerController, + Logic::InstallerController, InstallerControllerEvents:: InitializeEvent()); @@ -581,7 +581,7 @@ extern "C" // Installer termination CONTROLLER_POST_SYNC_EVENT( - InstallerController, + Logic::InstallerController, InstallerControllerEvents:: TerminateEvent()); |