Fixed recovery widget during preinstallation
authorSoyoung Kim <sy037.kim@samsung.com>
Wed, 3 Apr 2013 09:02:34 +0000 (18:02 +0900)
committerSoyoung Kim <sy037.kim@samsung.com>
Wed, 3 Apr 2013 09:11:32 +0000 (18:11 +0900)
[Issue#] N/A
[Problem] icon file is emtpy after booting.
[Cause] if powel off when preinstall widget during booting
[Solution] fixed recovery logic.
[SCMRequest] N/A

Change-Id: Ib66b900701aefe3c4ae69117d4e249e3a74b5d69

etc/wrt_preinstall_widgets.sh
src/jobs/widget_uninstall/job_widget_uninstall.cpp
src/jobs/widget_uninstall/job_widget_uninstall.h
src/jobs/widget_uninstall/task_remove_files.cpp
src/jobs/widget_uninstall/uninstaller_context.h
src/wrt-installer/wrt_installer.cpp

index 218015d..61935a3 100755 (executable)
 #
 
 _working_dir="/opt/usr/media/Downloads/.preinstallWidgets"
-_widget_temp="/opt/share/widget/*";
+_widget_temp="/opt/share/widget/*"
+
+#Reinstall widget during booting
+_temp_widget_path="/opt/share/widget/temp_info"
 
 install_widgets() {
        _wgt_list=`find $_working_dir -name '*.wgt'`
@@ -47,10 +50,6 @@ for file in $_widget_temp; do
     fi
 done
 
-
-#Reinstall widget during booting
-_temp_widget_path=/opt/share/widget/temp_info
-
 FILE_LIST=`ls $_temp_widget_path`
 
 if [ -n "$FILE_LIST" ]; then
@@ -60,9 +59,8 @@ if [ -n "$FILE_LIST" ]; then
         line=`cat $FILE_NAME`
         echo "----------------------------------------------------------------"
         echo "UnInstalling widget : $line ..."
-        wrt-installer -up $line
-        echo "Installing widget : $line ..."
-        wrt-installer -i $line
+               return_string=`wrt-installer -up $line 2>&1 | grep -v plugin`
+        echo "Result $return_string"
     done
 else
     echo "There is no reinstall widget."
@@ -72,10 +70,10 @@ fi
 #Plugin installation is temporary code for window SDK
 /usr/bin/wrt-installer -p
 
-if [ ! -d $_working_dir ]; then
-       echo "There is no preinstall widget directory - $_working_dir"
+RECOVER_WIDGETS=`ls $_temp_widget_path`
+if [ -n "$RECOVER_WIDGETS" ]; then
+    echo "Start Recover"
     restore_widget
-       exit 1
 fi
 
 install_widgets
index fb5244e..65a1a41 100644 (file)
@@ -15,6 +15,7 @@
  */
 
 #include <regex.h>
+#include <sys/stat.h>
 #include <widget_uninstall/job_widget_uninstall.h>
 #include <widget_uninstall/widget_uninstall_errors.h>
 #include <widget_uninstall/task_check.h>
@@ -24,6 +25,7 @@
 #include <widget_uninstall/task_smack.h>
 #include <widget_uninstall/task_uninstall_ospsvc.h>
 #include <widget_uninstall/task_delete_certificates.h>
+#include <dpl/wrt-dao-ro/global_config.h>
 #include <pkg-manager/pkgmgr_signal.h>
 #include <app2ext_interface.h>
 
@@ -31,6 +33,21 @@ using namespace WrtDB;
 
 namespace { //anonymous
 const char* REG_TIZEN_PKGID_PATTERN = "^[a-zA-Z0-9]{10}$";
+const int PKGID_LENTH = 10;
+
+bool checkDirectoryExist(const std::string& pkgId)
+{
+    std::string installPath =
+        std::string(GlobalConfig::GetUserInstalledWidgetPath()) +
+        "/" + pkgId;
+
+    struct stat dirStat;
+    if ((stat(installPath.c_str(), &dirStat) == 0)) {
+        return true;
+    }
+    return false;
+}
+
 class UninstallerTaskFail :
     public DPL::TaskDecl<UninstallerTaskFail>
 {
@@ -69,57 +86,90 @@ JobWidgetUninstall::JobWidgetUninstall(
     using namespace PackageManager;
     m_context.removeStarted = false;
     m_context.removeFinished = false;
+    m_context.removeAbnormal = false;
     m_context.uninstallStep = UninstallerContext::UNINSTALL_START;
     m_context.job = this;
     m_context.isExternalWidget = getExternalWidgetFlag();
 
     Try
     {
-        regex_t regx;
-        if(regcomp(&regx, REG_TIZEN_PKGID_PATTERN, REG_NOSUB | REG_EXTENDED)!=0){
-            LogDebug("Regcomp failed");
+        WidgetStatus status = getWidgetStatus(tizenAppId);
+
+        if (WidgetStatus::Ok == status) {
+            WrtDB::WidgetDAOReadOnly dao(DPL::FromUTF8String(m_context.tzAppid));
+            m_context.tzPkgid = DPL::ToUTF8String(dao.getTizenPkgId());
+            m_context.locations = WidgetLocation(m_context.tzPkgid);
+            m_context.locations->registerAppid(m_context.tzAppid);
+
+            LogInfo("Widget model exists. App id : " << m_context.tzAppid);
+
+            AddTask(new TaskSmack(m_context));
+            AddTask(new TaskCheck(m_context));
+
+            if (dao.getPackagingType() == PKG_TYPE_HYBRID_WEB_APP) {
+                AddTask(new TaskUninstallOspsvc(m_context));
+            }
+            AddTask(new TaskRemoveFiles(m_context));
+            AddTask(new TaskDbUpdate(m_context));
+            AddTask(new TaskRemoveCustomHandlers(m_context));
+            AddTask(new TaskDeleteCertificates(m_context));
+
+            // send start signal of pkgmgr
+            if (getInstallerStruct().pkgmgrInterface->setPkgname(m_context.tzPkgid))
+            {
+                getInstallerStruct().pkgmgrInterface->sendSignal(
+                        PKGMGR_START_KEY,
+                        PKGMGR_START_UNINSTALL);
+            }
+        } else if (WidgetStatus::NOT_INSTALLED == status) {
+            AddTask(new UninstallerTaskFail(true));
+        } else if (WidgetStatus::ABNORMAL == status) {
+            m_context.locations = WidgetLocation(m_context.tzPkgid);
+            m_context.removeAbnormal = true;
+            AddTask(new TaskRemoveFiles(m_context));
+        } else {
+            AddTask(new UninstallerTaskFail(false));
         }
+    } Catch(WidgetDAOReadOnly::Exception::Base) {
+        AddTask(new UninstallerTaskFail(false));
+    }
+}
+
+JobWidgetUninstall::WidgetStatus JobWidgetUninstall::getWidgetStatus(const std::string &id)
+{
+    regex_t regx;
+    if(regcomp(&regx, REG_TIZEN_PKGID_PATTERN, REG_NOSUB | REG_EXTENDED)!=0){
+        LogDebug("Regcomp failed");
+    }
+    std::string pkgId;
 
-        if ((regexec(&regx, tizenAppId.c_str(),
+    Try {
+        if ((regexec(&regx, id.c_str(),
                         static_cast<size_t>(0), NULL, 0) == REG_NOERROR)) {
+            pkgId = id;
+
             TizenAppId appid =
                 WrtDB::WidgetDAOReadOnly::getTzAppId(
-                        DPL::FromUTF8String(tizenAppId));
+                        DPL::FromUTF8String(id));
             LogDebug("Get appid from pkgid : " << appid);
             m_context.tzAppid = DPL::ToUTF8String(appid);
         } else {
-            m_context.tzAppid = tizenAppId;
-        }
-        WrtDB::WidgetDAOReadOnly dao(DPL::FromUTF8String(m_context.tzAppid));
-        m_context.tzPkgid = DPL::ToUTF8String(dao.getTizenPkgId());
-        m_context.locations = WidgetLocation(m_context.tzPkgid);
-        m_context.locations->registerAppid(m_context.tzAppid);
-
-        LogInfo("Widget model exists. App id : " << m_context.tzAppid);
-
-        AddTask(new TaskSmack(m_context));
-        AddTask(new TaskCheck(m_context));
-
-        if (dao.getPackagingType() == PKG_TYPE_HYBRID_WEB_APP) {
-            AddTask(new TaskUninstallOspsvc(m_context));
-        }
-        AddTask(new TaskRemoveFiles(m_context));
-        AddTask(new TaskDbUpdate(m_context));
-        AddTask(new TaskRemoveCustomHandlers(m_context));
-        AddTask(new TaskDeleteCertificates(m_context));
-
-        // send start signal of pkgmgr
-        if (getInstallerStruct().pkgmgrInterface->setPkgname(m_context.tzPkgid))
-        {
-            getInstallerStruct().pkgmgrInterface->sendSignal(
-                PKGMGR_START_KEY,
-                PKGMGR_START_UNINSTALL);
+            pkgId = id.substr(0, PKGID_LENTH);
+            WrtDB::WidgetDAOReadOnly dao(DPL::FromUTF8String(id));
+            m_context.tzAppid = id;
         }
     } Catch(WidgetDAOReadOnly::Exception::WidgetNotExist) {
-        AddTask(new UninstallerTaskFail(true));
-    } Catch(WidgetDAOReadOnly::Exception::Base) {
-        AddTask(new UninstallerTaskFail(false));
+        LogDebug("package id : " << pkgId);
+        m_context.tzPkgid = pkgId;
+        if (!pkgId.empty()) {
+            if(checkDirectoryExist(pkgId)) {
+                LogError("installed widget status is abnormal");
+                return WidgetStatus::ABNORMAL;
+            }
+        }
+        return WidgetStatus::NOT_INSTALLED;
     }
+    return WidgetStatus::Ok;
 }
 
 std::string JobWidgetUninstall::getRemovedTizenId() const
index a76444e..9ab0ee0 100644 (file)
@@ -57,6 +57,13 @@ class JobWidgetUninstall :
     bool getRemoveFinishedFlag() const;
     bool getExternalWidgetFlag() const;
 
+    enum class WidgetStatus
+    {
+        Ok, NOT_INSTALLED, ABNORMAL
+    };
+
+    WidgetStatus getWidgetStatus(const std::string &appId);
+
     void SendProgress();
     void SendFinishedSuccess();
     void SendFinishedFailure();
index ac26deb..d000f4a 100644 (file)
@@ -53,7 +53,6 @@ TaskRemoveFiles::TaskRemoveFiles(UninstallerContext& context) :
     } else {
         AddStep(&TaskRemoveFiles::StepRemoveExternalWidget);
     }
-    //AddStep(&TaskRemoveFiles::StepRemoveDesktop);
     AddStep(&TaskRemoveFiles::StepRemoveManifest);
     AddStep(&TaskRemoveFiles::StepRemoveExternalLocations);
     AddStep(&TaskRemoveFiles::StepRemoveVconf);
@@ -91,37 +90,6 @@ void TaskRemoveFiles::StepRemoveFinished()
         "Widget remove steps Finished");
 }
 
-void TaskRemoveFiles::StepRemoveDesktop()
-{
-    std::ostringstream desktopFile;
-
-    desktopFile << GlobalConfig::GetUserWidgetDesktopPath() << "/";
-    desktopFile << m_context.tzAppid << ".desktop";
-
-    unlink(desktopFile.str().c_str());
-
-    ail_appinfo_h ai = NULL;
-    ail_error_e ret;
-
-    const char* package = m_context.tzAppid.c_str();
-    LogDebug("ail delete : " << package);
-
-    ret = ail_get_appinfo(package, &ai);
-    if (ai) {
-        ail_destroy_appinfo(ai);
-    }
-
-    if (AIL_ERROR_OK == ret) {
-        if (0 > ail_desktop_remove(package)) {
-            LogWarning("Failed to remove ail information : " << package);
-        }
-    }
-
-    m_context.job->UpdateProgress(
-        UninstallerContext::UNINSTALL_REMOVE_DESKTOP,
-        "Widget remove desktop Finished");
-}
-
 void TaskRemoveFiles::StepRemoveManifest()
 {
     std::ostringstream manifest_name;
@@ -144,42 +112,46 @@ void TaskRemoveFiles::StepRemoveManifest()
 
 void TaskRemoveFiles::StepRemoveExternalLocations()
 {
-    WidgetDAO dao(DPL::FromUTF8String(m_context.tzAppid));
-    LogDebug("Removing external locations:");
-    WrtDB::ExternalLocationList externalPaths = dao.getWidgetExternalLocations();
-    FOREACH(path, externalPaths)
-    {
-        if (WrtUtilFileExists(*path)) {
-            LogDebug("  -> " << *path);
-            int ret = remove(path->c_str());
-            if (ret != 0) {
-                LogError(
-                    "Failed to remove the file: " << path->c_str() <<
-                    " with error: " << strerror(errno));
+    if (!m_context.removeAbnormal) {
+        WidgetDAO dao(DPL::FromUTF8String(m_context.tzAppid));
+        LogDebug("Removing external locations:");
+        WrtDB::ExternalLocationList externalPaths = dao.getWidgetExternalLocations();
+        FOREACH(path, externalPaths)
+        {
+            if (WrtUtilFileExists(*path)) {
+                LogDebug("  -> " << *path);
+                int ret = remove(path->c_str());
+                if (ret != 0) {
+                    LogError(
+                            "Failed to remove the file: " << path->c_str() <<
+                            " with error: " << strerror(errno));
+                }
+            } else if (WrtUtilDirExists(*path)) {
+                LogDebug("  -> " << *path);
+                if (!WrtUtilRemove(*path)) {
+                    Throw(
+                            Jobs::WidgetUninstall::TaskRemoveFiles::Exception::
+                            RemoveFilesFailed);
+                }
+            } else {
+                LogWarning("  -> " << *path << "(no such a path)");
             }
-        } else if (WrtUtilDirExists(*path)) {
-            LogDebug("  -> " << *path);
-            if (!WrtUtilRemove(*path)) {
-                Throw(
-                    Jobs::WidgetUninstall::TaskRemoveFiles::Exception::
-                        RemoveFilesFailed);
-            }
-        } else {
-            LogWarning("  -> " << *path << "(no such a path)");
         }
+        dao.unregisterAllExternalLocations();
     }
-    dao.unregisterAllExternalLocations();
 }
 
 void TaskRemoveFiles::StepRemoveVconf()
 {
-    std::string key =
-        WrtDB::VconfConfig::GetVconfKeyRootPath(DPL::FromUTF8String(m_context.
-                                                                        tzAppid));
-    if (vconf_unset_recursive(key.c_str())) {
-        LogError("Fail to unset vconf file");
-    } else {
-        LogDebug("vconf file is removed");
+    if (!m_context.removeAbnormal) {
+        std::string key =
+            WrtDB::VconfConfig::GetVconfKeyRootPath(DPL::FromUTF8String(m_context.
+                        tzAppid));
+        if (vconf_unset_recursive(key.c_str())) {
+            LogError("Fail to unset vconf file");
+        } else {
+            LogDebug("vconf file is removed");
+        }
     }
 }
 
index 67f15eb..15625d1 100644 (file)
@@ -62,6 +62,7 @@ struct UninstallerContext
     std::string tzAppid;
     std::string tzPkgid;
     bool isExternalWidget;
+    bool removeAbnormal;
 };
 
 #endif // WRT_SRC_INSTALLER_CORE_UNINSTALLER_TASKS_UNINSTALLER_CONTEXT_H_
index da38798..27d75f3 100644 (file)
@@ -63,6 +63,7 @@ const double BASE_LAYOUT_W = 720.0f;
 const double BASE_LAYOUT_H = 1280.0f;
 
 const char * const CONFIG_XML = "config.xml";
+const char * const HYBRID_CONFIG_XML = "res/wgt/config.xml";
 
 struct free_deleter
 {
@@ -503,10 +504,17 @@ void WrtInstaller::unistallWgtFileStep()
         // Open zip file
         std::unique_ptr<DPL::ZipInput> zipFile(
             new DPL::ZipInput(m_packagePath));
+        std::unique_ptr<DPL::ZipInput::File> configFile;
 
-        // Open config.xml file
-        std::unique_ptr<DPL::ZipInput::File> configFile(
-            zipFile->OpenFile(CONFIG_XML));
+        Try {
+            // Open config.xml file
+            configFile.reset(zipFile->OpenFile(CONFIG_XML));
+        }
+        Catch(DPL::ZipInput::Exception::OpenFileFailed)
+        {
+            // Open config.xml file for hybrid
+            configFile.reset(zipFile->OpenFile(HYBRID_CONFIG_XML));
+        }
 
         // Extract config
         DPL::BinaryQueue buffer;
@@ -519,16 +527,11 @@ void WrtInstaller::unistallWgtFileStep()
                                                       DPL::FromUTF32String(
                                                           L"widget"))));
 
-        DPL::OptionalString widgetGUID = configInfo.widget_id;
-
-        std::string guid = DPL::ToUTF8String(*widgetGUID);
-
-        std::string appid;
-        WrtErrStatus status = wrt_get_widget_by_guid(appid, guid);
-        if (status == WRT_SUCCESS) {
-            LogDebug("Appid from packagePath : " << appid);
+        DPL::OptionalString pkgId = configInfo.tizenPkgId;
+        if (!pkgId.IsNull()) {
+            LogDebug("Pkgid from packagePath : " << pkgId);
             wrt_uninstall_widget(
-                appid.c_str(), this, &staticWrtStatusCallback,
+                DPL::ToUTF8String(*pkgId).c_str(), this, &staticWrtStatusCallback,
                 !m_quiet ? &staticWrtUninstallProgressCallback
                 : NULL,
                 pkgmgrSignalInterface);