From 66f0018a9d36e6f6638f7272d80245c9b5cb5858 Mon Sep 17 00:00:00 2001 From: Junghyun Yeon Date: Fri, 7 Jun 2019 13:15:10 +0900 Subject: [PATCH] Change database removal logic 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 --- src/pkg_initdb/pkg_initdb.cc | 41 +++++++++++++++++++---------------------- 1 file changed, 19 insertions(+), 22 deletions(-) diff --git a/src/pkg_initdb/pkg_initdb.cc b/src/pkg_initdb/pkg_initdb.cc index 5d54558..69b1b15 100644 --- a/src/pkg_initdb/pkg_initdb.cc +++ b/src/pkg_initdb/pkg_initdb.cc @@ -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 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 -- 2.7.4