Merge lp:~ken-vandine/content-hub/gsettings_type_check into lp:content-hub

Proposed by Ken VanDine
Status: Merged
Approved by: Ken VanDine
Approved revision: 82
Merged at revision: 89
Proposed branch: lp:~ken-vandine/content-hub/gsettings_type_check
Merge into: lp:content-hub
Diff against target: 142 lines (+48/-46)
2 files modified
src/com/ubuntu/content/service/main.cpp (+1/-21)
src/com/ubuntu/content/service/registry.cpp (+47/-25)
To merge this branch: bzr merge lp:~ken-vandine/content-hub/gsettings_type_check
Reviewer Review Type Date Requested Status
Michael Sheldon (community) Approve
PS Jenkins bot continuous-integration Approve
Review via email: mp+213099@code.launchpad.net

Commit message

Ensure m_defaultSources is a StringList before attempting to use
it as a list

Description of the change

Ensure m_defaultSources is a StringList before attempting to use
it as a list

To post a comment you must log in.
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
Ken VanDine (ken-vandine) wrote :

Are there any related MPs required for this MP to build/function as expected? Please list.

 * No

Is your branch in sync with latest trunk (e.g. bzr pull lp:trunk -> no changes)

 * Yes

Did you perform an exploratory manual test run of your code change and any related functionality on device or emulator?

 * Yes

Did you successfully run all tests found in your component's Test Plan (https://wiki.ubuntu.com/Process/Merges/TestPlan/content-hub) on device or emulator?

 * Yes

If you changed the UI, was the change specified/approved by design?

 * No changes

If you changed the packaging (debian), did you subscribe a core-dev to this MP?

 * No changes

Revision history for this message
Michael Sheldon (michael-sheldon) wrote :

Did you perform an exploratory manual test run of the code change and any related functionality on device or emulator?

 * Yes

Did CI run pass? If not, please explain why.

 * Yes

Have you checked that submitter has accurately filled out the submitter checklist and has taken no shortcut?

 * Yes

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/com/ubuntu/content/service/main.cpp'
2--- src/com/ubuntu/content/service/main.cpp 2014-03-04 21:47:48 +0000
3+++ src/com/ubuntu/content/service/main.cpp 2014-03-27 16:05:34 +0000
4@@ -33,22 +33,6 @@
5 namespace cuc = com::ubuntu::content;
6
7 namespace {
8- void list(QSharedPointer<cucd::PeerRegistry> registry)
9- {
10- /* list known peers for pictures */
11- QStringList result;
12- registry->enumerate_known_sources_for_type(
13- cuc::Type::Known::pictures(),
14- [&result](const cuc::Peer& peer)
15- {
16- result.append(peer.id());
17- });
18-
19- foreach (QString r, result) {
20- TRACE() << "PEER: " << r;
21- }
22- }
23-
24 void shutdown(int sig)
25 {
26 TRACE() << Q_FUNC_INFO << sig;
27@@ -100,12 +84,8 @@
28
29 if (ret == 1)
30 app->exit(ret);
31- else
32- {
33- /* list known peers */
34- list(registry);
35+ else
36 ret = app->exec();
37- }
38
39 TRACE() << "Server exiting, cleaning up";
40 delete server;
41
42=== modified file 'src/com/ubuntu/content/service/registry.cpp'
43--- src/com/ubuntu/content/service/registry.cpp 2014-03-18 15:23:16 +0000
44+++ src/com/ubuntu/content/service/registry.cpp 2014-03-27 16:05:34 +0000
45@@ -37,19 +37,35 @@
46 {
47 if (m_defaultSources->keys().contains(type.id()))
48 {
49- QString peer_id = m_defaultSources->get(type.id()).toString();
50- QStringList as(m_defaultSources->get(type.id()).toStringList());
51- if (!as.isEmpty())
52- {
53- std::string pkg = as[0].toStdString();
54- std::string app = as[1].toStdString();
55- std::string ver = as[2].toStdString();
56- cuc::Peer peer;
57- if (app.empty() || ver.empty())
58- peer = QString::fromStdString(pkg);
59- else
60- peer = QString::fromLocal8Bit(upstart_app_launch_triplet_to_app_id(pkg.c_str(), app.c_str(), ver.c_str()));
61- install_source_for_type(type, cuc::Peer{peer.id(), true});
62+ QVariant peer_v = m_defaultSources->get(type.id());
63+ // If default isn't a StringList, attempt to reset
64+ if (peer_v.type() != QVariant::StringList)
65+ {
66+ TRACE() << Q_FUNC_INFO << "Default type for" << type.id() << "is incorrect, resetting";
67+ m_defaultSources->reset(type.id());
68+ // After reset, lets get a new QVariant
69+ peer_v = m_defaultSources->get(type.id());
70+ }
71+
72+ /* Only assume the default is correct if the type is a StringList
73+ * The reset above should have ensured it was reset, lets double
74+ * check anyway to prevent crashes
75+ */
76+ if (peer_v.type() == QVariant::StringList)
77+ {
78+ QStringList as(peer_v.toStringList());
79+ if (!as.isEmpty())
80+ {
81+ std::string pkg = as[0].toStdString();
82+ std::string app = as[1].toStdString();
83+ std::string ver = as[2].toStdString();
84+ cuc::Peer peer;
85+ if (app.empty() || ver.empty())
86+ peer = QString::fromStdString(pkg);
87+ else
88+ peer = QString::fromLocal8Bit(upstart_app_launch_triplet_to_app_id(pkg.c_str(), app.c_str(), ver.c_str()));
89+ install_source_for_type(type, cuc::Peer{peer.id(), true});
90+ }
91 }
92 }
93 }
94@@ -62,13 +78,15 @@
95 TRACE() << Q_FUNC_INFO << type.id();
96 if (m_defaultSources->keys().contains(type.id()))
97 {
98- QStringList as(m_defaultSources->get(type.id()).toStringList());
99+ QVariant peer_v = m_defaultSources->get(type.id());
100+ if (peer_v.type() != QVariant::StringList)
101+ return cuc::Peer(peer_v.toString());
102+ QStringList as(peer_v.toStringList());
103 if (!as.isEmpty())
104 {
105 std::string pkg = as[0].toStdString();
106 std::string app = as[1].toStdString();
107 std::string ver = as[2].toStdString();
108- cuc::Peer peer;
109 if (app.empty() || ver.empty())
110 return cuc::Peer(QString::fromStdString(pkg));
111 return cuc::Peer(QString::fromLocal8Bit(upstart_app_launch_triplet_to_app_id(pkg.c_str(), app.c_str(), ver.c_str())), true);
112@@ -122,16 +140,20 @@
113 {
114 TRACE() << Q_FUNC_INFO << k;
115 bool defaultPeer = false;
116- QStringList as(m_defaultSources->get(type.id()).toStringList());
117- if (!as.isEmpty())
118- {
119- std::string pkg = as[0].toStdString();
120- std::string app = as[1].toStdString();
121- std::string ver = as[2].toStdString();
122- if (app.empty() || ver.empty())
123- defaultPeer = QString::fromStdString(pkg) == k;
124- else
125- defaultPeer = QString::fromLocal8Bit(upstart_app_launch_triplet_to_app_id(pkg.c_str(), app.c_str(), ver.c_str())) == k;
126+ QVariant peer_v = m_defaultSources->get(type.id());
127+ if (peer_v.type() == QVariant::StringList)
128+ {
129+ QStringList as(peer_v.toStringList());
130+ if (!as.isEmpty())
131+ {
132+ std::string pkg = as[0].toStdString();
133+ std::string app = as[1].toStdString();
134+ std::string ver = as[2].toStdString();
135+ if (app.empty() || ver.empty())
136+ defaultPeer = QString::fromStdString(pkg) == k;
137+ else
138+ defaultPeer = QString::fromLocal8Bit(upstart_app_launch_triplet_to_app_id(pkg.c_str(), app.c_str(), ver.c_str())) == k;
139+ }
140 }
141 for_each(cuc::Peer{k, defaultPeer});
142 }

Subscribers

People subscribed via source and target branches