Change initdb logic 03/181603/1
authorJunghyun Yeon <jungh.yeon@samsung.com>
Fri, 15 Jun 2018 05:00:37 +0000 (14:00 +0900)
committerJunghyun Yeon <jungh.yeon@samsung.com>
Fri, 15 Jun 2018 05:01:38 +0000 (14:01 +0900)
- Initializing user parser db will not remove integrated cert db.
- Change method to get certificate db.

Related changes:
[pkgmgr-info] : https://review.tizen.org/gerrit/#/c/181599/

Change-Id: Id932d0e4ae7690a825aa4169b699d2ff10d08dff
Signed-off-by: Junghyun Yeon <jungh.yeon@samsung.com>
src/pkg_initdb/pkg_initdb.cc

index 5697a2a..613d79d 100644 (file)
@@ -94,22 +94,19 @@ void InitdbLoadDirectory(uid_t uid, const bf::path& directory,
 
 void RemoveOldDatabases(uid_t uid) {
   char *parser_db = getUserPkgParserDBPathUID(uid);
-  char *cert_db = getUserPkgCertDBPathUID(uid);
-  if (parser_db == nullptr || cert_db == nullptr) {
+
+  if (parser_db == nullptr) {
     std::cerr << "Failed to get db path, cannot remove old databases";
     free(parser_db);
-    free(cert_db);
     return;
   }
   std::string journal = "-journal";
   std::string parser_db_journal = parser_db + journal;
-  std::string cert_db_journal = cert_db + journal;
 
   bs::error_code error;
   bf::path info_db_path(parser_db);
   bf::path info_db_journal_path(parser_db_journal.c_str());
-  bf::path cert_db_path(cert_db);
-  bf::path cert_db_journal_path(cert_db_journal.c_str());
+
 
   bf::remove(info_db_path, error);
   if (error)
@@ -117,14 +114,21 @@ void RemoveOldDatabases(uid_t uid) {
   bf::remove(info_db_journal_path, error);
   if (error)
     std::cerr << info_db_journal_path << " is not removed" << std::endl;
-  bf::remove(cert_db_path, error);
-  if (error)
-    std::cerr << cert_db_path << " is not removed" << std::endl;
-  bf::remove(cert_db_journal_path, error);
-  if (error)
-    std::cerr << cert_db_journal_path << " is not removed" << std::endl;
+  if (IsGlobal(uid)) {
+    char *cert_db = getUserPkgCertDBPath();
+    std::string cert_db_journal = cert_db + journal;
+    bf::path cert_db_path(cert_db);
+    bf::path cert_db_journal_path(cert_db_journal.c_str());
+
+    bf::remove(cert_db_path, error);
+    if (error)
+      std::cerr << cert_db_path << " is not removed" << std::endl;
+    bf::remove(cert_db_journal_path, error);
+    if (error)
+      std::cerr << cert_db_journal_path << " is not removed" << std::endl;
+    free(cert_db);
+  }
 
-  free(cert_db);
   free(parser_db);
 }