Skip to content

Commit ef0974f

Browse files
authored
Merge pull request rdkcentral#5865 from npoltorapavlo/SERXIONE-6515
SERXIONE-6515 : Integrity check
2 parents c90d0f6 + 0b545ff commit ef0974f

File tree

4 files changed

+293
-149
lines changed

4 files changed

+293
-149
lines changed

PersistentStore/l0test/ServiceMock.h

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@
33
#include "../Module.h"
44
#include <gmock/gmock.h>
55

6-
class ServiceMock : public WPEFramework::PluginHost::IShell,
7-
public WPEFramework::PluginHost::IShell::ICOMLink {
6+
class ServiceMock : public WPEFramework::PluginHost::IShell {
87
public:
98
~ServiceMock() override = default;
109
MOCK_METHOD(string, Versions, (), (const, override));
@@ -47,15 +46,8 @@ class ServiceMock : public WPEFramework::PluginHost::IShell,
4746
MOCK_METHOD(WPEFramework::Core::hresult, Resumed, (const bool), (override));
4847
MOCK_METHOD(WPEFramework::Core::hresult, Metadata, (string&), (const, override));
4948
MOCK_METHOD(WPEFramework::Core::hresult, Hibernate, (const uint32_t), (override));
50-
MOCK_METHOD(void, Register, (WPEFramework::RPC::IRemoteConnection::INotification*), (override));
51-
MOCK_METHOD(void, Unregister, (const WPEFramework::RPC::IRemoteConnection::INotification*), (override));
52-
MOCK_METHOD(void, Register, (IShell::ICOMLink::INotification*), (override));
53-
MOCK_METHOD(void, Unregister, (const IShell::ICOMLink::INotification*), (override));
54-
MOCK_METHOD(WPEFramework::RPC::IRemoteConnection*, RemoteConnection, (const uint32_t), (override));
55-
MOCK_METHOD(void*, Instantiate, (const WPEFramework::RPC::Object&, const uint32_t, uint32_t&), (override));
5649
MOCK_METHOD(WPEFramework::RPC::IStringIterator*, GetLibrarySearchPaths, (const string&), (const, override));
5750
BEGIN_INTERFACE_MAP(ServiceMock)
5851
INTERFACE_ENTRY(IShell)
59-
INTERFACE_ENTRY(IShell::ICOMLink)
6052
END_INTERFACE_MAP
6153
};

PersistentStore/l1test/ServiceMock.h

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@
33
#include "../Module.h"
44
#include <gmock/gmock.h>
55

6-
class ServiceMock : public WPEFramework::PluginHost::IShell,
7-
public WPEFramework::PluginHost::IShell::ICOMLink {
6+
class ServiceMock : public WPEFramework::PluginHost::IShell {
87
public:
98
~ServiceMock() override = default;
109
MOCK_METHOD(string, Versions, (), (const, override));
@@ -47,15 +46,8 @@ class ServiceMock : public WPEFramework::PluginHost::IShell,
4746
MOCK_METHOD(WPEFramework::Core::hresult, Resumed, (const bool), (override));
4847
MOCK_METHOD(WPEFramework::Core::hresult, Metadata, (string&), (const, override));
4948
MOCK_METHOD(WPEFramework::Core::hresult, Hibernate, (const uint32_t), (override));
50-
MOCK_METHOD(void, Register, (WPEFramework::RPC::IRemoteConnection::INotification*), (override));
51-
MOCK_METHOD(void, Unregister, (const WPEFramework::RPC::IRemoteConnection::INotification*), (override));
52-
MOCK_METHOD(void, Register, (IShell::ICOMLink::INotification*), (override));
53-
MOCK_METHOD(void, Unregister, (const IShell::ICOMLink::INotification*), (override));
54-
MOCK_METHOD(WPEFramework::RPC::IRemoteConnection*, RemoteConnection, (const uint32_t), (override));
55-
MOCK_METHOD(void*, Instantiate, (const WPEFramework::RPC::Object&, const uint32_t, uint32_t&), (override));
5649
MOCK_METHOD(WPEFramework::RPC::IStringIterator*, GetLibrarySearchPaths, (const string&), (const, override));
5750
BEGIN_INTERFACE_MAP(ServiceMock)
5851
INTERFACE_ENTRY(IShell)
59-
INTERFACE_ENTRY(IShell::ICOMLink)
6052
END_INTERFACE_MAP
6153
};

PersistentStore/sqlite/Store2.h

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ namespace Plugin {
8888
, _maxValue(maxValue)
8989
, _limit(limit)
9090
{
91+
IntegrityCheck();
9192
Open();
9293
}
9394
~Store2() override
@@ -96,6 +97,28 @@ namespace Plugin {
9697
}
9798

9899
private:
100+
void IntegrityCheck()
101+
{
102+
Core::File file(_path);
103+
Core::Directory(file.PathName().c_str()).CreatePath();
104+
auto rc = sqlite3_open(_path.c_str(), &_data);
105+
sqlite3_stmt* stmt;
106+
sqlite3_prepare_v2(_data, "pragma integrity_check;",
107+
-1, &stmt, nullptr);
108+
while ((rc = sqlite3_step(stmt)) == SQLITE_ROW) {
109+
TRACE(Trace::Information,
110+
(_T("%s %s"), __FUNCTION__,
111+
(const char*)sqlite3_column_text(stmt, 0)));
112+
}
113+
sqlite3_finalize(stmt);
114+
sqlite3_close_v2(_data);
115+
if (rc != SQLITE_DONE) {
116+
OnError(__FUNCTION__, rc);
117+
if ((rc == SQLITE_MISUSE) || (rc == SQLITE_CORRUPT)) {
118+
ASSERT(file.Destroy());
119+
}
120+
}
121+
}
99122
void Open()
100123
{
101124
Core::File file(_path);
@@ -150,12 +173,13 @@ namespace Plugin {
150173
+ std::to_string(_maxSize) + " then raise (fail, 'max size') end; end;",
151174
"create temporary trigger if not exists item_limit_default insert on item"
152175
" begin select case when"
153-
" (select length(new.key)+length(new.value)+sum(length(key)+length(value)) from item where ns = new.ns) > "
176+
" (select sum(s) from (select sum(length(key)+length(value)) s from item where ns = new.ns"
177+
" union all select length(new.key)+length(new.value) s)) > "
154178
+ std::to_string(_limit) + " then raise (fail, 'limit') end; end;",
155179
"create temporary trigger if not exists item_limit insert on item"
156180
" begin select case when"
157-
" (select size-length(new.key)-length(new.value)-sum(length(key)+length(value)) from limits"
158-
" inner join item on limits.n = item.ns where n = new.ns) < 0"
181+
" (select size-length(new.key)-length(new.value)-ifnull(sum(length(key)+length(value)), 0) from limits"
182+
" left join item on limits.n = item.ns where n = new.ns) < 0"
159183
" then raise (fail, 'limit') end; end;"
160184
};
161185
for (auto& sql : statements) {
@@ -172,6 +196,8 @@ namespace Plugin {
172196
OnError(__FUNCTION__, rc);
173197
}
174198
}
199+
200+
private:
175201
bool IsTimeSynced() const
176202
{
177203
#ifdef WITH_SYSMGR

0 commit comments

Comments
 (0)