Direcotry install feature added to wrt-installer
authorAndrzej Surdej <a.surdej@samsung.com>
Thu, 22 Nov 2012 12:22:40 +0000 (13:22 +0100)
committerGerrit Code Review <gerrit2@kim11>
Tue, 27 Nov 2012 08:50:42 +0000 (17:50 +0900)
[Issue#] LINUXNGWAP-572
[Problem] SDK takes too long time to install/update widget
[Cause] Steps done: zipping->transfer->uninstall->install->unzipping->checking version
[Solution] Added feature to install widget directly from directory.
To do that run wrt-installer -i /path/widget_directory (note that -if works as before)
Widget is not zipped/unzipped and version check is not performed (always update)
[Verification] First of all check if old options works correctly, wrt-test-w3c
might be helpful.
Secondly check if new feature works by installing/updating/running/uninstalling
widget with -i /directory option

Change-Id: I4a07c66e74630df7c97b015c9dadbe3452da7509

src/jobs/widget_install/job_widget_install.cpp
src/jobs/widget_install/task_file_manipulation.cpp
src/jobs/widget_install/task_prepare_files.cpp
src/jobs/widget_install/widget_installer_struct.h
src/misc/widget_location.cpp
src/wrt-installer/wrt_installer.cpp
src/wrt-installer/wrt_installer_api.cpp
src/wrt-installer/wrt_installer_api.h

index 2dc371e..b5bc9bc 100644 (file)
@@ -153,13 +153,20 @@ JobWidgetInstall::JobWidgetInstall(std::string const &widgetPath,
 
         // Create installation tasks
         if (m_installerContext.widgetConfig.packagingType !=
-                WrtDB::PKG_TYPE_HOSTED_WEB_APP || !m_isDRM) {
+                WrtDB::PKG_TYPE_DIRECTORY_WEB_APP &&
+            m_installerContext.widgetConfig.packagingType !=
+                WrtDB::PKG_TYPE_HOSTED_WEB_APP &&
+            !m_isDRM)
+        {
             AddTask(new TaskUnzip(m_installerContext));
         }
 
         AddTask(new TaskWidgetConfig(m_installerContext));
-        if (m_installerContext.widgetConfig.packagingType ==
-                WrtDB::PKG_TYPE_HOSTED_WEB_APP ) {
+        if (m_installerContext.widgetConfig.packagingType  ==
+                WrtDB::PKG_TYPE_HOSTED_WEB_APP ||
+            m_installerContext.widgetConfig.packagingType ==
+                WrtDB::PKG_TYPE_DIRECTORY_WEB_APP)
+        {
             AddTask(new TaskPrepareFiles(m_installerContext));
         }
         AddTask(new TaskCertify(m_installerContext));
@@ -189,14 +196,21 @@ JobWidgetInstall::JobWidgetInstall(std::string const &widgetPath,
         LogInfo("Configure installation updated");
         LogInfo("Widget Update");
         if (m_installerContext.widgetConfig.packagingType !=
-                WrtDB::PKG_TYPE_HOSTED_WEB_APP || !m_isDRM) {
+                WrtDB::PKG_TYPE_HOSTED_WEB_APP &&
+            m_installerContext.widgetConfig.packagingType !=
+                WrtDB::PKG_TYPE_DIRECTORY_WEB_APP &&
+            !m_isDRM)
+        {
             AddTask(new TaskUnzip(m_installerContext));
         }
 
         AddTask(new TaskWidgetConfig(m_installerContext));
 
         if (m_installerContext.widgetConfig.packagingType ==
-                WrtDB::PKG_TYPE_HOSTED_WEB_APP ) {
+                WrtDB::PKG_TYPE_HOSTED_WEB_APP ||
+            m_installerContext.widgetConfig.packagingType ==
+                WrtDB::PKG_TYPE_DIRECTORY_WEB_APP)
+        {
             AddTask(new TaskPrepareFiles(m_installerContext));
         }
 
@@ -244,7 +258,7 @@ JobWidgetInstall::ConfigureResult JobWidgetInstall::PrePareInstallation(
     {
         std::string tempDir = Jobs::WidgetInstall::createTempPath();
 
-        bool m_isDRM = isDRMWidget(widgetPath);
+        m_isDRM = isDRMWidget(widgetPath);
         if (true == m_isDRM) {
             LogDebug("decrypt DRM widget");
             if(DecryptDRMWidget(widgetPath, tempDir)) {
@@ -409,7 +423,10 @@ JobWidgetInstall::ConfigureResult JobWidgetInstall::ConfigureInstallation(
         updateTypeCheckBit = CalcWidgetUpdatePolicy(existingVersion,
                                                     incomingVersion);
         // Calc proceed flag
-        if ((m_jobStruct.updateMode & updateTypeCheckBit) > 0) {
+        if ((m_jobStruct.updateMode & updateTypeCheckBit) > 0 ||
+            m_jobStruct.updateMode ==
+                WidgetUpdateMode::PolicyDirectoryForceInstall)
+        {
             LogInfo("Whether widget policy allow proceed ok");
             ret = ConfigureResult::Updated;
         }
@@ -495,6 +512,12 @@ ConfigParserData JobWidgetInstall::getWidgetDataFromXML(
                         new RootParser<WidgetParser>(configInfo,
                             DPL::FromUTF32String(
                                 L"widget"))));
+        } else if (pkgType == PKG_TYPE_DIRECTORY_WEB_APP) {
+            parser.Parse(widgetSource + '/' + CONFIG_XML,
+                         ElementParserPtr(
+                             new RootParser<WidgetParser>(
+                             configInfo,
+                             DPL::FromUTF32String(L"widget"))));
         } else {
             if (!isDRM) {
                 std::unique_ptr<DPL::ZipInput> zipFile(
@@ -749,7 +772,12 @@ WrtDB::PackagingType JobWidgetInstall::checkPackageType(
         const std::string &widgetSource,
         const std::string &tempPath)
 {
-    // Check installation type (config.xml or widget.wgt)
+    // Check installation type (direcotory/ or config.xml or widget.wgt)
+    if (WidgetUpdateMode::PolicyDirectoryForceInstall == m_jobStruct.updateMode)
+    {
+        LogDebug("Install directly from directory");
+        return PKG_TYPE_DIRECTORY_WEB_APP;
+    }
     if (hasExtension(widgetSource, XML_EXTENSION)) {
         LogInfo("Hosted app installation");
         return PKG_TYPE_HOSTED_WEB_APP;
@@ -845,7 +873,7 @@ bool JobWidgetInstall::isDRMWidget(std::string widgetPath)
 bool JobWidgetInstall::DecryptDRMWidget(std::string widgetPath,
         std::string destPath)
 {
-    /* TODO : 
+    /* TODO :
     drm_trusted_sapps_decrypt_package_info_s package_info;
 
     strncpy(package_info.sadcf_filepath, widgetPath.c_str(),
@@ -865,7 +893,7 @@ bool JobWidgetInstall::DecryptDRMWidget(std::string widgetPath,
     }
     */
     if (drm_oem_intel_decrypt_package(const_cast<char*>(widgetPath.c_str()),
-                const_cast<char*>(destPath.c_str())) != 0) { 
+                const_cast<char*>(destPath.c_str())) != 0) {
         return true;
     } else {
         return false;
index ae02d73..759510e 100644 (file)
@@ -98,7 +98,6 @@ void TaskFileManipulation::StepRenamePath()
         ThrowMsg(Exceptions::UnknownError,
                 "Error occurs during renaming widget folder");
     }
-
     m_context.job->UpdateProgress(
         InstallerContext::INSTALL_RENAME_PATH,
         "Widget Rename path Finished");
index 9395094..b1c2179 100644 (file)
@@ -88,20 +88,33 @@ void TaskPrepareFiles::CopyFile(const std::string& source)
 
 void TaskPrepareFiles::StepCopyFiles()
 {
-    CopyFile(m_installerContext.locations->getWidgetSource());
+    if (m_installerContext.widgetConfig.packagingType == WrtDB::PKG_TYPE_DIRECTORY_WEB_APP)
+    {
+        LogError("Copying files to temp directory...");
+        //TODO: use different copy way - above function looks ok
+        std::string command = "cp -r ";
+        command += m_installerContext.locations->getWidgetSource();
+        command += "/* ";
+        command += m_installerContext.locations->getTemporaryPackageDir();
+        LogInfo("command: " << command);
+        system(command.c_str());
+        //copy all files
+    } else {
+        CopyFile(m_installerContext.locations->getWidgetSource());
 
-    size_t last = m_installerContext.locations->getWidgetSource().find_last_of("\\/");
-    std::string sourceDir = "";
-    if (last != std::string::npos) {
-        sourceDir = m_installerContext.locations->getWidgetSource().substr(0,last+1);
-    }
+        size_t last = m_installerContext.locations->getWidgetSource().find_last_of("\\/");
+        std::string sourceDir = "";
+        if (last != std::string::npos) {
+            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());
+        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());
+        }
     }
 }
 
index 2c7e3c8..108fd66 100755 (executable)
@@ -71,7 +71,8 @@ enum Type
         ExistingVersionEqual |
         ExistingVersionNewer,
 
-    PolicyForceInstall = PolicyAlwaysInstall
+    PolicyForceInstall = PolicyAlwaysInstall,
+    PolicyDirectoryForceInstall
 };
 
 inline Type operator | (const Type &a,
index fbf458f..64345e0 100644 (file)
@@ -143,6 +143,9 @@ std::string WidgetLocation::getTemporaryPackageDir() const
 
 std::string WidgetLocation::getTemporaryRootDir() const
 {
+    if (m_type == WrtDB::PKG_TYPE_DIRECTORY_WEB_APP) {
+        return getWidgetSource();
+    }
     if(m_type == WrtDB::PKG_TYPE_HYBRID_WEB_APP)
     {
         return getTemporaryPackageDir() + WrtDB::GlobalConfig::GetWidgetSrcPath();
@@ -155,7 +158,7 @@ std::string WidgetLocation::getTemporaryRootDir() const
 
 std::string WidgetLocation::getConfigurationDir() const
 {
-    if(m_type ==  WrtDB::PKG_TYPE_HOSTED_WEB_APP)
+    if(m_type == WrtDB::PKG_TYPE_HOSTED_WEB_APP)
     {
         std::string path = ".";
         int index = m_widgetSource.find_last_of("\\/");
index 354cb5a..38db876 100644 (file)
@@ -147,8 +147,17 @@ void WrtInstaller::OnCreate()
                 return showHelpAndQuit();
             }
 
+            struct stat info;
+            if (-1 != stat(m_argv[2], &info) && S_ISDIR(info.st_mode)) {
+                LogInfo("Installing package directly from directory");
+                m_installPolicy = WRT_WIM_POLICY_DIRECTORY_FORCE_INSTALL;
+            }
+            else
+            {
+                LogInfo("Installing from regular location");
+                m_installPolicy = WRT_WIM_POLICY_WAC;
+            }
             m_packagePath = m_argv[2];
-            m_installPolicy = WRT_WIM_POLICY_WAC;
             AddStep(&WrtInstaller::installStep);
         } else if (arg == "-if" || arg == "--install-force") {
             if (m_argc != 3) {
index e370ae5..95d59ab 100755 (executable)
@@ -62,8 +62,10 @@ extern "C"
     inline WidgetUpdateMode::Type translateWidgetUpdateMode(
             wrt_widget_update_mode_t updateMode)
     {
-        WidgetUpdateMode::Type result = WidgetUpdateMode::Zero;
+        if (updateMode == WRT_WIM_POLICY_DIRECTORY_FORCE_INSTALL)
+            return WidgetUpdateMode::PolicyDirectoryForceInstall;
 
+        WidgetUpdateMode::Type result = WidgetUpdateMode::Zero;
         if (updateMode & WRT_WIM_NOT_INSTALLED) {
             result = result | WidgetUpdateMode::NotInstalled;
         }
index cd83c5b..8d77308 100755 (executable)
@@ -151,7 +151,10 @@ typedef enum wrt_widget_install_mode_e
 
     /* Force install policy
      */
-    WRT_WIM_POLICY_FORCE_INSTALL = WRT_WIM_POLICY_ALWAYS_INSTALL
+    WRT_WIM_POLICY_FORCE_INSTALL = WRT_WIM_POLICY_ALWAYS_INSTALL,
+    /* Installation from directory - forced update
+     */
+    WRT_WIM_POLICY_DIRECTORY_FORCE_INSTALL
 } wrt_widget_update_mode_t;
 
 int wrt_installer_init(void *userdata,