Revert "Change database removal logic" 19/210519/3
authorilho kim <ilho159.kim@samsung.com>
Mon, 22 Jul 2019 05:33:25 +0000 (05:33 +0000)
committerIlho Kim <ilho159.kim@samsung.com>
Mon, 22 Jul 2019 05:49:48 +0000 (14:49 +0900)
This reverts commit 66f0018a9d36e6f6638f7272d80245c9b5cb5858.

Change-Id: Ifa278212372491fa9f9f565cbf87b3ea2ff9258e

src/pkg_initdb/pkg_initdb.cc

index 69b1b15..5d54558 100644 (file)
@@ -120,38 +120,41 @@ 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;
-  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);
+  bf::path info_db_path(parser_db);
+  bf::path info_db_journal_path(parser_db_journal.c_str());
 
-  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());
 
-    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"));
+    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);
-    for (auto& path : file_list) {
-      bf::remove(path, error);
-      if (error)
-        std::cerr << path << " is not removed" << std::endl;
-    }
   }
+
+  free(parser_db);
 }
 
 }  // namespace