Change naming of recovery-management file & functions 73/187773/4
authorTomasz Swierczek <t.swierczek@samsung.com>
Tue, 28 Aug 2018 08:35:19 +0000 (10:35 +0200)
committerGerrit Code Review <gerrit@review.ap-northeast-2.compute.internal>
Thu, 30 Aug 2018 08:20:41 +0000 (08:20 +0000)
The flag file is a sign for other system components to
feed DB with user-installed-apps, so they'd probably want to
know that DB 'was recovered' to initial state, rather than
know that 'DB used to be broken' (if the DB was broken,
and recovery to initial state is not successful, system
will not boot properly anyway).

Change-Id: Icc3b71b56c8299ba37a3acf3b8f20667af352e15

src/common/config.cpp
src/common/include/config.h
src/common/privilege_db.cpp
test/privilege_db_fixture.cpp
test/test_privilege_db_migration.cpp
test/test_privilege_db_transactions.cpp

index b7411df8a308684b7d9e70473f582e4efbeb6534..739fa78f7182e67ddbd3999f755cbbe789f3555b 100644 (file)
@@ -55,8 +55,8 @@ const bool IS_ASKUSER_ENABLED = false;
 const std::string privilegeDbPath = TizenPlatformConfig::makePath(TZ_SYS_DB, ".security-manager.db");
 const std::string privilegeDbFallbackPath = TizenPlatformConfig::makePath(TZ_SYS_RO_SHARE, "security-manager", ".security-manager.db");
 
-std::string dbBrokenFlagFileName(const std::string &dbPath) {
-    return dbPath + "-broken";
+std::string dbRecoveryFlagFileName(const std::string &dbPath) {
+    return dbPath + "-recovered";
 }
 };
 
index a04bfe15e15bb55515c4c84254d2f6c451b80694..25099e63086ec226814b77228e87b674e2d812c9 100644 (file)
@@ -62,7 +62,9 @@ extern const bool IS_ASKUSER_ENABLED;
 extern const std::string privilegeDbPath;
 extern const std::string privilegeDbFallbackPath;
 
-std::string dbBrokenFlagFileName(const std::string &dbPath);
+/* a file flag for other system components that there was
+ a Db failure and DB was recovered to initial (preloaded-apps only) state */
+std::string dbRecoveryFlagFileName(const std::string &dbPath);
 };
 
 } /* namespace SecurityManager */
index 530fafbed86a7deb167c9f62e92872e1fa47b180..2b217edcc8346fcf5994a2729637698a377ec715 100644 (file)
@@ -188,14 +188,14 @@ void throwDbInitEx(const std::string &errDesc) {
     ThrowMsg(PrivilegeDb::Exception::IOError, s);
 }
 
-void createBrokenFlagFile(const std::string &dbPath) {
-    if (SECURITY_MANAGER_SUCCESS != FS::createFile(Config::dbBrokenFlagFileName(dbPath)))
-        throwDbInitEx("Error creating db broken flag file");
+void createRecoveryFlagFile(const std::string &dbPath) {
+    if (SECURITY_MANAGER_SUCCESS != FS::createFile(Config::dbRecoveryFlagFileName(dbPath)))
+        throwDbInitEx("Error creating db recovery flag file");
 }
 
-void removeBrokenFlagFile(const std::string &dbPath) {
-    if (SECURITY_MANAGER_SUCCESS == FS::removeFile(Config::dbBrokenFlagFileName(dbPath)))
-        LogWarning("Broken DB flag file removed - booting 1st time after DB recovery");
+void removeRecoveryFlagFile(const std::string &dbPath) {
+    if (SECURITY_MANAGER_SUCCESS == FS::removeFile(Config::dbRecoveryFlagFileName(dbPath)))
+        LogWarning("Recovery DB flag file removed - booting 1st time after DB recovery");
 }
 
 template <class F>
@@ -216,15 +216,15 @@ void applyFallbackDb(DB::SqlConnection &conn, const std::string &dbPath, const s
 }
 
 void initDb(DB::SqlConnection &conn, const std::string &path, const std::string &roFallbackPath) {
-    removeBrokenFlagFile(path);
+    removeRecoveryFlagFile(path);
     if (!FS::fileStatus(path)) {
-        createBrokenFlagFile(path);
+        createRecoveryFlagFile(path);
         LogError("Database file " + path + " missing, attempting fallback");
         applyFallbackDb(conn, path, roFallbackPath);
     } else try {
         connectMigrateVerify(conn, path);
     } catch (DB::SqlConnection::Exception::Base &e) {
-        createBrokenFlagFile(path);
+        createRecoveryFlagFile(path);
         LogError("Database initialization error (" << e.DumpToString() << "), attempting fallback");
         tryCatchDbInit([&]{ conn.Disconnect(); });
         applyFallbackDb(conn, path, roFallbackPath);
index 05d2d77baaa158a7543ee366ea6651f6f8c129ef..6fe160d1c545ef00989a426b0c383e80ad6bb877 100644 (file)
@@ -54,7 +54,7 @@ std::string genName(const std::string &prefix, int i)
 void requireNoDb(const std::string &dbPath) {
     BOOST_REQUIRE(!FS::fileStatus(dbPath));
     BOOST_REQUIRE(!FS::fileStatus(genJournalPath(dbPath)));
-    BOOST_REQUIRE(!FS::fileStatus(Config::dbBrokenFlagFileName(dbPath)));
+    BOOST_REQUIRE(!FS::fileStatus(Config::dbRecoveryFlagFileName(dbPath)));
 }
 
 PrivilegeDBFixture::PrivilegeDBFixture(const std::string &src, const std::string &fallback,
@@ -66,7 +66,7 @@ PrivilegeDBFixture::PrivilegeDBFixture(const std::string &src, const std::string
     putFile(genJournalPath(src), genJournalPath(dst));
 
     testPrivDb = new PrivilegeDb(dst, fallback);
-    const auto brokenFlagFileName = Config::dbBrokenFlagFileName(dst);
+    const auto brokenFlagFileName = Config::dbRecoveryFlagFileName(dst);
     const auto flagFileStatus = FS::fileStatus(brokenFlagFileName);
     if (haveBrokenFlagFile == HaveBrokenFlagFile::no) {
         BOOST_REQUIRE(!flagFileStatus);
@@ -82,7 +82,7 @@ PrivilegeDBFixture::~PrivilegeDBFixture()
     BOOST_REQUIRE_MESSAGE(remove(dbPath.c_str()) == 0, "Could not delete test database file: " << dbPath);
     auto journalPath = genJournalPath(dbPath);
     BOOST_REQUIRE_MESSAGE(remove(journalPath.c_str()) == 0, "Could not delete test database journal file: " << journalPath);
-    BOOST_REQUIRE(!FS::fileStatus(Config::dbBrokenFlagFileName(dbPath)));
+    BOOST_REQUIRE(!FS::fileStatus(Config::dbRecoveryFlagFileName(dbPath)));
     delete testPrivDb;
 }
 
index 6f4065568c2d8bf7e94fed0cf44ff45a8d1bf386..7a1dfe8e80ded883f46eb4c5ea197c14cef6f0ed 100644 (file)
@@ -103,7 +103,7 @@ BOOST_AUTO_TEST_CASE(T1540_db_missing_fallback_migration) {
     const std::string missingDbPath("/tmp/thisNotExists.db");
     requireNoDb(missingDbPath);
     const auto missingDbPathJournal = genJournalPath(missingDbPath);
-    const auto missingDbPathFlag = Config::dbBrokenFlagFileName(missingDbPath);
+    const auto missingDbPathFlag = Config::dbRecoveryFlagFileName(missingDbPath);
     BOOST_REQUIRE_NO_THROW(PrivilegeDb(missingDbPath, PRIVILEGE_DB_EXAMPLE_V0));
     requireTestDbContents(missingDbPath);
     BOOST_REQUIRE(!remove(missingDbPath.c_str()));
index 68aed113ebe643de22498b72dbc7639e63060892..839e4a93f0510657c5e0e1357a148e4d490bb17d 100644 (file)
@@ -51,7 +51,7 @@ BOOST_FIXTURE_TEST_CASE(T100_privilegedb_constructor, Empty)
     requireNoDb(nExist2);
     BOOST_REQUIRE_THROW(testPrivDb.reset(new PrivilegeDb(nExist, nExist2)),
         PrivilegeDb::Exception::IOError);
-    const auto flagFile = Config::dbBrokenFlagFileName(nExist);
+    const auto flagFile = Config::dbRecoveryFlagFileName(nExist);
     BOOST_REQUIRE(!FS::fileSize(flagFile));
     BOOST_REQUIRE(!remove(flagFile.c_str()));
     requireNoDb(nExist);