Workaround for pkg_initdb failure 89/265989/2
authorSangyoon Jang <jeremy.jang@samsung.com>
Wed, 3 Nov 2021 08:43:08 +0000 (17:43 +0900)
committerSangyoon Jang <jeremy.jang@samsung.com>
Wed, 3 Nov 2021 08:56:19 +0000 (17:56 +0900)
The pkg_initdb initialize its package db only, so installing theme may
failed because of unique key constraint of theme db. Try update instead
of insert in this case.

Change-Id: I259a6c2510d699959924a609e7a90d8c422aac87
Signed-off-by: Sangyoon Jang <jeremy.jang@samsung.com>
src/theme_plugin/theme_parser.cc

index c106062..7411093 100644 (file)
@@ -230,9 +230,19 @@ bool ThemeParser::Commit(ThemeOperation operation,
     default:
       return false;
   }
-  if (reply.GetString(dbus::kCmdResultKey) != "ok")
-    return false;
-  return true;
+
+  if (reply.GetString(dbus::kCmdResultKey) == "ok")
+    return true;
+
+  if (operation == ThemeOperation::ADD && getuid() == 0) {
+    LOG(WARNING) << "This case maybe a db initializing. "
+                 << "Try update instead of insert.";
+    reply = broker.SendData(Command::UPDATE, theme_info);
+    if (reply.GetString(dbus::kCmdResultKey) == "ok")
+      return true;
+  }
+
+  return false;
 }
 
 bool ThemeParser::ForceCommit(ThemeOperation operation,
@@ -240,7 +250,10 @@ bool ThemeParser::ForceCommit(ThemeOperation operation,
   ttm::provider::ThemeInfoProxy proxy("/opt/dbspace/.tizen_theme.db");
   switch (operation) {
     case ThemeOperation::ADD:
-      return proxy.SaveTheme(theme);
+      // if pkgmgr db re-initialized, insert may failed, try update instead.
+      if (!proxy.SaveTheme(theme))
+        return proxy.UpdateTheme(theme);
+      return true;
     case ThemeOperation::UPDATE:
       return proxy.UpdateTheme(theme);
     case ThemeOperation::REMOVE: