Widget gets corrupted if device battery is removed while uninstalling it.
authorTomasz Iwanek <t.iwanek@samsung.com>
Fri, 4 Oct 2013 15:25:25 +0000 (17:25 +0200)
committerGerrit Code Review <gerrit@gerrit.vlan144.tizendev.org>
Tue, 22 Oct 2013 04:55:13 +0000 (04:55 +0000)
 *** This patch is just a temporary fix. See [Remarks] section. ***

[Issue#]   WGL-580
[Problem]  Uninstallation is broken if battery is removed when uninstalling.
[Cause]    Db is cleaned up but files are still present.
[Solution] Ignore existing files for new installation.

[Remarks]
 If widget was uninstalled (no db information).
 Source of problem is that installation/uninstalaltion is not fully transactional
 and there is no information that something is to be fixed.
 This is just a temporary fix. This is currently losing disc space
 for widgets that will not be installed again.

Separate solution (daemon/boot time/...) for fixing unfinshed jobs should be proposed.

[Verification] Build repo and (as in issue):
 1) Install a heavy widget.
 2) Uninstall the same the widget.
 3) While uninstalling the widget, remove battery.
 4) Again install the same widget.( on step 3, widget is un-installed)

* Use widget attached in https://bugs.tizendev.org/jira/browse/WGL-580

Change-Id: I3e840cc5c508fe9951c77cabfceb377fb996a927

src/jobs/widget_install/task_configuration.cpp

index f584ff9..4dd66ca 100644 (file)
@@ -63,6 +63,7 @@ const char* const OSP_MANIFEST_XML = "info/manifest.xml";
 
 //allowed: a-z, A-Z, 0-9
 const char* REG_TIZENID_PATTERN = "^[a-zA-Z0-9]{10}.{1,}$";
+const char* REG_PKGID_PATTERN = "^[a-zA-Z0-9]{10}$";
 const char* REG_NAME_PATTERN = "^[a-zA-Z0-9._-]{1,}$";
 const size_t PACKAGE_ID_LENGTH = 10;
 
@@ -421,6 +422,7 @@ bool TaskConfiguration::validateTizenApplicationID(
     regex_t reg;
     if (regcomp(&reg, REG_TIZENID_PATTERN, REG_NOSUB | REG_EXTENDED) != 0) {
         _D("Regcomp failed");
+        return false;
     }
 
     if (regexec(&reg, DPL::ToUTF8String(tizenAppId).c_str(), 0, NULL, 0)
@@ -436,17 +438,20 @@ bool TaskConfiguration::validateTizenApplicationID(
 bool TaskConfiguration::validateTizenPackageID(
     const WrtDB::TizenPkgId &tizenPkgId)
 {
-    std::string pkgId = DPL::ToUTF8String(tizenPkgId);
-
-    std::string installPath =
-        std::string(GlobalConfig::GetUserInstalledWidgetPath()) +
-        "/" + pkgId;
+    _D("tizen application ID = [%ls]", tizenPkgId.c_str());
 
-    struct stat dirStat;
-    if ((stat(installPath.c_str(), &dirStat) == 0))
+    regex_t reg;
+    if (regcomp(&reg, REG_PKGID_PATTERN, REG_NOSUB | REG_EXTENDED) != 0)
     {
+        _D("Regcomp failed");
         return false;
     }
+    if (regexec(&reg, DPL::ToUTF8String(tizenPkgId).c_str(), 0, NULL, 0) == REG_NOMATCH)
+    {
+        regfree(&reg);
+        return false;
+    }
+    regfree(&reg);
     return true;
 }