WidgetHandle removal - part 2. Task order change
[framework/web/wrt-installer.git] / src / jobs / widget_install / job_widget_install.cpp
index ca3feb3..11e2b25 100755 (executable)
@@ -144,13 +144,7 @@ JobWidgetInstall::JobWidgetInstall(std::string const &widgetPath,
     struct timeval tv;
     gettimeofday(&tv, NULL);
     srand(time(NULL) + tv.tv_usec);
-    WrtDB::DbWidgetHandle handle;
-    do {
-        handle = rand() % INT_MAX + 1;
-        LogInfo("Random widget handle: " << handle);
-    } while (WidgetDAOReadOnly::isWidgetInstalled(handle));
 
-    m_installerContext.widgetHandle = handle;   //TODO: mvoe to wrt-commons (ace_widget_handle_t not int needed)
     m_installerContext.m_quiet = m_jobStruct.m_quiet;
 
     if(!browserRequest)
@@ -189,12 +183,11 @@ JobWidgetInstall::JobWidgetInstall(std::string const &widgetPath,
         if (needEncryption) {
             AddTask(new TaskEncryptResource(m_installerContext));
         }
-        AddTask(new TaskDatabase(m_installerContext)); //TODO: this should belast task (or almost)
         AddTask(new TaskFileManipulation(m_installerContext));
         // TODO: Update progress information for this task
 
         AddTask(new TaskPrivateStorage(m_installerContext));
-        AddTask(new TaskAceCheck(m_installerContext));
+
         //This is sort of quick solution, because ACE verdicts are based upon
         //data from DAO (DB). So AceCheck for now has to be AFTER DbUpdate
         //task.
@@ -210,6 +203,9 @@ JobWidgetInstall::JobWidgetInstall(std::string const &widgetPath,
         AddTask(new TaskLiveboxConf(m_installerContext));
 #endif
         AddTask(new TaskPluginsCopy(m_installerContext));
+
+        AddTask(new TaskDatabase(m_installerContext));
+        AddTask(new TaskAceCheck(m_installerContext));
     } else if (result == ConfigureResult::Updated) {
         LogInfo("Configure installation updated");
         LogInfo("Widget Update");
@@ -224,22 +220,28 @@ JobWidgetInstall::JobWidgetInstall(std::string const &widgetPath,
 
         AddTask(new TaskCertify(m_installerContext));
         AddTask(new TaskUpdateFiles(m_installerContext));
-        AddTask(new TaskDatabase(m_installerContext)); //TODO: this should belast task (or almost)
 
         /* TODO : To backup file, save md5 values */
-        AddTask(new TaskAceCheck(m_installerContext));
         AddTask(new TaskSmack(m_installerContext));
 
         AddTask(new TaskManifestFile(m_installerContext));
-        AddTask(new TaskRemoveBackupFiles(m_installerContext));
         if (m_installerContext.widgetConfig.pType ==
                 PKG_TYPE_TIZEN_WITHSVCAPP) {
             AddTask(new TaskInstallOspsvc(m_installerContext));
         }
+        AddTask(new TaskRemoveBackupFiles(m_installerContext));
 #ifdef LB_SUPPORT
         AddTask(new TaskLiveboxConf(m_installerContext));
 #endif
         AddTask(new TaskPluginsCopy(m_installerContext));
+
+        AddTask(new TaskDatabase(m_installerContext));
+
+        AddTask(new TaskAceCheck(m_installerContext));
+        //TODO: remove widgetHandle from this task and move before database task
+        // by now widget handle is needed in ace check
+        // Any error in acecheck while update will break widget
+
     } else if (result == ConfigureResult::Deferred) {
         // Installation is deferred
         LogInfo("Configure installation deferred");
@@ -270,9 +272,6 @@ std::string JobWidgetInstall::generateTizenId() {
 bool JobWidgetInstall::setTizenId(
         const WrtDB::ConfigParserData &configInfo, ConfigureResult result)
 {
-    Assert(!!m_installerContext.widgetHandle
-           && "Widget Handle should be initialized");
-
     regex_t reg;
     regcomp(&reg, REG_TIZENID_PATTERN, REG_NOSUB | REG_EXTENDED);
     struct stat dirStat;
@@ -280,8 +279,9 @@ bool JobWidgetInstall::setTizenId(
         LogDebug("Setting tizenId provided in config.xml: " << configInfo.tizenId);
         if ((regexec(&reg, DPL::ToUTF8String(*(configInfo.tizenId)).c_str(),
              static_cast<size_t>(0), NULL, 0) != REG_NOERROR) ||
-            (stat((std::string(GlobalConfig::GetUserInstalledWidgetPath()) + "/"
-                   + DPL::ToUTF8String(*(configInfo.tizenId))).c_str(), &dirStat) == 0))
+            ((stat((std::string(GlobalConfig::GetUserInstalledWidgetPath()) + "/"
+                   + DPL::ToUTF8String(*(configInfo.tizenId))).c_str(), &dirStat) == 0)
+             && result != ConfigureResult::Updated))
         {
             //it is true when tizenId does not fit REG_TIZENID_PATTERN
             LogError("tizen_id provided but not proper.");
@@ -326,11 +326,6 @@ bool JobWidgetInstall::setTizenId(
     return true;
 }
 
-DPL::Optional<WidgetHandle> JobWidgetInstall::getNewWidgetHandle() const
-{
-    return m_installerContext.widgetHandle;
-}
-
 DPL::OptionalString JobWidgetInstall::getNewTizenId() const
 {
     return m_installerContext.widgetConfig.pkgname;
@@ -359,18 +354,16 @@ JobWidgetInstall::ConfigureResult JobWidgetInstall::ConfigureInstallation(
 
     // Check policy
     WidgetUpdateMode::Type updateTypeCheckBit;
-    bool isUpdate = false;
     JobWidgetInstall::ConfigureResult ret = ConfigureResult::Ok;
 
     if (update.existingWidgetInfo.isExist == false) {
         LogInfo("Widget info does not exist");
         updateTypeCheckBit = WidgetUpdateMode::NotInstalled;
     } else {
-        LogInfo("Widget info exists. Handle: " <<
-                update.existingWidgetInfo.existingHandle);
+        LogInfo("Widget info exists. PkgName: " <<
+                update.existingWidgetInfo.pkgname);
 
-        DPL::OptionalString pkgname =
-            WidgetDAOReadOnly(update.existingWidgetInfo.existingHandle).getPkgname();
+        DPL::OptionalString pkgname = update.existingWidgetInfo.pkgname;
 
         if(pkgname.IsNull()) {
             LogInfo("But package name doesn't exist");
@@ -424,7 +417,6 @@ JobWidgetInstall::ConfigureResult JobWidgetInstall::ConfigureInstallation(
         return ConfigureResult::Failed;
     } else {
         using namespace PackageManager;
-        LogInfo("WidgetHandle: " << m_installerContext.widgetHandle);
         LogInfo("Tizen Id: " << m_installerContext.widgetConfig.pkgname);
 
         configureWidgetLocation(widgetSource, browserRequest);
@@ -582,7 +574,7 @@ WidgetUpdateInfo JobWidgetInstall::detectWidgetUpdate(
             widgetGUID,
             widgetVersion,
             WidgetUpdateInfo::ExistingWidgetInfo(
-                dao.getHandle(), dao.getVersion()));
+                *dao.getPkgname(), dao.getVersion()));
     }
     Catch(WidgetDAOReadOnly::Exception::WidgetNotExist)
     {
@@ -666,14 +658,11 @@ void JobWidgetInstall::SaveExceptionData(const Jobs::JobExceptionBase &e)
 
 void JobWidgetInstall::displayWidgetInfo()
 {
-    DPL::Optional<WidgetHandle> handle = getNewWidgetHandle();
-    Assert(!!handle);
-
-    WidgetDAOReadOnly dao(*handle);
+    WidgetDAOReadOnly dao(m_installerContext.locations->getPkgname());
 
     std::ostringstream out;
     WidgetLocalizedInfo localizedInfo =
-        W3CFileLocalization::getLocalizedInfo(*handle);
+        W3CFileLocalization::getLocalizedInfo(dao.getHandle()); //TODO: pkgname arg
 
     out << std::endl <<
         "===================================== INSTALLED WIDGET INFO ========="\
@@ -684,7 +673,7 @@ void JobWidgetInstall::displayWidgetInfo()
     out << std::endl << "Width:                       " << size.width;
     out << std::endl << "Height:                      " << size.height;
     out << std::endl << "Start File:                  " <<
-        W3CFileLocalization::getStartFile(*handle);
+        W3CFileLocalization::getStartFile(dao.getHandle()); //TODO: pkgname arg
     out << std::endl << "Version:                     " << dao.getVersion();
     out << std::endl << "Licence:                     " <<
         localizedInfo.license;
@@ -699,7 +688,7 @@ void JobWidgetInstall::displayWidgetInfo()
         dao.isDistributorSigned();
     out << std::endl << "Widget trusted:              " << dao.isTrusted();
 
-    OptionalWidgetIcon icon = W3CFileLocalization::getIcon(*handle);
+    OptionalWidgetIcon icon = W3CFileLocalization::getIcon(dao.getHandle()); //TODO: pkgname arg
     DPL::OptionalString iconSrc =
         !!icon ? icon->src : DPL::OptionalString::Null;
     out << std::endl << "Icon:                        " << iconSrc;