Skip to content

Commit

Permalink
Merge pull request #5865 from npoltorapavlo/SERXIONE-6515
Browse files Browse the repository at this point in the history
SERXIONE-6515 : Integrity check
  • Loading branch information
anand-ky authored Nov 13, 2024
2 parents c90d0f6 + 0b545ff commit ef0974f
Show file tree
Hide file tree
Showing 4 changed files with 293 additions and 149 deletions.
10 changes: 1 addition & 9 deletions PersistentStore/l0test/ServiceMock.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@
#include "../Module.h"
#include <gmock/gmock.h>

class ServiceMock : public WPEFramework::PluginHost::IShell,
public WPEFramework::PluginHost::IShell::ICOMLink {
class ServiceMock : public WPEFramework::PluginHost::IShell {
public:
~ServiceMock() override = default;
MOCK_METHOD(string, Versions, (), (const, override));
Expand Down Expand Up @@ -47,15 +46,8 @@ class ServiceMock : public WPEFramework::PluginHost::IShell,
MOCK_METHOD(WPEFramework::Core::hresult, Resumed, (const bool), (override));
MOCK_METHOD(WPEFramework::Core::hresult, Metadata, (string&), (const, override));
MOCK_METHOD(WPEFramework::Core::hresult, Hibernate, (const uint32_t), (override));
MOCK_METHOD(void, Register, (WPEFramework::RPC::IRemoteConnection::INotification*), (override));
MOCK_METHOD(void, Unregister, (const WPEFramework::RPC::IRemoteConnection::INotification*), (override));
MOCK_METHOD(void, Register, (IShell::ICOMLink::INotification*), (override));
MOCK_METHOD(void, Unregister, (const IShell::ICOMLink::INotification*), (override));
MOCK_METHOD(WPEFramework::RPC::IRemoteConnection*, RemoteConnection, (const uint32_t), (override));
MOCK_METHOD(void*, Instantiate, (const WPEFramework::RPC::Object&, const uint32_t, uint32_t&), (override));
MOCK_METHOD(WPEFramework::RPC::IStringIterator*, GetLibrarySearchPaths, (const string&), (const, override));
BEGIN_INTERFACE_MAP(ServiceMock)
INTERFACE_ENTRY(IShell)
INTERFACE_ENTRY(IShell::ICOMLink)
END_INTERFACE_MAP
};
10 changes: 1 addition & 9 deletions PersistentStore/l1test/ServiceMock.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@
#include "../Module.h"
#include <gmock/gmock.h>

class ServiceMock : public WPEFramework::PluginHost::IShell,
public WPEFramework::PluginHost::IShell::ICOMLink {
class ServiceMock : public WPEFramework::PluginHost::IShell {
public:
~ServiceMock() override = default;
MOCK_METHOD(string, Versions, (), (const, override));
Expand Down Expand Up @@ -47,15 +46,8 @@ class ServiceMock : public WPEFramework::PluginHost::IShell,
MOCK_METHOD(WPEFramework::Core::hresult, Resumed, (const bool), (override));
MOCK_METHOD(WPEFramework::Core::hresult, Metadata, (string&), (const, override));
MOCK_METHOD(WPEFramework::Core::hresult, Hibernate, (const uint32_t), (override));
MOCK_METHOD(void, Register, (WPEFramework::RPC::IRemoteConnection::INotification*), (override));
MOCK_METHOD(void, Unregister, (const WPEFramework::RPC::IRemoteConnection::INotification*), (override));
MOCK_METHOD(void, Register, (IShell::ICOMLink::INotification*), (override));
MOCK_METHOD(void, Unregister, (const IShell::ICOMLink::INotification*), (override));
MOCK_METHOD(WPEFramework::RPC::IRemoteConnection*, RemoteConnection, (const uint32_t), (override));
MOCK_METHOD(void*, Instantiate, (const WPEFramework::RPC::Object&, const uint32_t, uint32_t&), (override));
MOCK_METHOD(WPEFramework::RPC::IStringIterator*, GetLibrarySearchPaths, (const string&), (const, override));
BEGIN_INTERFACE_MAP(ServiceMock)
INTERFACE_ENTRY(IShell)
INTERFACE_ENTRY(IShell::ICOMLink)
END_INTERFACE_MAP
};
32 changes: 29 additions & 3 deletions PersistentStore/sqlite/Store2.h
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ namespace Plugin {
, _maxValue(maxValue)
, _limit(limit)
{
IntegrityCheck();
Open();
}
~Store2() override
Expand All @@ -96,6 +97,28 @@ namespace Plugin {
}

private:
void IntegrityCheck()
{
Core::File file(_path);
Core::Directory(file.PathName().c_str()).CreatePath();
auto rc = sqlite3_open(_path.c_str(), &_data);
sqlite3_stmt* stmt;
sqlite3_prepare_v2(_data, "pragma integrity_check;",
-1, &stmt, nullptr);
while ((rc = sqlite3_step(stmt)) == SQLITE_ROW) {
TRACE(Trace::Information,
(_T("%s %s"), __FUNCTION__,
(const char*)sqlite3_column_text(stmt, 0)));
}
sqlite3_finalize(stmt);
sqlite3_close_v2(_data);
if (rc != SQLITE_DONE) {
OnError(__FUNCTION__, rc);
if ((rc == SQLITE_MISUSE) || (rc == SQLITE_CORRUPT)) {
ASSERT(file.Destroy());
}
}
}
void Open()
{
Core::File file(_path);
Expand Down Expand Up @@ -150,12 +173,13 @@ namespace Plugin {
+ std::to_string(_maxSize) + " then raise (fail, 'max size') end; end;",
"create temporary trigger if not exists item_limit_default insert on item"
" begin select case when"
" (select length(new.key)+length(new.value)+sum(length(key)+length(value)) from item where ns = new.ns) > "
" (select sum(s) from (select sum(length(key)+length(value)) s from item where ns = new.ns"
" union all select length(new.key)+length(new.value) s)) > "
+ std::to_string(_limit) + " then raise (fail, 'limit') end; end;",
"create temporary trigger if not exists item_limit insert on item"
" begin select case when"
" (select size-length(new.key)-length(new.value)-sum(length(key)+length(value)) from limits"
" inner join item on limits.n = item.ns where n = new.ns) < 0"
" (select size-length(new.key)-length(new.value)-ifnull(sum(length(key)+length(value)), 0) from limits"
" left join item on limits.n = item.ns where n = new.ns) < 0"
" then raise (fail, 'limit') end; end;"
};
for (auto& sql : statements) {
Expand All @@ -172,6 +196,8 @@ namespace Plugin {
OnError(__FUNCTION__, rc);
}
}

private:
bool IsTimeSynced() const
{
#ifdef WITH_SYSMGR
Expand Down
Loading

0 comments on commit ef0974f

Please sign in to comment.