Change database removal logic 54/207554/7
authorJunghyun Yeon <jungh.yeon@samsung.com>
Fri, 7 Jun 2019 04:15:10 +0000 (13:15 +0900)
committerJunghyun Yeon <jungh.yeon@samsung.com>
Fri, 12 Jul 2019 02:13:26 +0000 (02:13 +0000)
Journaling mode has changed to WAL so removing logic should be changed.

Related changes:
[pkgmgr-info] : https://review.tizen.org/gerrit/c/platform/core/appfw/pkgmgr-info/+/207513

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

index 5d54558..69b1b15 100644 (file)
@@ -120,41 +120,38 @@ void RemoveOldDatabases(uid_t uid) {
     std::cerr << "Failed to get db path, cannot remove old databases";
     return;
   }
-  std::string journal = "-journal";
-  std::string parser_db_journal = parser_db + journal;
 
   bs::error_code error;
-  bf::path info_db_path(parser_db);
-  bf::path info_db_journal_path(parser_db_journal.c_str());
+  std::vector<bf::path> file_list;
+  file_list.emplace_back(bf::path(parser_db));
+  file_list.emplace_back(bf::path(std::string(parser_db) + "-shm"));
+  file_list.emplace_back(bf::path(std::string(parser_db) + "-wal"));
+  free(parser_db);
 
+  for (auto& path : file_list) {
+    bf::remove(path, error);
+    if (error)
+      std::cerr << path << " is not removed" << std::endl;
+  }
+  file_list.clear();
 
-  bf::remove(info_db_path, error);
-  if (error)
-    std::cerr << info_db_path << " is not removed" << std::endl;
-  bf::remove(info_db_journal_path, error);
-  if (error)
-    std::cerr << info_db_journal_path << " is not removed" << std::endl;
   if (IsGlobal(uid)) {
     char *cert_db = getUserPkgCertDBPath();
     if (!cert_db) {
       std::cerr << "Failed to get cert db path" << std::endl;
-      free(parser_db);
       return;
     }
-    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;
+    file_list.emplace_back(bf::path(cert_db));
+    file_list.emplace_back(bf::path(std::string(cert_db) + "-shm"));
+    file_list.emplace_back(bf::path(std::string(cert_db) + "-wal"));
     free(cert_db);
+    for (auto& path : file_list) {
+      bf::remove(path, error);
+      if (error)
+        std::cerr << path << " is not removed" << std::endl;
+    }
   }
-
-  free(parser_db);
 }
 
 }  // namespace