Merge lp:~xavi-garcia-mena/keeper/sf-errors-dbus-interface into lp:keeper/devel
- sf-errors-dbus-interface
- Merge into devel
Status: | Merged |
---|---|
Merged at revision: | 127 |
Proposed branch: | lp:~xavi-garcia-mena/keeper/sf-errors-dbus-interface |
Merge into: | lp:keeper/devel |
Diff against target: |
2685 lines (+930/-444) 40 files modified
include/client/client.h (+5/-4) include/client/keeper-errors.h (+18/-11) include/client/keeper-items.h (+78/-0) include/helper/helper.h (+1/-1) src/cli/command-line-client-view.cpp (+34/-16) src/cli/command-line-client-view.h (+3/-3) src/cli/command-line-client.cpp (+69/-82) src/cli/command-line-client.h (+5/-3) src/client/CMakeLists.txt (+3/-0) src/client/client.cpp (+65/-46) src/client/keeper-errors.cpp (+9/-9) src/client/keeper-items.cpp (+212/-0) src/helper/backup-helper.cpp (+6/-6) src/helper/helper.cpp (+1/-1) src/helper/restore-helper.cpp (+5/-5) src/qdbus-stubs/CMakeLists.txt (+5/-4) src/qdbus-stubs/com.canonical.keeper.User.xml (+3/-3) src/qdbus-stubs/dbus-types.h (+5/-2) src/service/backup-choices.cpp (+1/-1) src/service/keeper-task-backup.cpp (+11/-5) src/service/keeper-task-restore.cpp (+9/-3) src/service/keeper-task.cpp (+6/-6) src/service/keeper-task.h (+3/-2) src/service/keeper-user.cpp (+3/-3) src/service/keeper-user.h (+4/-4) src/service/keeper.cpp (+103/-58) src/service/keeper.h (+3/-3) src/service/metadata-provider.h (+2/-1) src/service/private/keeper-task_p.h (+2/-2) src/service/restore-choices.cpp (+3/-3) src/service/task-manager.cpp (+34/-6) src/service/task-manager.h (+3/-2) src/storage-framework/storage_framework_client.cpp (+57/-1) src/storage-framework/storage_framework_client.h (+5/-0) tests/dbusmock/keeper-template-test.cpp (+111/-102) tests/integration/helpers/helpers-test-failure.cpp (+10/-10) tests/integration/helpers/helpers-test.cc (+5/-5) tests/integration/helpers/restore-test.cpp (+1/-1) tests/integration/helpers/test-helpers-base.cpp (+22/-25) tests/integration/helpers/test-helpers-base.h (+5/-5) |
To merge this branch: | bzr merge lp:~xavi-garcia-mena/keeper/sf-errors-dbus-interface |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
unity-api-1-bot | continuous-integration | Needs Fixing | |
Xavi Garcia | Pending | ||
Review via email: mp+313721@code.launchpad.net |
This proposal supersedes a proposal from 2016-12-21.
Commit message
Just for testing build
Description of the change
Just for testing build
unity-api-1-bot (unity-api-1-bot) wrote : Posted in a previous version of this proposal | # |
unity-api-1-bot (unity-api-1-bot) wrote : | # |
FAILED: Continuous integration, rev:134
https:/
Executed test runs:
FAILURE: https:/
FAILURE: https:/
Click here to trigger a rebuild:
https:/
- 127. By Xavi Garcia
-
conflicts resolved
unity-api-1-bot (unity-api-1-bot) wrote : | # |
FAILED: Continuous integration, rev:127
https:/
Executed test runs:
FAILURE: https:/
SUCCESS: https:/
FAILURE: https:/
FAILURE: https:/
FAILURE: https:/
FAILURE: https:/
FAILURE: https:/
FAILURE: https:/
Click here to trigger a rebuild:
https:/
- 128. By Xavi Garcia
-
Removed metadata_error signal, signature of dbus is internally again QVariantDictMap, returning error as additional dbus argument
- 129. By Xavi Garcia
-
KeeperError as Error and error codes changed
- 130. By Xavi Garcia
-
Fixed CMakeLists.txt
unity-api-1-bot (unity-api-1-bot) wrote : | # |
FAILED: Continuous integration, rev:130
https:/
Executed test runs:
FAILURE: https:/
SUCCESS: https:/
SUCCESS: https:/
deb: https:/
FAILURE: https:/
SUCCESS: https:/
deb: https:/
FAILURE: https:/
SUCCESS: https:/
deb: https:/
FAILURE: https:/
Click here to trigger a rebuild:
https:/
Preview Diff
1 | === modified file 'include/client/client.h' |
2 | --- include/client/client.h 2016-12-14 11:00:21 +0000 |
3 | +++ include/client/client.h 2016-12-22 14:35:27 +0000 |
4 | @@ -25,6 +25,7 @@ |
5 | #include <QScopedPointer> |
6 | #include <QStringList> |
7 | #include <QVariant> |
8 | +#include "keeper-items.h" |
9 | |
10 | struct KeeperClientPrivate; |
11 | |
12 | @@ -62,12 +63,12 @@ |
13 | |
14 | // C++ |
15 | public: |
16 | - QMap<QString, QVariantMap> getBackupChoices() const; |
17 | - QMap<QString, QVariantMap> getRestoreChoices() const; |
18 | + keeper::KeeperItemsMap getBackupChoices(keeper::Error & error) const; |
19 | + keeper::KeeperItemsMap getRestoreChoices(keeper::Error & error) const; |
20 | void startBackup(QStringList const& uuids) const; |
21 | void startRestore(QStringList const& uuids) const; |
22 | |
23 | - QMap<QString, QVariantMap> getState() const; |
24 | + keeper::KeeperItemsMap getState() const; |
25 | |
26 | Q_SIGNALS: |
27 | void statusChanged(); |
28 | @@ -75,7 +76,7 @@ |
29 | void readyToBackupChanged(); |
30 | void backupBusyChanged(); |
31 | |
32 | - void taskStatusChanged(QString const & displayName, QString const & status, double percentage, keeper::KeeperError error); |
33 | + void taskStatusChanged(QString const & displayName, QString const & status, double percentage, keeper::Error error); |
34 | void finished(); |
35 | |
36 | private Q_SLOTS: |
37 | |
38 | === modified file 'include/client/keeper-errors.h' |
39 | --- include/client/keeper-errors.h 2016-12-21 08:36:57 +0000 |
40 | +++ include/client/keeper-errors.h 2016-12-22 14:35:27 +0000 |
41 | @@ -25,25 +25,32 @@ |
42 | namespace keeper |
43 | { |
44 | |
45 | -enum class KeeperError |
46 | +enum class Error |
47 | { |
48 | OK, |
49 | - ERROR_UNKNOWN, |
50 | - HELPER_READ_ERROR, |
51 | - HELPER_WRITE_ERROR, |
52 | + UNKNOWN, |
53 | + HELPER_READ, |
54 | + HELPER_WRITE, |
55 | HELPER_INACTIVITY_DETECTED, |
56 | - HELPER_SOCKET_ERROR, |
57 | + HELPER_SOCKET, |
58 | HELPER_START_TIMEOUT, |
59 | NO_HELPER_INFORMATION_IN_REGISTRY, |
60 | HELPER_BAD_URL, |
61 | - MANIFEST_STORAGE_ERROR, |
62 | - COMMITTING_DATA_ERROR |
63 | + MANIFEST_STORAGE, |
64 | + COMMITTING_DATA, |
65 | + |
66 | + CREATING_REMOTE_DIR, |
67 | + CREATING_REMOTE_FILE, |
68 | + READING_REMOTE_FILE, |
69 | + REMOTE_DIR_NOT_EXISTS, |
70 | + NO_REMOTE_ACCOUNTS, |
71 | + NO_REMOTE_ROOTS |
72 | }; |
73 | |
74 | -KeeperError convertFromDBusVariant(const QVariant & value, bool *conversion_ok = nullptr); |
75 | +Error convert_from_dbus_variant(const QVariant & value, bool *conversion_ok = nullptr); |
76 | } // namespace keeper |
77 | |
78 | -QDBusArgument &operator<<(QDBusArgument &argument, keeper::KeeperError value); |
79 | -const QDBusArgument &operator>>(const QDBusArgument &argument, keeper::KeeperError &val); |
80 | +QDBusArgument &operator<<(QDBusArgument &argument, keeper::Error value); |
81 | +const QDBusArgument &operator>>(const QDBusArgument &argument, keeper::Error &val); |
82 | |
83 | -Q_DECLARE_METATYPE(keeper::KeeperError) |
84 | +Q_DECLARE_METATYPE(keeper::Error) |
85 | |
86 | === added file 'include/client/keeper-items.h' |
87 | --- include/client/keeper-items.h 1970-01-01 00:00:00 +0000 |
88 | +++ include/client/keeper-items.h 2016-12-22 14:35:27 +0000 |
89 | @@ -0,0 +1,78 @@ |
90 | +/* |
91 | + * Copyright (C) 2016 Canonical, Ltd. |
92 | + * |
93 | + * This program is free software: you can redistribute it and/or modify it |
94 | + * under the terms of the GNU General Public License version 3, as published |
95 | + * by the Free Software Foundation. |
96 | + * |
97 | + * This program is distributed in the hope that it will be useful, but |
98 | + * WITHOUT ANY WARRANTY; without even the implied warranties of |
99 | + * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR |
100 | + * PURPOSE. See the GNU General Public License for more details. |
101 | + * |
102 | + * You should have received a copy of the GNU General Public License along |
103 | + * with this program. If not, see <http://www.gnu.org/licenses/>. |
104 | + * |
105 | + * Authors: |
106 | + * Xavi Garcia Mena <xavi.garcia.mena@canonical.com> |
107 | + */ |
108 | + |
109 | +#pragma once |
110 | + |
111 | +#include "client/keeper-errors.h" |
112 | + |
113 | +#include <QDBusArgument> |
114 | +#include <QObject> |
115 | +#include <QScopedPointer> |
116 | + |
117 | +typedef QMap<QString, QVariantMap> QVariantDictMap; |
118 | + |
119 | +namespace keeper |
120 | +{ |
121 | + |
122 | +class KeeperItem : public QVariantMap |
123 | +{ |
124 | +public: |
125 | + KeeperItem(); |
126 | + ~KeeperItem(); |
127 | + explicit KeeperItem(QVariantMap const & values); |
128 | + |
129 | + // methods created for convenience |
130 | + bool has_property(QString const & property) const; |
131 | + QVariant get_property_value(QString const & property) const; |
132 | + |
133 | + // checks that the item is valid |
134 | + bool is_valid() const; |
135 | + |
136 | + // predefined properties |
137 | + QString get_type(bool *valid = nullptr) const; |
138 | + QString get_display_name(bool *valid = nullptr) const; |
139 | + QString get_dir_name(bool *valid = nullptr) const; |
140 | + QString get_status(bool *valid = nullptr) const; |
141 | + double get_percent_done(bool *valid = nullptr) const; |
142 | + keeper::Error get_error(bool *valid = nullptr) const; |
143 | + |
144 | + // d-bus |
145 | + static void registerMetaType(); |
146 | +}; |
147 | + |
148 | +class KeeperItemsMap : public QMap<QString, KeeperItem> |
149 | +{ |
150 | +public: |
151 | + KeeperItemsMap(); |
152 | + ~KeeperItemsMap(); |
153 | + explicit KeeperItemsMap(Error error); |
154 | + |
155 | + QStringList get_uuids() const; |
156 | + |
157 | + // d-bus |
158 | + static void registerMetaType(); |
159 | + |
160 | +private: |
161 | + Error error_ = Error::OK; |
162 | +}; |
163 | + |
164 | +} // namespace keeper |
165 | + |
166 | +Q_DECLARE_METATYPE(keeper::KeeperItem) |
167 | +Q_DECLARE_METATYPE(keeper::KeeperItemsMap) |
168 | |
169 | === modified file 'include/helper/helper.h' |
170 | --- include/helper/helper.h 2016-12-14 11:00:21 +0000 |
171 | +++ include/helper/helper.h 2016-12-22 14:35:27 +0000 |
172 | @@ -70,7 +70,7 @@ |
173 | Q_SIGNALS: |
174 | void state_changed(Helper::State); |
175 | void percent_done_changed(float); |
176 | - void error(keeper::KeeperError error); |
177 | + void error(keeper::Error error); |
178 | |
179 | protected: |
180 | Helper(QString const & appid, const clock_func& clock=default_clock, QObject *parent=nullptr); |
181 | |
182 | === modified file 'src/cli/command-line-client-view.cpp' |
183 | --- src/cli/command-line-client-view.cpp 2016-12-21 08:36:57 +0000 |
184 | +++ src/cli/command-line-client-view.cpp 2016-12-22 14:35:27 +0000 |
185 | @@ -48,7 +48,7 @@ |
186 | |
187 | void CommandLineClientView::add_task(QString const & display_name, QString const & initial_status, double initial_percentage) |
188 | { |
189 | - tasks_strings_[display_name] = get_task_string(display_name, initial_status, initial_percentage, keeper::KeeperError::OK); |
190 | + tasks_strings_[display_name] = get_task_string(display_name, initial_status, initial_percentage, keeper::Error::OK); |
191 | // TODO see if we can do this in a better way |
192 | // We add a line per each backup task |
193 | std::cout << std::endl; |
194 | @@ -112,58 +112,76 @@ |
195 | return ret; |
196 | } |
197 | |
198 | -QString CommandLineClientView::get_task_string(QString const & displayName, QString const & status, double percentage, keeper::KeeperError error) |
199 | +QString CommandLineClientView::get_task_string(QString const & displayName, QString const & status, double percentage, keeper::Error error) |
200 | { |
201 | |
202 | - if (error == keeper::KeeperError::OK) |
203 | + if (error == keeper::Error::OK) |
204 | return QStringLiteral("%1 %2 % %3").arg(displayName, 15).arg((percentage * 100), 10, 'f', 2, ' ').arg(status, -15); |
205 | else |
206 | return QStringLiteral("%1 %2 % %3 %4").arg(displayName, 15).arg((percentage * 100), 10, 'f', 2, ' ').arg(status, -15).arg(get_error_string(error)); |
207 | } |
208 | |
209 | -QString CommandLineClientView::get_error_string(keeper::KeeperError error) |
210 | +QString CommandLineClientView::get_error_string(keeper::Error error) |
211 | { |
212 | QString ret; |
213 | switch(error) |
214 | { |
215 | - case keeper::KeeperError::ERROR_UNKNOWN: |
216 | + case keeper::Error::UNKNOWN: |
217 | ret = QStringLiteral("Unknown error"); |
218 | break; |
219 | - case keeper::KeeperError::HELPER_BAD_URL: |
220 | + case keeper::Error::HELPER_BAD_URL: |
221 | ret = QStringLiteral("Bad URL for keeper helper"); |
222 | break; |
223 | - case keeper::KeeperError::HELPER_INACTIVITY_DETECTED: |
224 | + case keeper::Error::HELPER_INACTIVITY_DETECTED: |
225 | ret = QStringLiteral("Inactivity detected in task"); |
226 | break; |
227 | - case keeper::KeeperError::HELPER_START_TIMEOUT: |
228 | + case keeper::Error::HELPER_START_TIMEOUT: |
229 | ret = QStringLiteral("Task failed to start"); |
230 | break; |
231 | - case keeper::KeeperError::HELPER_READ_ERROR: |
232 | + case keeper::Error::HELPER_READ: |
233 | ret = QStringLiteral("Read error"); |
234 | break; |
235 | - case keeper::KeeperError::HELPER_SOCKET_ERROR: |
236 | + case keeper::Error::HELPER_SOCKET: |
237 | ret = QStringLiteral("Error creating internal socket"); |
238 | break; |
239 | - case keeper::KeeperError::HELPER_WRITE_ERROR: |
240 | + case keeper::Error::HELPER_WRITE: |
241 | ret = QStringLiteral("Write error"); |
242 | break; |
243 | - case keeper::KeeperError::MANIFEST_STORAGE_ERROR: |
244 | + case keeper::Error::MANIFEST_STORAGE: |
245 | ret = QStringLiteral("Error storing manifest file"); |
246 | break; |
247 | - case keeper::KeeperError::NO_HELPER_INFORMATION_IN_REGISTRY: |
248 | + case keeper::Error::NO_HELPER_INFORMATION_IN_REGISTRY: |
249 | ret = QStringLiteral("No helper information in registry"); |
250 | break; |
251 | - case keeper::KeeperError::OK: |
252 | + case keeper::Error::OK: |
253 | ret = QStringLiteral("Success"); |
254 | break; |
255 | - case keeper::KeeperError::COMMITTING_DATA_ERROR: |
256 | + case keeper::Error::COMMITTING_DATA: |
257 | ret = QStringLiteral("Error uploading data"); |
258 | break; |
259 | + case keeper::Error::CREATING_REMOTE_DIR: |
260 | + ret = QStringLiteral("Error creating remote directory"); |
261 | + break; |
262 | + case keeper::Error::CREATING_REMOTE_FILE: |
263 | + ret = QStringLiteral("Error creating remote file"); |
264 | + break; |
265 | + case keeper::Error::READING_REMOTE_FILE: |
266 | + ret = QStringLiteral("Error reading remote file"); |
267 | + break; |
268 | + case keeper::Error::REMOTE_DIR_NOT_EXISTS: |
269 | + ret = QStringLiteral("Remote directory does not exist"); |
270 | + break; |
271 | + case keeper::Error::NO_REMOTE_ACCOUNTS: |
272 | + ret = QStringLiteral("No remote accounts were found"); |
273 | + break; |
274 | + case keeper::Error::NO_REMOTE_ROOTS: |
275 | + ret = QStringLiteral("No remote root accounts were found"); |
276 | + break; |
277 | } |
278 | return ret; |
279 | } |
280 | |
281 | -void CommandLineClientView::on_task_state_changed(QString const & displayName, QString const & status, double percentage, keeper::KeeperError error) |
282 | +void CommandLineClientView::on_task_state_changed(QString const & displayName, QString const & status, double percentage, keeper::Error error) |
283 | { |
284 | auto iter = tasks_strings_.find(displayName); |
285 | if (iter != tasks_strings_.end()) |
286 | |
287 | === modified file 'src/cli/command-line-client-view.h' |
288 | --- src/cli/command-line-client-view.h 2016-12-14 11:00:21 +0000 |
289 | +++ src/cli/command-line-client-view.h 2016-12-22 14:35:27 +0000 |
290 | @@ -42,15 +42,15 @@ |
291 | void clear_all(); |
292 | void print_sections(QStringList const & sections); |
293 | void print_error_message(QString const & error_message); |
294 | + QString get_error_string(keeper::Error error); |
295 | |
296 | public Q_SLOTS: |
297 | void show_info(); |
298 | - void on_task_state_changed(QString const & displayName, QString const & status, double percentage, keeper::KeeperError error); |
299 | + void on_task_state_changed(QString const & displayName, QString const & status, double percentage, keeper::Error error); |
300 | |
301 | private: |
302 | char get_next_spin_char(); |
303 | - QString get_task_string(QString const & displayName, QString const & status, double percentage, keeper::KeeperError error); |
304 | - QString get_error_string(keeper::KeeperError error); |
305 | + QString get_task_string(QString const & displayName, QString const & status, double percentage, keeper::Error error); |
306 | |
307 | QString status_; |
308 | QTimer timer_status_; |
309 | |
310 | === modified file 'src/cli/command-line-client.cpp' |
311 | --- src/cli/command-line-client.cpp 2016-12-16 09:34:05 +0000 |
312 | +++ src/cli/command-line-client.cpp 2016-12-22 14:35:27 +0000 |
313 | @@ -42,15 +42,18 @@ |
314 | |
315 | void CommandLineClient::run_list_sections(bool remote) |
316 | { |
317 | - QMap<QString, QVariantMap> choices_values; |
318 | + keeper::KeeperItemsMap choices_values; |
319 | + keeper::Error error; |
320 | if(!remote) |
321 | { |
322 | - choices_values = keeper_client_->getBackupChoices(); |
323 | + choices_values = keeper_client_->getBackupChoices(error); |
324 | + check_for_choices_error(error); |
325 | list_backup_sections(choices_values); |
326 | } |
327 | else |
328 | { |
329 | - choices_values = keeper_client_->getRestoreChoices(); |
330 | + choices_values = keeper_client_->getRestoreChoices(error); |
331 | + check_for_choices_error(error); |
332 | list_restore_sections(choices_values); |
333 | } |
334 | } |
335 | @@ -58,28 +61,27 @@ |
336 | void CommandLineClient::run_backup(QStringList & sections) |
337 | { |
338 | auto unhandled_sections = sections; |
339 | - auto choices_values = keeper_client_->getBackupChoices(); |
340 | + keeper::Error error; |
341 | + auto choices_values = keeper_client_->getBackupChoices(error); |
342 | + check_for_choices_error(error); |
343 | QStringList uuids; |
344 | - for(auto iter = choices_values.begin(); iter != choices_values.end() && unhandled_sections.size(); ++iter) |
345 | + |
346 | + auto uuids_choices = choices_values.get_uuids(); |
347 | + for(auto iter = uuids_choices.begin(); iter != uuids_choices.end() && unhandled_sections.size(); ++iter) |
348 | { |
349 | - const auto& values = iter.value(); |
350 | - auto iter_values = values.find("type"); |
351 | - if (iter_values != values.end()) |
352 | + const auto& values = choices_values[(*iter)]; |
353 | + |
354 | + if (values.is_valid() && values.get_type() == "folder") |
355 | { |
356 | - if (iter_values.value() == "folder") |
357 | + |
358 | + auto display_name = values.get_display_name(); |
359 | + auto index = unhandled_sections.indexOf(display_name); |
360 | + if (index != -1) |
361 | { |
362 | - auto iter_display_name = values.find("display-name"); |
363 | - if (iter_display_name != values.end()) |
364 | - { |
365 | - auto index = unhandled_sections.indexOf((*iter_display_name).toString()); |
366 | - if (index != -1) |
367 | - { |
368 | - // we have to backup this section |
369 | - uuids << iter.key(); |
370 | - unhandled_sections.removeAt(index); |
371 | - view_->add_task((*iter_display_name).toString(), "waiting", 0.0); |
372 | - } |
373 | - } |
374 | + // we have to backup this section |
375 | + uuids << (*iter); |
376 | + unhandled_sections.removeAt(index); |
377 | + view_->add_task(display_name, "waiting", 0.0); |
378 | } |
379 | } |
380 | } |
381 | @@ -106,34 +108,29 @@ |
382 | void CommandLineClient::run_restore(QStringList & sections) |
383 | { |
384 | auto unhandled_sections = sections; |
385 | - auto choices_values = keeper_client_->getRestoreChoices(); |
386 | + keeper::Error error; |
387 | + auto choices_values = keeper_client_->getRestoreChoices(error); |
388 | + check_for_choices_error(error); |
389 | QStringList uuids; |
390 | - for(auto iter = choices_values.begin(); iter != choices_values.end(); ++iter) |
391 | + |
392 | + auto uuids_choices = choices_values.get_uuids(); |
393 | + for(auto iter = uuids_choices.begin(); iter != uuids_choices.end(); ++iter) |
394 | { |
395 | - const auto& values = iter.value(); |
396 | + const auto& values = choices_values[(*iter)]; |
397 | |
398 | - QVariant choice_value; |
399 | - auto has_type = find_choice_value(values, "type", choice_value); |
400 | - if (has_type && choice_value == "folder") |
401 | + if (values.is_valid() && values.get_type() == "folder") |
402 | { |
403 | - QVariant display_name; |
404 | - auto has_display_name = find_choice_value(values, "display-name", display_name); |
405 | - if (!has_display_name) |
406 | - continue; |
407 | - |
408 | - QVariant dir_name; |
409 | - auto has_dir_name = find_choice_value(values, "dir-name", dir_name); |
410 | - if (!has_dir_name) |
411 | - continue; |
412 | - |
413 | - auto section_name = QStringLiteral("%1:%2").arg(display_name.toString()).arg(dir_name.toString()); |
414 | + auto display_name = values.get_display_name(); |
415 | + auto dir_name = values.get_dir_name(); |
416 | + |
417 | + auto section_name = QStringLiteral("%1:%2").arg(display_name).arg(dir_name); |
418 | auto index = unhandled_sections.indexOf(section_name); |
419 | if (index != -1) |
420 | { |
421 | // we have to restore this section |
422 | - uuids << iter.key(); |
423 | + uuids << (*iter); |
424 | unhandled_sections.removeAt(index); |
425 | - view_->add_task(display_name.toString(), "waiting", 0.0); |
426 | + view_->add_task(display_name, "waiting", 0.0); |
427 | } |
428 | } |
429 | } |
430 | @@ -156,45 +153,34 @@ |
431 | view_->start_printing_tasks(); |
432 | } |
433 | |
434 | -void CommandLineClient::list_backup_sections(QMap<QString, QVariantMap> const & choices_values) |
435 | +void CommandLineClient::list_backup_sections(keeper::KeeperItemsMap const & choices_values) |
436 | { |
437 | QStringList sections; |
438 | for(auto iter = choices_values.begin(); iter != choices_values.end(); ++iter) |
439 | { |
440 | - const auto& values = iter.value(); |
441 | - |
442 | - QVariant choice_value; |
443 | - auto has_type = find_choice_value(values, "type", choice_value); |
444 | - if (has_type && choice_value == "folder") |
445 | - { |
446 | - auto has_display_name = find_choice_value(values, "display-name", choice_value); |
447 | - if (has_display_name) |
448 | + if ((*iter).is_valid() && (*iter).get_type() == "folder") |
449 | + { |
450 | + sections << (*iter).get_display_name(); |
451 | + } |
452 | + } |
453 | + view_->print_sections(sections); |
454 | +} |
455 | + |
456 | +void CommandLineClient::list_restore_sections(keeper::KeeperItemsMap const & choices_values) |
457 | +{ |
458 | + QMap<QString, QList<keeper::KeeperItem>> values_per_dir; |
459 | + |
460 | + for(auto iter = choices_values.begin(); iter != choices_values.end(); ++iter) |
461 | + { |
462 | + if ((*iter).is_valid() && (*iter).get_type() == "folder") |
463 | + { |
464 | + auto dir_name = (*iter).get_dir_name(); |
465 | + if (!dir_name.isEmpty()) |
466 | { |
467 | - sections << choice_value.toString(); |
468 | + values_per_dir[dir_name].push_back((*iter)); |
469 | } |
470 | } |
471 | } |
472 | - view_->print_sections(sections); |
473 | -} |
474 | - |
475 | -void CommandLineClient::list_restore_sections(QMap<QString, QVariantMap> const & choices_values) |
476 | -{ |
477 | - QMap<QString, QList<QVariantMap>> values_per_dir; |
478 | - |
479 | - for(auto iter = choices_values.begin(); iter != choices_values.end(); ++iter) |
480 | - { |
481 | - const auto& values = iter.value(); |
482 | - |
483 | - QVariant choice_value; |
484 | - auto has_type = find_choice_value(values, "type", choice_value); |
485 | - if (has_type && choice_value == "folder") |
486 | - { |
487 | - auto has_dir_name = find_choice_value(values, "dir-name", choice_value); |
488 | - if (!has_dir_name) |
489 | - continue; |
490 | - values_per_dir[choice_value.toString()].push_back(values); |
491 | - } |
492 | - } |
493 | |
494 | QStringList sections; |
495 | for(auto iter = values_per_dir.begin(); iter != values_per_dir.end(); ++iter) |
496 | @@ -202,17 +188,7 @@ |
497 | for(auto iter_items = (*iter).begin(); iter_items != (*iter).end(); ++iter_items) |
498 | { |
499 | const auto& values = (*iter_items); |
500 | - |
501 | - QVariant choice_value; |
502 | - auto has_type = find_choice_value(values, "type", choice_value); |
503 | - if (has_type && choice_value == "folder") |
504 | - { |
505 | - auto has_display_name = find_choice_value(values, "display-name", choice_value); |
506 | - if (has_display_name) |
507 | - { |
508 | - sections << QStringLiteral("%1:%2").arg(choice_value.toString()).arg(iter.key()); |
509 | - } |
510 | - } |
511 | + sections << QStringLiteral("%1:%2").arg(values.get_display_name()).arg(iter.key()); |
512 | } |
513 | sections << ""; |
514 | } |
515 | @@ -245,3 +221,14 @@ |
516 | value = (*iter); |
517 | return true; |
518 | } |
519 | + |
520 | +void CommandLineClient::check_for_choices_error(keeper::Error error) |
521 | +{ |
522 | + if (error != keeper::Error::OK) |
523 | + { |
524 | + // an error occurred |
525 | + auto error_message = QStringLiteral("Error obtaining keeper choices: %1").arg(view_->get_error_string(error)); |
526 | + view_->print_error_message(error_message); |
527 | + return; |
528 | + } |
529 | +} |
530 | |
531 | === modified file 'src/cli/command-line-client.h' |
532 | --- src/cli/command-line-client.h 2016-12-16 09:34:05 +0000 |
533 | +++ src/cli/command-line-client.h 2016-12-22 14:35:27 +0000 |
534 | @@ -22,6 +22,7 @@ |
535 | #include <QObject> |
536 | #include <QScopedPointer> |
537 | #include <QTimer> |
538 | +#include "../../include/client/keeper-items.h" |
539 | |
540 | class KeeperClient; |
541 | class CommandLineClientView; |
542 | @@ -45,9 +46,10 @@ |
543 | void on_keeper_client_finished(); |
544 | |
545 | private: |
546 | - static bool find_choice_value(QVariantMap const & choice, QString const & id, QVariant & value); |
547 | - void list_backup_sections(QMap<QString, QVariantMap> const & choices); |
548 | - void list_restore_sections(QMap<QString, QVariantMap> const & choices); |
549 | + bool find_choice_value(QVariantMap const & choice, QString const & id, QVariant & value); |
550 | + void list_backup_sections(keeper::KeeperItemsMap const & choices); |
551 | + void list_restore_sections(keeper::KeeperItemsMap const & choices); |
552 | + void check_for_choices_error(keeper::Error error); |
553 | QScopedPointer<KeeperClient> keeper_client_; |
554 | QScopedPointer<CommandLineClientView> view_; |
555 | }; |
556 | |
557 | === modified file 'src/client/CMakeLists.txt' |
558 | --- src/client/CMakeLists.txt 2016-12-14 12:03:22 +0000 |
559 | +++ src/client/CMakeLists.txt 2016-12-22 14:35:27 +0000 |
560 | @@ -10,12 +10,15 @@ |
561 | STATIC |
562 | keeper-errors.cpp |
563 | ${CMAKE_SOURCE_DIR}/include/client/keeper-errors.h |
564 | + ${CMAKE_SOURCE_DIR}/include/client/keeper-items.h |
565 | + keeper-items.cpp |
566 | ) |
567 | |
568 | set( |
569 | CLIENT_HEADERS |
570 | ${CMAKE_SOURCE_DIR}/include/client/client.h |
571 | ${CMAKE_SOURCE_DIR}/include/client/keeper-errors.h |
572 | + ${CMAKE_SOURCE_DIR}/include/client/keeper-items.h |
573 | ) |
574 | |
575 | add_library( |
576 | |
577 | === modified file 'src/client/client.cpp' |
578 | --- src/client/client.cpp 2016-12-21 17:19:46 +0000 |
579 | +++ src/client/client.cpp 2016-12-22 14:35:27 +0000 |
580 | @@ -23,6 +23,7 @@ |
581 | |
582 | #include <qdbus-stubs/keeper_user_interface.h> |
583 | #include <qdbus-stubs/DBusPropertiesInterface.h> |
584 | +#include <qdbus-stubs/dbus-types.h> |
585 | |
586 | struct KeeperClientPrivate final |
587 | { |
588 | @@ -57,7 +58,7 @@ |
589 | return (stateString == "complete" || stateString == "cancelled" || stateString == "failed"); |
590 | } |
591 | |
592 | - static bool checkAllTasksFinished(QMap<QString, QVariantMap> const & state) |
593 | + bool checkAllTasksFinished(keeper::KeeperItemsMap const & state) const |
594 | { |
595 | bool ret = true; |
596 | for (auto iter = state.begin(); ret && (iter != state.end()); ++iter) |
597 | @@ -68,15 +69,52 @@ |
598 | return ret; |
599 | } |
600 | |
601 | + static keeper::KeeperItemsMap getValue(QDBusMessage const & message, keeper::Error & error) |
602 | + { |
603 | + if (message.errorMessage().isEmpty()) |
604 | + { |
605 | + if (message.arguments().count() != 1) |
606 | + { |
607 | + error = keeper::Error::UNKNOWN; |
608 | + return keeper::KeeperItemsMap(); |
609 | + } |
610 | + |
611 | + auto value = message.arguments().at(0); |
612 | + if (value.typeName() != QStringLiteral("QDBusArgument")) |
613 | + { |
614 | + error = keeper::Error::UNKNOWN; |
615 | + return keeper::KeeperItemsMap(); |
616 | + } |
617 | + auto dbus_arg = value.value<QDBusArgument>(); |
618 | + error = keeper::Error::OK; |
619 | + keeper::KeeperItemsMap ret; |
620 | + dbus_arg >> ret; |
621 | + return ret; |
622 | + } |
623 | + if (message.arguments().count() != 2) |
624 | + { |
625 | + error = keeper::Error::UNKNOWN; |
626 | + return keeper::KeeperItemsMap(); |
627 | + } |
628 | + |
629 | + // pick up the error |
630 | + bool valid; |
631 | + error = keeper::convert_from_dbus_variant(message.arguments().at(1), &valid); |
632 | + if (!valid) |
633 | + { |
634 | + error = keeper::Error::UNKNOWN; |
635 | + } |
636 | + return keeper::KeeperItemsMap(); |
637 | + } |
638 | + |
639 | QScopedPointer<DBusInterfaceKeeperUser> userIface; |
640 | QScopedPointer<DBusPropertiesInterface> propertiesIface; |
641 | QString status; |
642 | - QMap<QString, QVariantMap> backups; |
643 | - QMap<QString, QVariantMap> restores; |
644 | + keeper::KeeperItemsMap backups; |
645 | double progress = 0; |
646 | bool readyToBackup = false; |
647 | bool backupBusy = false; |
648 | - QMap<QString, TaskStatus> task_status; |
649 | + QMap<QString, TaskStatus> taskStatus; |
650 | TasksMode mode = TasksMode::IDLE_MODE; |
651 | }; |
652 | |
653 | @@ -88,7 +126,9 @@ |
654 | |
655 | // Store backups list locally with an additional "enabled" pair to keep track enabled states |
656 | // TODO: We should be listening to a backupChoicesChanged signal to keep this list updated |
657 | - d->backups = getBackupChoices(); |
658 | + keeper::Error error; |
659 | + d->backups = getBackupChoices(error); |
660 | + |
661 | for(auto iter = d->backups.begin(); iter != d->backups.end(); ++iter) |
662 | { |
663 | iter.value()["enabled"] = false; |
664 | @@ -148,7 +188,7 @@ |
665 | } |
666 | } |
667 | |
668 | - d->task_status[uuid] = KeeperClientPrivate::TaskStatus{"", 0.0}; |
669 | + d->taskStatus[uuid] = KeeperClientPrivate::TaskStatus{"", 0.0}; |
670 | |
671 | Q_EMIT readyToBackupChanged(); |
672 | } |
673 | @@ -212,31 +252,16 @@ |
674 | return d->backups.value(uuid).value("display-name").toString(); |
675 | } |
676 | |
677 | -QMap<QString, QVariantMap> KeeperClient::getBackupChoices() const |
678 | +keeper::KeeperItemsMap KeeperClient::getBackupChoices(keeper::Error & error) const |
679 | { |
680 | - QDBusReply<QMap<QString, QVariantMap>> choices = d->userIface->call("GetBackupChoices"); |
681 | - |
682 | - if (!choices.isValid()) |
683 | - { |
684 | - qWarning() << "Error getting backup choices:" << choices.error().message(); |
685 | - return QMap<QString, QVariantMap>(); |
686 | - } |
687 | - |
688 | - return choices.value(); |
689 | + QDBusMessage choices = d->userIface->call("GetBackupChoices"); |
690 | + return KeeperClientPrivate::getValue(choices, error); |
691 | } |
692 | |
693 | -QMap<QString, QVariantMap> KeeperClient::getRestoreChoices() const |
694 | +keeper::KeeperItemsMap KeeperClient::getRestoreChoices(keeper::Error & error) const |
695 | { |
696 | - QDBusPendingReply<QMap<QString, QVariantMap>> choices = d->userIface->call("GetRestoreChoices"); |
697 | - |
698 | - choices.waitForFinished(); |
699 | - if (!choices.isValid()) |
700 | - { |
701 | - qWarning() << "Error getting restore choices:" << choices.error().message(); |
702 | - return QMap<QString, QVariantMap>(); |
703 | - } |
704 | - |
705 | - return choices.value(); |
706 | + QDBusMessage choices = d->userIface->call("GetRestoreChoices"); |
707 | + return KeeperClientPrivate::getValue(choices, error); |
708 | } |
709 | |
710 | void KeeperClient::startBackup(const QStringList& uuids) const |
711 | @@ -259,7 +284,7 @@ |
712 | } |
713 | } |
714 | |
715 | -QMap<QString, QVariantMap> KeeperClient::getState() const |
716 | +keeper::KeeperItemsMap KeeperClient::getState() const |
717 | { |
718 | return d->userIface->state(); |
719 | } |
720 | @@ -270,38 +295,32 @@ |
721 | |
722 | if (!states.empty()) |
723 | { |
724 | - for (auto const & uuid : d->task_status.keys()) |
725 | + for (auto const & uuid : d->taskStatus.keys()) |
726 | { |
727 | auto iter_state = states.find(uuid); |
728 | if (iter_state == states.end()) |
729 | { |
730 | qWarning() << "State for uuid: " << uuid << " was not found"; |
731 | } |
732 | - auto state = (*iter_state); |
733 | - double progress = state.value("percent-done").toDouble(); |
734 | - auto status = state.value("action").toString(); |
735 | - |
736 | - keeper::KeeperError keeper_error = keeper::KeeperError::OK; |
737 | - auto iter_error = state.find("error"); |
738 | - if (iter_error != state.end()) |
739 | - { |
740 | - bool conversion_ok; |
741 | - keeper_error = keeper::convertFromDBusVariant(state.value("error"), &conversion_ok); |
742 | - } |
743 | - |
744 | - auto current_state = d->task_status[uuid]; |
745 | + keeper::KeeperItem keeper_item((*iter_state)); |
746 | + auto progress = keeper_item.get_percent_done(); |
747 | + auto status = keeper_item.get_status(); |
748 | + auto keeper_error = keeper_item.get_error(); |
749 | + |
750 | + auto current_state = d->taskStatus[uuid]; |
751 | if (current_state.status != status || current_state.percentage < progress) |
752 | { |
753 | - d->task_status[uuid].status = status; |
754 | - d->task_status[uuid].percentage = progress; |
755 | - Q_EMIT(taskStatusChanged(state.value("display-name").toString(), status, progress, keeper_error)); |
756 | + d->taskStatus[uuid].status = status; |
757 | + d->taskStatus[uuid].percentage = progress; |
758 | + Q_EMIT(taskStatusChanged(keeper_item.get_display_name(), status, progress, keeper_error)); |
759 | } |
760 | } |
761 | |
762 | double totalProgress = 0; |
763 | for (auto const& state : states) |
764 | { |
765 | - totalProgress += state.value("percent-done").toDouble(); |
766 | + keeper::KeeperItem keeper_item(state); |
767 | + totalProgress += keeper_item.get_percent_done(); |
768 | } |
769 | |
770 | d->progress = totalProgress / states.count(); |
771 | |
772 | === modified file 'src/client/keeper-errors.cpp' |
773 | --- src/client/keeper-errors.cpp 2016-12-21 08:36:57 +0000 |
774 | +++ src/client/keeper-errors.cpp 2016-12-22 14:35:27 +0000 |
775 | @@ -21,7 +21,7 @@ |
776 | |
777 | #include <QDebug> |
778 | |
779 | -QDBusArgument &operator<<(QDBusArgument &argument, keeper::KeeperError value) |
780 | +QDBusArgument &operator<<(QDBusArgument &argument, keeper::Error value) |
781 | { |
782 | argument.beginStructure(); |
783 | argument << static_cast<int>(value); |
784 | @@ -29,41 +29,41 @@ |
785 | return argument; |
786 | } |
787 | |
788 | -const QDBusArgument &operator>>(const QDBusArgument &argument, keeper::KeeperError &val) |
789 | +const QDBusArgument &operator>>(const QDBusArgument &argument, keeper::Error &val) |
790 | { |
791 | int int_val; |
792 | argument.beginStructure(); |
793 | argument >> int_val; |
794 | - val = static_cast<keeper::KeeperError>(int_val); |
795 | + val = static_cast<keeper::Error>(int_val); |
796 | argument.endStructure(); |
797 | return argument; |
798 | } |
799 | |
800 | namespace keeper |
801 | { |
802 | -KeeperError convertFromDBusVariant(const QVariant & value, bool *conversion_ok) |
803 | +Error convert_from_dbus_variant(const QVariant & value, bool *conversion_ok) |
804 | { |
805 | if (value.typeName() != QStringLiteral("QDBusArgument")) |
806 | { |
807 | qWarning() << Q_FUNC_INFO |
808 | - << " Error converting dbus QVariant to KeeperError, expected type is [ QDBusArgument ] and current type is: [" |
809 | + << " Error converting dbus QVariant to Error, expected type is [ QDBusArgument ] and current type is: [" |
810 | << value.typeName() << "]"; |
811 | if (conversion_ok) |
812 | *conversion_ok = false; |
813 | - return KeeperError(keeper::KeeperError::ERROR_UNKNOWN); |
814 | + return Error(keeper::Error::UNKNOWN); |
815 | } |
816 | auto dbus_arg = value.value<QDBusArgument>(); |
817 | |
818 | if (dbus_arg.currentSignature() != "(i)") |
819 | { |
820 | qWarning() << Q_FUNC_INFO |
821 | - << " Error converting dbus QVariant to KeeperError, expected signature is \"(i)\" and current signature is: \"" |
822 | + << " Error converting dbus QVariant to Error, expected signature is \"(i)\" and current signature is: \"" |
823 | << dbus_arg.currentSignature() << "\""; |
824 | if (conversion_ok) |
825 | *conversion_ok = false; |
826 | - return KeeperError(keeper::KeeperError::ERROR_UNKNOWN); |
827 | + return Error(keeper::Error::UNKNOWN); |
828 | } |
829 | - KeeperError ret; |
830 | + Error ret; |
831 | dbus_arg >> ret; |
832 | |
833 | if (conversion_ok) |
834 | |
835 | === added file 'src/client/keeper-items.cpp' |
836 | --- src/client/keeper-items.cpp 1970-01-01 00:00:00 +0000 |
837 | +++ src/client/keeper-items.cpp 2016-12-22 14:35:27 +0000 |
838 | @@ -0,0 +1,212 @@ |
839 | +/* |
840 | + * Copyright (C) 2016 Canonical, Ltd. |
841 | + * |
842 | + * This program is free software: you can redistribute it and/or modify it |
843 | + * under the terms of the GNU General Public License version 3, as published |
844 | + * by the Free Software Foundation. |
845 | + * |
846 | + * This program is distributed in the hope that it will be useful, but |
847 | + * WITHOUT ANY WARRANTY; without even the implied warranties of |
848 | + * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR |
849 | + * PURPOSE. See the GNU General Public License for more details. |
850 | + * |
851 | + * You should have received a copy of the GNU General Public License along |
852 | + * with this program. If not, see <http://www.gnu.org/licenses/>. |
853 | + * |
854 | + * Authors: |
855 | + * Xavi Garcia Mena <xavi.garcia.mena@canonical.com> |
856 | + */ |
857 | + |
858 | +#include "client/keeper-items.h" |
859 | + |
860 | +#include <QtDBus> |
861 | +#include <QVariantMap> |
862 | + |
863 | +namespace keeper |
864 | +{ |
865 | + |
866 | +// KeeperItem |
867 | + |
868 | +bool has_all_predefined_properties(QStringList const & predefined_properties, KeeperItem const & values); |
869 | + |
870 | +bool has_all_predefined_properties(QStringList const & predefined_properties, KeeperItem const & values) |
871 | +{ |
872 | + for (auto iter = predefined_properties.begin(); iter != predefined_properties.end(); ++iter) |
873 | + { |
874 | + if (!values.has_property((*iter))) |
875 | + return false; |
876 | + } |
877 | + return true; |
878 | +} |
879 | + |
880 | +constexpr const char TYPE_KEY[] = "type"; |
881 | +constexpr const char DISPLAY_NAME_KEY[] = "display-name"; |
882 | +constexpr const char DIR_NAME_KEY[] = "dir-name"; |
883 | +constexpr const char STATUS_KEY[] = "action"; |
884 | +constexpr const char PERCENT_DONE_KEY[] = "percent-done"; |
885 | +constexpr const char ERROR_KEY[] = "error"; |
886 | + |
887 | + |
888 | +KeeperItem::KeeperItem() |
889 | + : QVariantMap() |
890 | +{ |
891 | +} |
892 | + |
893 | +KeeperItem::KeeperItem(QVariantMap const & values) |
894 | + : QVariantMap(values) |
895 | +{ |
896 | +} |
897 | + |
898 | +KeeperItem::~KeeperItem() = default; |
899 | + |
900 | +QVariant KeeperItem::get_property_value(QString const & property) const |
901 | +{ |
902 | + auto iter = this->find(property); |
903 | + if (iter != this->end()) |
904 | + { |
905 | + return (*iter); |
906 | + } |
907 | + else |
908 | + { |
909 | + return QVariant(); |
910 | + } |
911 | +} |
912 | + |
913 | +bool KeeperItem::is_valid()const |
914 | +{ |
915 | + // we need at least type and display name to consider this a keeper item |
916 | + return has_all_predefined_properties(QStringList{TYPE_KEY, DISPLAY_NAME_KEY}, *this); |
917 | +} |
918 | + |
919 | +bool KeeperItem::has_property(QString const & property) const |
920 | +{ |
921 | + auto iter = this->find(property); |
922 | + return iter != this->end(); |
923 | +} |
924 | + |
925 | +QString KeeperItem::get_type(bool *valid) const |
926 | +{ |
927 | + if (!has_property(TYPE_KEY)) |
928 | + { |
929 | + if (valid) |
930 | + *valid = false; |
931 | + return QString(); |
932 | + } |
933 | + if (valid) |
934 | + *valid = true; |
935 | + return get_property_value(TYPE_KEY).toString(); |
936 | +} |
937 | + |
938 | +QString KeeperItem::get_display_name(bool *valid) const |
939 | +{ |
940 | + if (!has_property(DISPLAY_NAME_KEY)) |
941 | + { |
942 | + if (valid) |
943 | + *valid = false; |
944 | + return QString(); |
945 | + } |
946 | + if (valid) |
947 | + *valid = true; |
948 | + return get_property_value(DISPLAY_NAME_KEY).toString(); |
949 | +} |
950 | + |
951 | +QString KeeperItem::get_dir_name(bool *valid) const |
952 | +{ |
953 | + if (!has_property(DIR_NAME_KEY)) |
954 | + { |
955 | + if (valid) |
956 | + *valid = false; |
957 | + return QString(); |
958 | + } |
959 | + if (valid) |
960 | + *valid = true; |
961 | + return get_property_value(DIR_NAME_KEY).toString(); |
962 | +} |
963 | + |
964 | +QString KeeperItem::get_status(bool *valid) const |
965 | +{ |
966 | + if (!has_property(STATUS_KEY)) |
967 | + { |
968 | + if (valid) |
969 | + *valid = false; |
970 | + return QString(); |
971 | + } |
972 | + if (valid) |
973 | + *valid = true; |
974 | + return get_property_value(STATUS_KEY).toString(); |
975 | +} |
976 | + |
977 | +double KeeperItem::get_percent_done(bool *valid) const |
978 | +{ |
979 | + auto value = get_property_value(PERCENT_DONE_KEY); |
980 | + if (value.type() == QVariant::Double) |
981 | + { |
982 | + if (valid) |
983 | + *valid = true; |
984 | + return get_property_value(PERCENT_DONE_KEY).toDouble(); |
985 | + } |
986 | + else |
987 | + { |
988 | + if (valid) |
989 | + *valid = false; |
990 | + return -1; |
991 | + } |
992 | +} |
993 | + |
994 | +keeper::Error KeeperItem::get_error(bool *valid) const |
995 | +{ |
996 | + // if it does not have explicitly defined the error, OK is considered |
997 | + if (!has_property(ERROR_KEY)) |
998 | + return keeper::Error::OK; |
999 | + |
1000 | + return keeper::convert_from_dbus_variant(get_property_value(ERROR_KEY), valid); |
1001 | +} |
1002 | + |
1003 | +void KeeperItem::registerMetaType() |
1004 | +{ |
1005 | + qRegisterMetaType<KeeperItem>("KeeperItem"); |
1006 | + |
1007 | + qDBusRegisterMetaType<KeeperItem>(); |
1008 | +} |
1009 | + |
1010 | +///// |
1011 | +// KeeperItemsMap |
1012 | +///// |
1013 | + |
1014 | + |
1015 | +KeeperItemsMap::KeeperItemsMap() |
1016 | + : QMap<QString, KeeperItem>() |
1017 | +{ |
1018 | +} |
1019 | + |
1020 | +KeeperItemsMap::~KeeperItemsMap() = default; |
1021 | + |
1022 | + |
1023 | +KeeperItemsMap::KeeperItemsMap(Error error) |
1024 | + : QMap<QString, KeeperItem>() |
1025 | + , error_(error) |
1026 | +{ |
1027 | + |
1028 | +} |
1029 | + |
1030 | +QStringList KeeperItemsMap::get_uuids() const |
1031 | +{ |
1032 | + QStringList ret; |
1033 | + for (auto iter = this->begin(); iter != this->end(); ++iter) |
1034 | + { |
1035 | + ret << iter.key(); |
1036 | + } |
1037 | + |
1038 | + return ret; |
1039 | +} |
1040 | + |
1041 | +void KeeperItemsMap::registerMetaType() |
1042 | +{ |
1043 | + qRegisterMetaType<KeeperItemsMap>("KeeperItemsMap"); |
1044 | + |
1045 | + qDBusRegisterMetaType<KeeperItemsMap>(); |
1046 | + |
1047 | + KeeperItem::registerMetaType(); |
1048 | +} |
1049 | + |
1050 | +} // namespace keeper |
1051 | |
1052 | === modified file 'src/helper/backup-helper.cpp' |
1053 | --- src/helper/backup-helper.cpp 2016-12-15 14:30:42 +0000 |
1054 | +++ src/helper/backup-helper.cpp 2016-12-22 14:35:27 +0000 |
1055 | @@ -63,7 +63,7 @@ |
1056 | if (rc == -1) |
1057 | { |
1058 | qWarning() << QStringLiteral("Error creating socket to communicate with helper");; |
1059 | - Q_EMIT(q_ptr->error(keeper::KeeperError::HELPER_SOCKET_ERROR)); |
1060 | + Q_EMIT(q_ptr->error(keeper::Error::HELPER_SOCKET)); |
1061 | return; |
1062 | } |
1063 | |
1064 | @@ -142,7 +142,7 @@ |
1065 | if (!success) |
1066 | { |
1067 | write_error_ = true; |
1068 | - Q_EMIT(q_ptr->error(keeper::KeeperError::COMMITTING_DATA_ERROR)); |
1069 | + Q_EMIT(q_ptr->error(keeper::Error::COMMITTING_DATA)); |
1070 | } |
1071 | else |
1072 | uploader_committed_file_name_ = uploader_->file_name(); |
1073 | @@ -178,7 +178,7 @@ |
1074 | { |
1075 | stop_inactivity_timer(); |
1076 | qWarning() << "Inactivity detected in the helper...stopping it"; |
1077 | - Q_EMIT(q_ptr->error(keeper::KeeperError::HELPER_INACTIVITY_DETECTED)); |
1078 | + Q_EMIT(q_ptr->error(keeper::Error::HELPER_INACTIVITY_DETECTED)); |
1079 | stop(); |
1080 | } |
1081 | |
1082 | @@ -214,7 +214,7 @@ |
1083 | } |
1084 | else if (n < 0) { |
1085 | read_error_ = true; |
1086 | - Q_EMIT(q_ptr->error(keeper::KeeperError::HELPER_READ_ERROR)); |
1087 | + Q_EMIT(q_ptr->error(keeper::Error::HELPER_READ)); |
1088 | stop(); |
1089 | return; |
1090 | } |
1091 | @@ -230,7 +230,7 @@ |
1092 | if (n < 0) { |
1093 | write_error_ = true; |
1094 | qWarning() << "Write error:" << socket->errorString(); |
1095 | - Q_EMIT(q_ptr->error(keeper::KeeperError::HELPER_WRITE_ERROR)); |
1096 | + Q_EMIT(q_ptr->error(keeper::Error::HELPER_WRITE)); |
1097 | stop(); |
1098 | } |
1099 | break; |
1100 | @@ -263,7 +263,7 @@ |
1101 | { |
1102 | if (n_uploaded_ > q_ptr->expected_size()) |
1103 | { |
1104 | - Q_EMIT(q_ptr->error(keeper::KeeperError::HELPER_WRITE_ERROR)); |
1105 | + Q_EMIT(q_ptr->error(keeper::Error::HELPER_WRITE)); |
1106 | } |
1107 | q_ptr->set_state(Helper::State::FAILED); |
1108 | } |
1109 | |
1110 | === modified file 'src/helper/helper.cpp' |
1111 | --- src/helper/helper.cpp 2016-12-21 17:29:58 +0000 |
1112 | +++ src/helper/helper.cpp 2016-12-22 14:35:27 +0000 |
1113 | @@ -354,7 +354,7 @@ |
1114 | void on_max_time_waiting_for_ual_started() |
1115 | { |
1116 | qWarning() << "Maximum time reached waiting for the helper to start."; |
1117 | - Q_EMIT(q_ptr->error(keeper::KeeperError::HELPER_START_TIMEOUT)); |
1118 | + Q_EMIT(q_ptr->error(keeper::Error::HELPER_START_TIMEOUT)); |
1119 | q_ptr->set_state(Helper::State::FAILED); |
1120 | stop_wait_for_ual_timer(); |
1121 | } |
1122 | |
1123 | === modified file 'src/helper/restore-helper.cpp' |
1124 | --- src/helper/restore-helper.cpp 2016-12-15 14:30:42 +0000 |
1125 | +++ src/helper/restore-helper.cpp 2016-12-22 14:35:27 +0000 |
1126 | @@ -58,7 +58,7 @@ |
1127 | if (rc == -1) |
1128 | { |
1129 | qWarning() << QStringLiteral("Error creating socket to communicate with helper");; |
1130 | - Q_EMIT(q_ptr->error(keeper::KeeperError::HELPER_SOCKET_ERROR)); |
1131 | + Q_EMIT(q_ptr->error(keeper::Error::HELPER_SOCKET)); |
1132 | return; |
1133 | } |
1134 | |
1135 | @@ -167,7 +167,7 @@ |
1136 | { |
1137 | stop_inactivity_timer(); |
1138 | qWarning() << "Inactivity detected in the helper...stopping it"; |
1139 | - Q_EMIT(q_ptr->error(keeper::KeeperError::HELPER_INACTIVITY_DETECTED)); |
1140 | + Q_EMIT(q_ptr->error(keeper::Error::HELPER_INACTIVITY_DETECTED)); |
1141 | stop(); |
1142 | } |
1143 | |
1144 | @@ -206,7 +206,7 @@ |
1145 | else if (n < 0) { |
1146 | read_error_ = true; |
1147 | qDebug() << "Read error in restore helper: " << socket->errorString(); |
1148 | - Q_EMIT(q_ptr->error(keeper::KeeperError::HELPER_READ_ERROR)); |
1149 | + Q_EMIT(q_ptr->error(keeper::Error::HELPER_READ)); |
1150 | stop(); |
1151 | return; |
1152 | } |
1153 | @@ -225,7 +225,7 @@ |
1154 | if (n < 0) { |
1155 | write_error_ = true; |
1156 | qWarning() << "Write error:" << write_socket_.errorString(); |
1157 | - Q_EMIT(q_ptr->error(keeper::KeeperError::HELPER_WRITE_ERROR)); |
1158 | + Q_EMIT(q_ptr->error(keeper::Error::HELPER_WRITE)); |
1159 | stop(); |
1160 | } |
1161 | break; |
1162 | @@ -259,7 +259,7 @@ |
1163 | { |
1164 | if (n_uploaded_ > q_ptr->expected_size()) |
1165 | { |
1166 | - Q_EMIT(q_ptr->error(keeper::KeeperError::HELPER_WRITE_ERROR)); |
1167 | + Q_EMIT(q_ptr->error(keeper::Error::HELPER_WRITE)); |
1168 | } |
1169 | q_ptr->set_state(Helper::State::FAILED); |
1170 | } |
1171 | |
1172 | === modified file 'src/qdbus-stubs/CMakeLists.txt' |
1173 | --- src/qdbus-stubs/CMakeLists.txt 2016-11-30 14:46:29 +0000 |
1174 | +++ src/qdbus-stubs/CMakeLists.txt 2016-12-22 14:35:27 +0000 |
1175 | @@ -67,6 +67,7 @@ |
1176 | ${user_xml} |
1177 | PROPERTIES |
1178 | CLASSNAME DBusInterfaceKeeperUser |
1179 | + INCLUDE "client/keeper-items.h" |
1180 | ) |
1181 | |
1182 | qt5_add_dbus_interface( |
1183 | @@ -116,7 +117,7 @@ |
1184 | ${adaptor_files} |
1185 | ) |
1186 | |
1187 | -#target_link_libraries( |
1188 | -# ${STUBS_LIB} |
1189 | -# backup-helper |
1190 | -#) |
1191 | +target_link_libraries( |
1192 | + ${STUBS_LIB} |
1193 | + keeper-errors-lib |
1194 | +) |
1195 | |
1196 | === modified file 'src/qdbus-stubs/com.canonical.keeper.User.xml' |
1197 | --- src/qdbus-stubs/com.canonical.keeper.User.xml 2016-07-28 19:44:52 +0000 |
1198 | +++ src/qdbus-stubs/com.canonical.keeper.User.xml 2016-12-22 14:35:27 +0000 |
1199 | @@ -5,7 +5,7 @@ |
1200 | <interface name="com.canonical.keeper.User"> |
1201 | |
1202 | <method name="GetBackupChoices"> |
1203 | - <annotation name="org.qtproject.QtDBus.QtTypeName.Out0" value="QVariantDictMap"/> |
1204 | + <annotation name="org.qtproject.QtDBus.QtTypeName.Out0" value="keeper::KeeperItemsMap"/> |
1205 | <arg direction="out" name="backups" type="a{sa{sv}}"> |
1206 | <doc:doc> |
1207 | <doc:summary>A list of backup possibilities for the user to choose from</doc:summary> |
1208 | @@ -35,7 +35,7 @@ |
1209 | </method> |
1210 | |
1211 | <method name="GetRestoreChoices"> |
1212 | - <annotation name="org.qtproject.QtDBus.QtTypeName.Out0" value="QVariantDictMap"/> |
1213 | + <annotation name="org.qtproject.QtDBus.QtTypeName.Out0" value="keeper::KeeperItemsMap"/> |
1214 | <arg direction="out" name="backups" type="a{sa{sv}}"> |
1215 | <doc:doc> |
1216 | <doc:summary>The backups which already exist and can be restored</doc:summary> |
1217 | @@ -65,7 +65,7 @@ |
1218 | </method> |
1219 | |
1220 | <property name="State" type="a{sa{sv}}" access="read"> |
1221 | - <annotation name="org.qtproject.QtDBus.QtTypeName" value="QVariantDictMap"/> |
1222 | + <annotation name="org.qtproject.QtDBus.QtTypeName" value="keeper::KeeperItemsMap"/> |
1223 | <doc:doc> |
1224 | <doc:description> |
1225 | <doc:para>Provides state information so the user interface can show |
1226 | |
1227 | === modified file 'src/qdbus-stubs/dbus-types.h' |
1228 | --- src/qdbus-stubs/dbus-types.h 2016-12-14 11:00:21 +0000 |
1229 | +++ src/qdbus-stubs/dbus-types.h 2016-12-22 14:35:27 +0000 |
1230 | @@ -23,6 +23,7 @@ |
1231 | #include <QString> |
1232 | #include <QVariantMap> |
1233 | #include <client/keeper-errors.h> |
1234 | +#include "client/keeper-items.h" |
1235 | |
1236 | typedef QMap<QString, QVariantMap> QVariantDictMap; |
1237 | Q_DECLARE_METATYPE(QVariantDictMap) |
1238 | @@ -36,11 +37,13 @@ |
1239 | { |
1240 | qRegisterMetaType<QVariantDictMap>("QVariantDictMap"); |
1241 | qRegisterMetaType<QStringMap>("QStringMap"); |
1242 | - qRegisterMetaType<keeper::KeeperError>("keeper::KeeperError"); |
1243 | + qRegisterMetaType<keeper::Error>("keeper::Error"); |
1244 | |
1245 | qDBusRegisterMetaType<QVariantDictMap>(); |
1246 | qDBusRegisterMetaType<QStringMap>(); |
1247 | - qDBusRegisterMetaType<keeper::KeeperError>(); |
1248 | + qDBusRegisterMetaType<keeper::Error>(); |
1249 | + |
1250 | + keeper::KeeperItemsMap::registerMetaType(); |
1251 | } |
1252 | |
1253 | constexpr const char KEEPER_SERVICE[] = "com.canonical.keeper"; |
1254 | |
1255 | === modified file 'src/service/backup-choices.cpp' |
1256 | --- src/service/backup-choices.cpp 2016-10-28 15:11:21 +0000 |
1257 | +++ src/service/backup-choices.cpp 2016-12-22 14:35:27 +0000 |
1258 | @@ -160,5 +160,5 @@ |
1259 | } |
1260 | } |
1261 | |
1262 | - Q_EMIT(finished()); |
1263 | + Q_EMIT(finished(keeper::Error::OK)); |
1264 | } |
1265 | |
1266 | === modified file 'src/service/keeper-task-backup.cpp' |
1267 | --- src/service/keeper-task-backup.cpp 2016-12-15 14:30:42 +0000 |
1268 | +++ src/service/keeper-task-backup.cpp 2016-12-22 14:35:27 +0000 |
1269 | @@ -50,7 +50,7 @@ |
1270 | qDebug() << "Initializing a backup helper"; |
1271 | helper_.reset(new BackupHelper(DEKKO_APP_ID), [](Helper *h){h->deleteLater();}); |
1272 | qDebug() << "Helper " << static_cast<void*>(helper_.data()) << " was created"; |
1273 | - QObject::connect(helper_.data(), &Helper::error, [this](keeper::KeeperError error){ error_ = error;}); |
1274 | + QObject::connect(helper_.data(), &Helper::error, [this](keeper::Error error){ error_ = error;}); |
1275 | } |
1276 | |
1277 | void ask_for_uploader(quint64 n_bytes, QString const & dir_name) |
1278 | @@ -65,14 +65,20 @@ |
1279 | storage_->get_new_uploader(n_bytes, dir_name, file_name), |
1280 | std::function<void(std::shared_ptr<Uploader> const&)>{ |
1281 | [this](std::shared_ptr<Uploader> const& uploader){ |
1282 | - int fd {-1}; |
1283 | + auto fd {-1}; |
1284 | if (uploader) { |
1285 | auto backup_helper = qSharedPointerDynamicCast<BackupHelper>(helper_); |
1286 | backup_helper->set_uploader(uploader); |
1287 | fd = backup_helper->get_helper_socket(); |
1288 | - } |
1289 | - qDebug("emitting task_socket_ready(socket=%d)", fd); |
1290 | - Q_EMIT(q_ptr->task_socket_ready(fd)); |
1291 | + qDebug("emitting task_socket_ready(socket=%d)", fd); |
1292 | + Q_EMIT(q_ptr->task_socket_ready(fd)); |
1293 | + } |
1294 | + else |
1295 | + { |
1296 | + error_ = storage_->get_last_error(); |
1297 | + qDebug("Emitting task_socket_error(error=%d)", static_cast<int>(error_)); |
1298 | + Q_EMIT(q_ptr->task_socket_error(error_)); |
1299 | + } |
1300 | } |
1301 | } |
1302 | ); |
1303 | |
1304 | === modified file 'src/service/keeper-task-restore.cpp' |
1305 | --- src/service/keeper-task-restore.cpp 2016-12-15 14:30:42 +0000 |
1306 | +++ src/service/keeper-task-restore.cpp 2016-12-22 14:35:27 +0000 |
1307 | @@ -78,13 +78,19 @@ |
1308 | storage_->get_new_downloader(dir_name, file_name), |
1309 | std::function<void(std::shared_ptr<Downloader> const&)>{ |
1310 | [this](std::shared_ptr<Downloader> const& downloader){ |
1311 | - int fd {-1}; |
1312 | + auto fd {-1}; |
1313 | if (downloader) { |
1314 | auto restore_helper = qSharedPointerDynamicCast<RestoreHelper>(helper_); |
1315 | restore_helper->set_downloader(downloader); |
1316 | fd = restore_helper->get_helper_socket(); |
1317 | - } |
1318 | - Q_EMIT(q_ptr->task_socket_ready(fd)); |
1319 | + Q_EMIT(q_ptr->task_socket_ready(fd)); |
1320 | + } |
1321 | + else |
1322 | + { |
1323 | + error_ = storage_->get_last_error(); |
1324 | + qDebug("Emitting task_socket_error(error=%d)", static_cast<int>(error_)); |
1325 | + Q_EMIT(q_ptr->task_socket_error(error_)); |
1326 | + } |
1327 | } |
1328 | } |
1329 | ); |
1330 | |
1331 | === modified file 'src/service/keeper-task.cpp' |
1332 | --- src/service/keeper-task.cpp 2016-12-15 14:30:42 +0000 |
1333 | +++ src/service/keeper-task.cpp 2016-12-22 14:35:27 +0000 |
1334 | @@ -35,7 +35,7 @@ |
1335 | , task_data_(task_data) |
1336 | , helper_registry_(helper_registry) |
1337 | , storage_(storage) |
1338 | - , error_(keeper::KeeperError::OK) |
1339 | + , error_(keeper::Error::OK) |
1340 | { |
1341 | } |
1342 | |
1343 | @@ -50,7 +50,7 @@ |
1344 | if (urls.isEmpty()) |
1345 | { |
1346 | task_data_.action = helper_->to_string(Helper::State::FAILED); |
1347 | - error_ = keeper::KeeperError::HELPER_BAD_URL; |
1348 | + error_ = keeper::Error::HELPER_BAD_URL; |
1349 | qWarning() << QStringLiteral("Error: uuid %1 has no url").arg(task_data_.metadata.uuid()); |
1350 | calculate_and_notify_state(Helper::State::FAILED); |
1351 | return false; |
1352 | @@ -66,7 +66,7 @@ |
1353 | std::bind(&KeeperTaskPrivate::on_helper_percent_done_changed, this, std::placeholders::_1) |
1354 | ); |
1355 | |
1356 | - QObject::connect(helper_.data(), &Helper::error, [this](keeper::KeeperError error){ |
1357 | + QObject::connect(helper_.data(), &Helper::error, [this](keeper::Error error){ |
1358 | error_ = error; |
1359 | }); |
1360 | |
1361 | @@ -140,7 +140,7 @@ |
1362 | if (task_data_.action == "failed" || task_data_.action == "cancelled") |
1363 | { |
1364 | auto error = error_; |
1365 | - if (task_data_.error != keeper::KeeperError::OK) |
1366 | + if (task_data_.error != keeper::Error::OK) |
1367 | { |
1368 | error = task_data_.error; |
1369 | } |
1370 | @@ -205,7 +205,7 @@ |
1371 | } |
1372 | } |
1373 | |
1374 | -keeper::KeeperError KeeperTaskPrivate::error() const |
1375 | +keeper::Error KeeperTaskPrivate::error() const |
1376 | { |
1377 | return error_; |
1378 | } |
1379 | @@ -269,7 +269,7 @@ |
1380 | return d->to_string(state); |
1381 | } |
1382 | |
1383 | -keeper::KeeperError KeeperTask::error() const |
1384 | +keeper::Error KeeperTask::error() const |
1385 | { |
1386 | Q_D(const KeeperTask); |
1387 | |
1388 | |
1389 | === modified file 'src/service/keeper-task.h' |
1390 | --- src/service/keeper-task.h 2016-12-14 13:10:00 +0000 |
1391 | +++ src/service/keeper-task.h 2016-12-22 14:35:27 +0000 |
1392 | @@ -41,7 +41,7 @@ |
1393 | struct TaskData |
1394 | { |
1395 | QString action; |
1396 | - keeper::KeeperError error; |
1397 | + keeper::Error error; |
1398 | Metadata metadata; |
1399 | }; |
1400 | |
1401 | @@ -63,10 +63,11 @@ |
1402 | |
1403 | QString to_string(Helper::State state); |
1404 | |
1405 | - keeper::KeeperError error() const; |
1406 | + keeper::Error error() const; |
1407 | Q_SIGNALS: |
1408 | void task_state_changed(Helper::State state); |
1409 | void task_socket_ready(int socket_descriptor); |
1410 | + void task_socket_error(keeper::Error error); |
1411 | |
1412 | protected: |
1413 | KeeperTask(KeeperTaskPrivate & d, QObject *parent = nullptr); |
1414 | |
1415 | === modified file 'src/service/keeper-user.cpp' |
1416 | --- src/service/keeper-user.cpp 2016-11-22 09:37:40 +0000 |
1417 | +++ src/service/keeper-user.cpp 2016-12-22 14:35:27 +0000 |
1418 | @@ -33,7 +33,7 @@ |
1419 | |
1420 | KeeperUser::~KeeperUser() =default; |
1421 | |
1422 | -QVariantDictMap |
1423 | +keeper::KeeperItemsMap |
1424 | KeeperUser::GetBackupChoices() |
1425 | { |
1426 | auto bus = connection(); |
1427 | @@ -57,7 +57,7 @@ |
1428 | keeper_.cancel(); |
1429 | } |
1430 | |
1431 | -QVariantDictMap |
1432 | +keeper::KeeperItemsMap |
1433 | KeeperUser::GetRestoreChoices() |
1434 | { |
1435 | Q_ASSERT(calledFromDBus()); |
1436 | @@ -81,7 +81,7 @@ |
1437 | keeper_.start_tasks(keys, bus, msg); |
1438 | } |
1439 | |
1440 | -QVariantDictMap |
1441 | +keeper::KeeperItemsMap |
1442 | KeeperUser::get_state() const |
1443 | { |
1444 | return keeper_.get_state(); |
1445 | |
1446 | === modified file 'src/service/keeper-user.h' |
1447 | --- src/service/keeper-user.h 2016-09-05 18:38:36 +0000 |
1448 | +++ src/service/keeper-user.h 2016-12-22 14:35:27 +0000 |
1449 | @@ -37,11 +37,11 @@ |
1450 | virtual ~KeeperUser(); |
1451 | Q_DISABLE_COPY(KeeperUser) |
1452 | |
1453 | - Q_PROPERTY(QVariantDictMap State |
1454 | + Q_PROPERTY(keeper::KeeperItemsMap State |
1455 | READ get_state |
1456 | NOTIFY state_changed) |
1457 | |
1458 | - QVariantDictMap get_state() const; |
1459 | + keeper::KeeperItemsMap get_state() const; |
1460 | |
1461 | Q_SIGNALS: |
1462 | |
1463 | @@ -49,10 +49,10 @@ |
1464 | |
1465 | public Q_SLOTS: |
1466 | |
1467 | - QVariantDictMap GetBackupChoices(); |
1468 | + keeper::KeeperItemsMap GetBackupChoices(); |
1469 | void StartBackup(const QStringList&); |
1470 | |
1471 | - QVariantDictMap GetRestoreChoices(); |
1472 | + keeper::KeeperItemsMap GetRestoreChoices(); |
1473 | void StartRestore(const QStringList&); |
1474 | |
1475 | void Cancel(); |
1476 | |
1477 | === modified file 'src/service/keeper.cpp' |
1478 | --- src/service/keeper.cpp 2016-12-01 14:18:57 +0000 |
1479 | +++ src/service/keeper.cpp 2016-12-22 14:35:27 +0000 |
1480 | @@ -46,12 +46,15 @@ |
1481 | return variants; |
1482 | } |
1483 | |
1484 | - QVariantDictMap choices_to_variant_dict_map(const QVector<Metadata>& choices) |
1485 | + keeper::KeeperItemsMap choices_to_variant_dict_map(const QVector<Metadata>& choices) |
1486 | { |
1487 | - QVariantDictMap ret; |
1488 | + keeper::KeeperItemsMap ret; |
1489 | |
1490 | for (auto const& metadata : choices) |
1491 | - ret.insert(metadata.uuid(), strings_to_variants(metadata.get_public_properties())); |
1492 | + { |
1493 | + keeper::KeeperItem value(strings_to_variants(metadata.get_public_properties())); |
1494 | + ret.insert(metadata.uuid(), value); |
1495 | + } |
1496 | |
1497 | return ret; |
1498 | } |
1499 | @@ -113,11 +116,7 @@ |
1500 | if (task_manager_.start_backup(tasks.values())) |
1501 | unhandled.subtract(QSet<QString>::fromList(tasks.keys())); |
1502 | |
1503 | - check_for_unhandled_tasks(unhandled, bus, msg); |
1504 | - |
1505 | - // reply now to the dbus call |
1506 | - auto reply = msg.createReply(); |
1507 | - bus.send(reply); |
1508 | + check_for_unhandled_tasks_and_reply(unhandled, bus, msg); |
1509 | } |
1510 | else // restore |
1511 | { |
1512 | @@ -125,19 +124,17 @@ |
1513 | connections_.connect_oneshot( |
1514 | this, |
1515 | &KeeperPrivate::restore_choices_ready, |
1516 | - std::function<void()>{[this, uuids, msg, bus, get_tasks](){ |
1517 | + std::function<void(keeper::Error)>{[this, uuids, msg, bus, get_tasks](keeper::Error error){ |
1518 | qDebug() << "Choices ready"; |
1519 | auto unhandled = QSet<QString>::fromList(uuids); |
1520 | - auto restore_tasks = get_tasks(cached_restore_choices_, uuids); |
1521 | - qDebug() << "After getting tasks..."; |
1522 | - if (!restore_tasks.empty() && task_manager_.start_restore(restore_tasks.values())) |
1523 | - unhandled.subtract(QSet<QString>::fromList(restore_tasks.keys())); |
1524 | - |
1525 | - check_for_unhandled_tasks(unhandled, bus, msg); |
1526 | - |
1527 | - // reply now to the dbus call |
1528 | - auto reply = msg.createReply(); |
1529 | - bus.send(reply); |
1530 | + if (error == keeper::Error::OK) |
1531 | + { |
1532 | + auto restore_tasks = get_tasks(cached_restore_choices_, uuids); |
1533 | + qDebug() << "After getting tasks..."; |
1534 | + if (!restore_tasks.empty() && task_manager_.start_restore(restore_tasks.values())) |
1535 | + unhandled.subtract(QSet<QString>::fromList(restore_tasks.keys())); |
1536 | + } |
1537 | + check_for_unhandled_tasks_and_reply(unhandled, bus, msg); |
1538 | }} |
1539 | ); |
1540 | get_choices(restore_choices_, KeeperPrivate::ChoicesType::RESTORES_CHOICES); |
1541 | @@ -149,18 +146,19 @@ |
1542 | msg.setDelayedReply(true); |
1543 | } |
1544 | |
1545 | - void emit_choices_ready(ChoicesType type) |
1546 | + void emit_choices_ready(ChoicesType type, keeper::Error error) |
1547 | { |
1548 | switch(type) |
1549 | { |
1550 | case KeeperPrivate::ChoicesType::BACKUP_CHOICES: |
1551 | - Q_EMIT(backup_choices_ready()); |
1552 | + Q_EMIT(backup_choices_ready(error)); |
1553 | break; |
1554 | case KeeperPrivate::ChoicesType::RESTORES_CHOICES: |
1555 | - Q_EMIT(restore_choices_ready()); |
1556 | + Q_EMIT(restore_choices_ready(error)); |
1557 | break; |
1558 | } |
1559 | } |
1560 | + |
1561 | void get_choices(const QSharedPointer<MetadataProvider> & provider, ChoicesType type) |
1562 | { |
1563 | bool check_empty = (type == KeeperPrivate::ChoicesType::BACKUP_CHOICES) |
1564 | @@ -170,71 +168,94 @@ |
1565 | connections_.connect_oneshot( |
1566 | provider.data(), |
1567 | &MetadataProvider::finished, |
1568 | - std::function<void()>{[this, provider, type](){ |
1569 | + std::function<void(keeper::Error)>{[this, provider, type](keeper::Error error){ |
1570 | qDebug() << "Get choices finished"; |
1571 | - switch (type) |
1572 | + if (error == keeper::Error::OK) |
1573 | { |
1574 | - case KeeperPrivate::ChoicesType::BACKUP_CHOICES: |
1575 | - cached_backup_choices_ = provider->get_backups(); |
1576 | - break; |
1577 | - case KeeperPrivate::ChoicesType::RESTORES_CHOICES: |
1578 | - cached_restore_choices_ = provider->get_backups(); |
1579 | - break; |
1580 | - }; |
1581 | - emit_choices_ready(type); |
1582 | + switch (type) |
1583 | + { |
1584 | + case KeeperPrivate::ChoicesType::BACKUP_CHOICES: |
1585 | + cached_backup_choices_ = provider->get_backups(); |
1586 | + break; |
1587 | + case KeeperPrivate::ChoicesType::RESTORES_CHOICES: |
1588 | + cached_restore_choices_ = provider->get_backups(); |
1589 | + break; |
1590 | + } |
1591 | + } |
1592 | + emit_choices_ready(type, error); |
1593 | }} |
1594 | ); |
1595 | - |
1596 | provider->get_backups_async(); |
1597 | } |
1598 | else |
1599 | { |
1600 | - emit_choices_ready(type); |
1601 | + emit_choices_ready(type, keeper::Error::OK); |
1602 | } |
1603 | } |
1604 | |
1605 | - QVariantDictMap get_backup_choices_var_dict_map(QDBusConnection bus, |
1606 | + keeper::KeeperItemsMap get_backup_choices_var_dict_map(QDBusConnection bus, |
1607 | QDBusMessage const & msg) |
1608 | { |
1609 | connections_.connect_oneshot( |
1610 | this, |
1611 | &KeeperPrivate::backup_choices_ready, |
1612 | - std::function<void()>{[this, msg, bus](){ |
1613 | + std::function<void(keeper::Error)>{[this, msg, bus](keeper::Error error){ |
1614 | qDebug() << "Backup choices are ready"; |
1615 | - // reply now to the dbus call |
1616 | - auto reply = msg.createReply(); |
1617 | - reply << QVariant::fromValue(choices_to_variant_dict_map(cached_backup_choices_)); |
1618 | - bus.send(reply); |
1619 | + if (error == keeper::Error::OK) |
1620 | + { |
1621 | + // reply now to the dbus call |
1622 | + auto reply = msg.createReply(); |
1623 | + reply << QVariant::fromValue(choices_to_variant_dict_map(cached_backup_choices_)); |
1624 | + bus.send(reply); |
1625 | + } |
1626 | + else |
1627 | + { |
1628 | + auto message = QStringLiteral("Error obtaining backup choices, keeper returned error: %1").arg(static_cast<int>(error)); |
1629 | + qWarning() << message; |
1630 | + auto reply = msg.createErrorReply(QDBusError::Failed, message); |
1631 | + reply << QVariant::fromValue(error); |
1632 | + bus.send(reply); |
1633 | + } |
1634 | }} |
1635 | ); |
1636 | - |
1637 | get_choices(backup_choices_, KeeperPrivate::ChoicesType::BACKUP_CHOICES); |
1638 | msg.setDelayedReply(true); |
1639 | - return QVariantDictMap(); |
1640 | + return keeper::KeeperItemsMap(); |
1641 | } |
1642 | |
1643 | - QVariantDictMap get_restore_choices_var_dict_map(QDBusConnection bus, |
1644 | + keeper::KeeperItemsMap get_restore_choices_var_dict_map(QDBusConnection bus, |
1645 | QDBusMessage const & msg) |
1646 | { |
1647 | + qDebug() << "Getting restores --------------------------------"; |
1648 | cached_restore_choices_.clear(); |
1649 | connections_.connect_oneshot( |
1650 | this, |
1651 | &KeeperPrivate::restore_choices_ready, |
1652 | - std::function<void()>{[this, msg, bus](){ |
1653 | + std::function<void(keeper::Error)>{[this, msg, bus](keeper::Error error){ |
1654 | qDebug() << "Restore choices are ready"; |
1655 | - // reply now to the dbus call |
1656 | - auto reply = msg.createReply(); |
1657 | - reply << QVariant::fromValue(choices_to_variant_dict_map(cached_restore_choices_)); |
1658 | - bus.send(reply); |
1659 | + if (error == keeper::Error::OK) |
1660 | + { |
1661 | + // reply now to the dbus call |
1662 | + auto reply = msg.createReply(); |
1663 | + reply << QVariant::fromValue(choices_to_variant_dict_map(cached_restore_choices_)); |
1664 | + bus.send(reply); |
1665 | + } |
1666 | + else |
1667 | + { |
1668 | + auto message = QStringLiteral("Error obtaining restore choices, keeper returned error: %1").arg(static_cast<int>(error)); |
1669 | + qWarning() << message; |
1670 | + auto reply = msg.createErrorReply(QDBusError::Failed, message); |
1671 | + reply << QVariant::fromValue(error); |
1672 | + bus.send(reply); |
1673 | + } |
1674 | }} |
1675 | ); |
1676 | - |
1677 | get_choices(restore_choices_, KeeperPrivate::ChoicesType::RESTORES_CHOICES); |
1678 | msg.setDelayedReply(true); |
1679 | - return QVariantDictMap(); |
1680 | + return keeper::KeeperItemsMap(); |
1681 | } |
1682 | |
1683 | - QVariantDictMap get_state() const |
1684 | + keeper::KeeperItemsMap get_state() const |
1685 | { |
1686 | return task_manager_.get_state(); |
1687 | } |
1688 | @@ -258,6 +279,17 @@ |
1689 | } |
1690 | ); |
1691 | |
1692 | + connections_.connect_oneshot( |
1693 | + &task_manager_, |
1694 | + &TaskManager::socket_error, |
1695 | + std::function<void(keeper::Error)>{ |
1696 | + [bus,msg](keeper::Error error){ |
1697 | + qDebug("BackupManager returned socket error: %d", static_cast<int>(error)); |
1698 | + bus.send(msg.createErrorReply(QDBusError::InvalidArgs, "Error obtaining remote backup socket")); |
1699 | + } |
1700 | + } |
1701 | + ); |
1702 | + |
1703 | qDebug() << "Asking for a storage framework socket from the task manager"; |
1704 | task_manager_.ask_for_uploader(n_bytes); |
1705 | |
1706 | @@ -286,6 +318,17 @@ |
1707 | } |
1708 | ); |
1709 | |
1710 | + connections_.connect_oneshot( |
1711 | + &task_manager_, |
1712 | + &TaskManager::socket_error, |
1713 | + std::function<void(keeper::Error)>{ |
1714 | + [bus,msg](keeper::Error error){ |
1715 | + qDebug("RestoreManager returned socket error: %d", static_cast<int>(error)); |
1716 | + bus.send(msg.createErrorReply(QDBusError::InvalidArgs, "Error obtaining remote restore socket")); |
1717 | + } |
1718 | + } |
1719 | + ); |
1720 | + |
1721 | qDebug() << "Asking for a storage framework socket from the task manager"; |
1722 | task_manager_.ask_for_downloader(); |
1723 | |
1724 | @@ -305,11 +348,10 @@ |
1725 | } |
1726 | |
1727 | Q_SIGNALS: |
1728 | - void backup_choices_ready(); |
1729 | - void restore_choices_ready(); |
1730 | + void backup_choices_ready(keeper::Error error); |
1731 | + void restore_choices_ready(keeper::Error error); |
1732 | |
1733 | private: |
1734 | - |
1735 | void on_task_manager_finished() |
1736 | { |
1737 | // force a backup choices regeneration to avoid repeating uuids |
1738 | @@ -317,7 +359,7 @@ |
1739 | invalidate_choices_cache(); |
1740 | } |
1741 | |
1742 | - void check_for_unhandled_tasks(QSet<QString> const & unhandled, |
1743 | + void check_for_unhandled_tasks_and_reply(QSet<QString> const & unhandled, |
1744 | QDBusConnection bus, |
1745 | QDBusMessage const & msg ) |
1746 | { |
1747 | @@ -329,6 +371,9 @@ |
1748 | text += ' ' + uuid; |
1749 | bus.send(msg.createErrorReply(QDBusError::InvalidArgs, text)); |
1750 | } |
1751 | + |
1752 | + auto reply = msg.createReply(); |
1753 | + bus.send(reply); |
1754 | } |
1755 | |
1756 | Keeper * const q_ptr; |
1757 | @@ -383,7 +428,7 @@ |
1758 | return d->start_restore(bus, msg); |
1759 | } |
1760 | |
1761 | -QVariantDictMap |
1762 | +keeper::KeeperItemsMap |
1763 | Keeper::get_backup_choices_var_dict_map(QDBusConnection bus, |
1764 | QDBusMessage const & msg) |
1765 | { |
1766 | @@ -392,7 +437,7 @@ |
1767 | return d->get_backup_choices_var_dict_map(bus, msg); |
1768 | } |
1769 | |
1770 | -QVariantDictMap |
1771 | +keeper::KeeperItemsMap |
1772 | Keeper::get_restore_choices(QDBusConnection bus, |
1773 | QDBusMessage const & msg) |
1774 | { |
1775 | @@ -401,7 +446,7 @@ |
1776 | return d->get_restore_choices_var_dict_map(bus,msg); |
1777 | } |
1778 | |
1779 | -QVariantDictMap |
1780 | +keeper::KeeperItemsMap |
1781 | Keeper::get_state() const |
1782 | { |
1783 | Q_D(const Keeper); |
1784 | |
1785 | === modified file 'src/service/keeper.h' |
1786 | --- src/service/keeper.h 2016-11-22 09:37:40 +0000 |
1787 | +++ src/service/keeper.h 2016-12-22 14:35:27 +0000 |
1788 | @@ -52,8 +52,8 @@ |
1789 | |
1790 | virtual ~Keeper(); |
1791 | |
1792 | - QVariantDictMap get_backup_choices_var_dict_map(QDBusConnection bus, QDBusMessage const & msg); |
1793 | - QVariantDictMap get_restore_choices(QDBusConnection bus, QDBusMessage const & msg); |
1794 | + keeper::KeeperItemsMap get_backup_choices_var_dict_map(QDBusConnection bus, QDBusMessage const & msg); |
1795 | + keeper::KeeperItemsMap get_restore_choices(QDBusConnection bus, QDBusMessage const & msg); |
1796 | |
1797 | QDBusUnixFileDescriptor StartBackup(QDBusConnection, |
1798 | QDBusMessage const & message, |
1799 | @@ -67,7 +67,7 @@ |
1800 | QDBusConnection bus, |
1801 | QDBusMessage const & msg); |
1802 | |
1803 | - QVariantDictMap get_state() const; |
1804 | + keeper::KeeperItemsMap get_state() const; |
1805 | |
1806 | void cancel(); |
1807 | |
1808 | |
1809 | === modified file 'src/service/metadata-provider.h' |
1810 | --- src/service/metadata-provider.h 2016-10-28 15:11:21 +0000 |
1811 | +++ src/service/metadata-provider.h 2016-12-22 14:35:27 +0000 |
1812 | @@ -19,6 +19,7 @@ |
1813 | |
1814 | #pragma once |
1815 | |
1816 | +#include "client/keeper-errors.h" |
1817 | #include "helper/metadata.h" |
1818 | |
1819 | #include <QObject> |
1820 | @@ -33,7 +34,7 @@ |
1821 | virtual void get_backups_async() =0; |
1822 | |
1823 | Q_SIGNALS: |
1824 | - void finished(); |
1825 | + void finished(keeper::Error error); |
1826 | |
1827 | protected: |
1828 | explicit MetadataProvider(QObject *parent = nullptr) : QObject(parent){}; |
1829 | |
1830 | === modified file 'src/service/private/keeper-task_p.h' |
1831 | --- src/service/private/keeper-task_p.h 2016-12-14 11:00:21 +0000 |
1832 | +++ src/service/private/keeper-task_p.h 2016-12-22 14:35:27 +0000 |
1833 | @@ -42,7 +42,7 @@ |
1834 | |
1835 | QString to_string(Helper::State state); |
1836 | |
1837 | - keeper::KeeperError error() const; |
1838 | + keeper::Error error() const; |
1839 | |
1840 | protected: |
1841 | void set_current_task_action(QString const& action); |
1842 | @@ -60,5 +60,5 @@ |
1843 | QSharedPointer<StorageFrameworkClient> storage_; |
1844 | QSharedPointer<Helper> helper_; |
1845 | QVariantMap state_; |
1846 | - keeper::KeeperError error_; |
1847 | + keeper::Error error_; |
1848 | }; |
1849 | |
1850 | === modified file 'src/service/restore-choices.cpp' |
1851 | --- src/service/restore-choices.cpp 2016-12-15 14:30:42 +0000 |
1852 | +++ src/service/restore-choices.cpp 2016-12-22 14:35:27 +0000 |
1853 | @@ -67,7 +67,7 @@ |
1854 | manifests_to_read_--; |
1855 | if (!manifests_to_read_) |
1856 | { |
1857 | - Q_EMIT(finished()); |
1858 | + Q_EMIT(finished(keeper::Error::OK)); |
1859 | } |
1860 | }} |
1861 | ); |
1862 | @@ -76,8 +76,8 @@ |
1863 | } |
1864 | else |
1865 | { |
1866 | - qWarning() << "We could not find and keeper backup when retrieving restore options."; |
1867 | - Q_EMIT(finished()); |
1868 | + qWarning() << "We could not find and keeper backups directory when retrieving restore options."; |
1869 | + Q_EMIT(finished(storage_->get_last_error())); |
1870 | } |
1871 | } |
1872 | } |
1873 | |
1874 | === modified file 'src/service/task-manager.cpp' |
1875 | --- src/service/task-manager.cpp 2016-12-14 11:00:21 +0000 |
1876 | +++ src/service/task-manager.cpp 2016-12-22 14:35:27 +0000 |
1877 | @@ -59,9 +59,21 @@ |
1878 | *** State public |
1879 | ***/ |
1880 | |
1881 | - QVariantDictMap get_state() const |
1882 | - { |
1883 | - return state_; |
1884 | + keeper::KeeperItemsMap get_converted_state_to_user_type() const |
1885 | + { |
1886 | + keeper::KeeperItemsMap ret; |
1887 | + for (auto iter = state_.begin(); iter != state_.end(); ++iter) |
1888 | + { |
1889 | + keeper::KeeperItem item((*iter)); |
1890 | + ret[iter.key()] = item; |
1891 | + } |
1892 | + return ret; |
1893 | + } |
1894 | + |
1895 | + keeper::KeeperItemsMap get_state() const |
1896 | + { |
1897 | + return get_converted_state_to_user_type(); |
1898 | +// return state_; |
1899 | } |
1900 | |
1901 | void ask_for_uploader(quint64 n_bytes) |
1902 | @@ -147,7 +159,7 @@ |
1903 | auto& td = task_data_[uuid]; |
1904 | td.metadata = metadata; |
1905 | td.action = QStringLiteral("queued"); // TODO i18n |
1906 | - td.error = keeper::KeeperError::OK; |
1907 | + td.error = keeper::Error::OK; |
1908 | set_initial_task_state(td); |
1909 | } |
1910 | |
1911 | @@ -170,7 +182,7 @@ |
1912 | } |
1913 | else |
1914 | { |
1915 | - td.error = keeper::KeeperError::MANIFEST_STORAGE_ERROR; |
1916 | + td.error = keeper::Error::MANIFEST_STORAGE; |
1917 | set_current_task_action(task_->to_string(Helper::State::FAILED)); |
1918 | } |
1919 | active_manifest_.reset(); |
1920 | @@ -266,9 +278,25 @@ |
1921 | std::bind(&TaskManager::socket_ready, q_ptr, std::placeholders::_1) |
1922 | ); |
1923 | |
1924 | + QObject::connect(task_.data(), &KeeperTask::task_socket_error, |
1925 | + std::bind(&TaskManagerPrivate::on_task_socket_error, this, std::placeholders::_1) |
1926 | + ); |
1927 | + |
1928 | return task_->start(); |
1929 | } |
1930 | |
1931 | + void on_task_socket_error(keeper::Error error) |
1932 | + { |
1933 | + if (!task_) |
1934 | + { |
1935 | + qWarning() << "Error updating current task state"; |
1936 | + } |
1937 | + auto& td = task_data_[current_task_]; |
1938 | + td.error = error; |
1939 | + set_current_task_action(task_->to_string(Helper::State::FAILED)); |
1940 | + Q_EMIT(q_ptr->socket_error(error)); |
1941 | + } |
1942 | + |
1943 | void set_current_task(QString const& uuid) |
1944 | { |
1945 | auto const prev = current_task_; |
1946 | @@ -409,7 +437,7 @@ |
1947 | return d->start_restore(tasks); |
1948 | } |
1949 | |
1950 | -QVariantDictMap TaskManager::get_state() const |
1951 | +keeper::KeeperItemsMap TaskManager::get_state() const |
1952 | { |
1953 | Q_D(const TaskManager); |
1954 | |
1955 | |
1956 | === modified file 'src/service/task-manager.h' |
1957 | --- src/service/task-manager.h 2016-12-01 14:18:57 +0000 |
1958 | +++ src/service/task-manager.h 2016-12-22 14:35:27 +0000 |
1959 | @@ -45,7 +45,7 @@ |
1960 | |
1961 | Q_DISABLE_COPY(TaskManager) |
1962 | |
1963 | - Q_PROPERTY(QVariantDictMap State |
1964 | + Q_PROPERTY(keeper::KeeperItemsMap State |
1965 | READ get_state |
1966 | NOTIFY state_changed) |
1967 | |
1968 | @@ -54,7 +54,7 @@ |
1969 | |
1970 | bool start_restore(QList<Metadata> const& tasks); |
1971 | |
1972 | - QVariantDictMap get_state() const; |
1973 | + keeper::KeeperItemsMap get_state() const; |
1974 | |
1975 | void ask_for_uploader(quint64 n_bytes); |
1976 | |
1977 | @@ -64,6 +64,7 @@ |
1978 | |
1979 | Q_SIGNALS: |
1980 | void socket_ready(int reply); |
1981 | + void socket_error(keeper::Error error); |
1982 | void state_changed(); |
1983 | void finished(); |
1984 | |
1985 | |
1986 | === modified file 'src/storage-framework/storage_framework_client.cpp' |
1987 | --- src/storage-framework/storage_framework_client.cpp 2016-12-15 14:30:42 +0000 |
1988 | +++ src/storage-framework/storage_framework_client.cpp 2016-12-22 14:35:27 +0000 |
1989 | @@ -55,6 +55,7 @@ |
1990 | if (choices.empty()) |
1991 | { |
1992 | qWarning() << "no storage-framework accounts to pick from"; |
1993 | + last_error_ = keeper::Error::NO_REMOTE_ACCOUNTS; |
1994 | } |
1995 | else // for now just pick the first one. FIXME |
1996 | { |
1997 | @@ -73,6 +74,7 @@ |
1998 | if (choices.empty()) |
1999 | { |
2000 | qWarning() << "no storage-framework roots to pick from"; |
2001 | + last_error_ = keeper::Error::NO_REMOTE_ROOTS; |
2002 | } |
2003 | else // for now just pick the first one. FIXME |
2004 | { |
2005 | @@ -106,6 +108,8 @@ |
2006 | QFuture<std::shared_ptr<Uploader>> |
2007 | StorageFrameworkClient::get_new_uploader(int64_t n_bytes, QString const & dir_name, QString const & file_name) |
2008 | { |
2009 | + clear_last_error(); |
2010 | + |
2011 | QFutureInterface<std::shared_ptr<Uploader>> fi; |
2012 | |
2013 | add_roots_task([this, fi, n_bytes, dir_name, file_name](QVector<sf::Root::SPtr> const& roots) |
2014 | @@ -133,12 +137,17 @@ |
2015 | [this, fi, keeper_folder](std::shared_ptr<sf::Uploader> const& sf_uploader){ |
2016 | qDebug() << "keeper_root->create_file() finished"; |
2017 | std::shared_ptr<Uploader> ret; |
2018 | - if (sf_uploader) { |
2019 | + if (sf_uploader) |
2020 | + { |
2021 | ret.reset( |
2022 | new StorageFrameworkUploader(sf_uploader, this), |
2023 | [](Uploader* u){u->deleteLater();} |
2024 | ); |
2025 | } |
2026 | + else |
2027 | + { |
2028 | + last_error_ = keeper::Error::CREATING_REMOTE_FILE; |
2029 | + } |
2030 | QFutureInterface<decltype(ret)> qfi(fi); |
2031 | qfi.reportResult(ret); |
2032 | qfi.reportFinished(); |
2033 | @@ -150,6 +159,13 @@ |
2034 | } |
2035 | ); |
2036 | } |
2037 | + else |
2038 | + { |
2039 | + std::shared_ptr<Uploader> ret; |
2040 | + QFutureInterface<decltype(ret)> qfi(fi); |
2041 | + qfi.reportResult(ret); |
2042 | + qfi.reportFinished(); |
2043 | + } |
2044 | }); |
2045 | |
2046 | return fi.future(); |
2047 | @@ -158,6 +174,8 @@ |
2048 | QFuture<std::shared_ptr<Downloader>> |
2049 | StorageFrameworkClient::get_new_downloader(QString const & dir_name, QString const & file_name) |
2050 | { |
2051 | + clear_last_error(); |
2052 | + |
2053 | QFutureInterface<std::shared_ptr<Downloader>> fi; |
2054 | |
2055 | add_roots_task([this, fi, dir_name, file_name](QVector<sf::Root::SPtr> const& roots) |
2056 | @@ -197,6 +215,10 @@ |
2057 | [](Downloader* d){d->deleteLater();} |
2058 | ); |
2059 | } |
2060 | + else |
2061 | + { |
2062 | + last_error_ = keeper::Error::READING_REMOTE_FILE; |
2063 | + } |
2064 | QFutureInterface<decltype(ret)> qfi(fi); |
2065 | qfi.reportResult(ret); |
2066 | qfi.reportFinished(); |
2067 | @@ -204,6 +226,7 @@ |
2068 | } |
2069 | ); |
2070 | } else { |
2071 | + last_error_ = keeper::Error::READING_REMOTE_FILE; |
2072 | std::shared_ptr<Downloader> ret_null; |
2073 | QFutureInterface<decltype(ret_null)> qfi(fi); |
2074 | qfi.reportResult(ret_null); |
2075 | @@ -217,6 +240,13 @@ |
2076 | } |
2077 | ); |
2078 | } |
2079 | + else |
2080 | + { |
2081 | + std::shared_ptr<Downloader> ret; |
2082 | + QFutureInterface<decltype(ret)> qfi(fi); |
2083 | + qfi.reportResult(ret); |
2084 | + qfi.reportFinished(); |
2085 | + } |
2086 | }); |
2087 | |
2088 | return fi.future(); |
2089 | @@ -225,6 +255,8 @@ |
2090 | QFuture<QVector<QString>> |
2091 | StorageFrameworkClient::get_keeper_dirs() |
2092 | { |
2093 | + clear_last_error(); |
2094 | + |
2095 | QFutureInterface<QVector<QString>> fi; |
2096 | |
2097 | add_roots_task([this, fi](QVector<sf::Root::SPtr> const& roots) |
2098 | @@ -262,10 +294,23 @@ |
2099 | } |
2100 | ); |
2101 | } |
2102 | + else |
2103 | + { |
2104 | + QVector<QString> res; |
2105 | + QFutureInterface<decltype(res)> qfi(fi); |
2106 | + qfi.reportResult(res); |
2107 | + qfi.reportFinished(); |
2108 | + } |
2109 | }); |
2110 | return fi.future(); |
2111 | } |
2112 | |
2113 | +keeper::Error |
2114 | +StorageFrameworkClient::get_last_error() const |
2115 | +{ |
2116 | + return last_error_; |
2117 | +} |
2118 | + |
2119 | QFuture<sf::Folder::SPtr> |
2120 | StorageFrameworkClient::get_keeper_folder(sf::Folder::SPtr const & root, QString const & dir_name, bool create_if_not_exists) |
2121 | { |
2122 | @@ -335,6 +380,7 @@ |
2123 | QFutureInterface<decltype(res)> qfi(fi); |
2124 | qfi.reportResult(res); |
2125 | qfi.reportFinished(); |
2126 | + last_error_ = keeper::Error::REMOTE_DIR_NOT_EXISTS; |
2127 | } |
2128 | else |
2129 | { |
2130 | @@ -343,6 +389,10 @@ |
2131 | root->create_folder(dir_name), |
2132 | std::function<void(sf::Folder::SPtr const &)>{ |
2133 | [this, fi, res, root](sf::Folder::SPtr const & folder){ |
2134 | + if (!folder) |
2135 | + { |
2136 | + last_error_ = keeper::Error::CREATING_REMOTE_DIR; |
2137 | + } |
2138 | QFutureInterface<decltype(res)> qfi(fi); |
2139 | qfi.reportResult(folder); |
2140 | qfi.reportFinished(); |
2141 | @@ -421,3 +471,9 @@ |
2142 | |
2143 | return fi.future(); |
2144 | } |
2145 | + |
2146 | +void |
2147 | +StorageFrameworkClient::clear_last_error() |
2148 | +{ |
2149 | + last_error_ = keeper::Error::OK; |
2150 | +} |
2151 | |
2152 | === modified file 'src/storage-framework/storage_framework_client.h' |
2153 | --- src/storage-framework/storage_framework_client.h 2016-11-11 14:50:06 +0000 |
2154 | +++ src/storage-framework/storage_framework_client.h 2016-12-22 14:35:27 +0000 |
2155 | @@ -20,6 +20,7 @@ |
2156 | |
2157 | #pragma once |
2158 | |
2159 | +#include "client/keeper-errors.h" |
2160 | #include "util/connection-helper.h" |
2161 | #include "storage-framework/uploader.h" |
2162 | #include "storage-framework/downloader.h" |
2163 | @@ -46,6 +47,7 @@ |
2164 | QFuture<std::shared_ptr<Uploader>> get_new_uploader(int64_t n_bytes, QString const & dir_name, QString const & file_name); |
2165 | QFuture<std::shared_ptr<Downloader>> get_new_downloader(QString const & dir_name, QString const & file_name); |
2166 | QFuture<QVector<QString>> get_keeper_dirs(); |
2167 | + keeper::Error get_last_error() const; |
2168 | |
2169 | static QString const KEEPER_FOLDER; |
2170 | private: |
2171 | @@ -61,6 +63,9 @@ |
2172 | QFuture<unity::storage::qt::client::File::SPtr> get_storage_framework_file(unity::storage::qt::client::Folder::SPtr const & root, QString const & file_name); |
2173 | QFuture<QVector<QString>> get_storage_framework_dirs(unity::storage::qt::client::Folder::SPtr const & root); |
2174 | |
2175 | + void clear_last_error(); |
2176 | + |
2177 | unity::storage::qt::client::Runtime::SPtr runtime_; |
2178 | ConnectionHelper connection_helper_; |
2179 | + mutable keeper::Error last_error_ = keeper::Error::OK; |
2180 | }; |
2181 | |
2182 | === modified file 'tests/dbusmock/keeper-template-test.cpp' |
2183 | --- tests/dbusmock/keeper-template-test.cpp 2016-08-01 19:34:24 +0000 |
2184 | +++ tests/dbusmock/keeper-template-test.cpp 2016-12-22 14:35:27 +0000 |
2185 | @@ -59,105 +59,114 @@ |
2186 | EXPECT_NE(QDBusMessage::ErrorMessage, msg.type()) << qPrintable(msg.errorMessage()); |
2187 | |
2188 | // ask for a list of backup choices |
2189 | - QDBusReply<QVariantDictMap> choices = user_iface_->call("GetBackupChoices"); |
2190 | - EXPECT_TRUE(choices.isValid()) << qPrintable(choices.error().message()); |
2191 | - |
2192 | - // check the results |
2193 | - const auto expected_choices = QVariantDictMap{{uuid, props}}; |
2194 | - ASSERT_EQ(expected_choices, choices); |
2195 | -} |
2196 | - |
2197 | - |
2198 | -// test that StartBackup() fails if we pass an invalid arg |
2199 | -TEST_F(KeeperTemplateTest, StartBackupWithInvalidArg) |
2200 | -{ |
2201 | - const auto invalid_uuid = QUuid::createUuid().toString(); |
2202 | - |
2203 | - QDBusReply<void> reply = user_iface_->call("StartBackup", QStringList{invalid_uuid}); |
2204 | - EXPECT_FALSE(reply.isValid()); |
2205 | - EXPECT_EQ(QDBusError::InvalidArgs, reply.error().type()); |
2206 | -} |
2207 | - |
2208 | - |
2209 | -// test GetRestoreChoices() returns what we give to AddRestoreChoice() |
2210 | -TEST_F(KeeperTemplateTest, RestoreChoices) |
2211 | -{ |
2212 | - // build a restore choice |
2213 | - const auto uuid = QUuid::createUuid().toString(); |
2214 | - const auto blob = QUuid::createUuid().toByteArray(); |
2215 | - const QMap<QString,QVariant> props { |
2216 | - { KEY_NAME, QStringLiteral("some-name") }, |
2217 | - { KEY_TYPE, QStringLiteral("some-type") }, |
2218 | - { KEY_SUBTYPE, QStringLiteral("some-subtype") }, |
2219 | - { KEY_HELPER, QString::fromUtf8("/dev/null") }, |
2220 | - { KEY_SIZE, quint64(blob.size()) }, |
2221 | - { KEY_CTIME, quint64(time(nullptr)) }, |
2222 | - { KEY_BLOB, blob } |
2223 | - }; |
2224 | - |
2225 | - // add it |
2226 | - auto msg = mock_iface_->call(QStringLiteral("AddRestoreChoice"), uuid, props); |
2227 | - EXPECT_NE(QDBusMessage::ErrorMessage, msg.type()) << qPrintable(msg.errorMessage()); |
2228 | - |
2229 | - // ask for a list of restore choices |
2230 | - QDBusReply<QVariantDictMap> choices = user_iface_->call("GetRestoreChoices"); |
2231 | - EXPECT_TRUE(choices.isValid()) << qPrintable(choices.error().message()); |
2232 | - |
2233 | - // check the results |
2234 | - const auto expected_choices = QVariantDictMap{{uuid, props}}; |
2235 | - ASSERT_EQ(expected_choices, choices); |
2236 | -} |
2237 | - |
2238 | - |
2239 | -// test that StartRestore() fails if we pass an invalid arg |
2240 | -TEST_F(KeeperTemplateTest, StartRestoreWithInvalidArg) |
2241 | -{ |
2242 | - const auto invalid_uuid = QUuid::createUuid().toString(); |
2243 | - |
2244 | - QDBusReply<void> reply = user_iface_->call("StartRestore", QStringList{invalid_uuid}); |
2245 | - EXPECT_FALSE(reply.isValid()); |
2246 | - EXPECT_EQ(QDBusError::InvalidArgs, reply.error().type()); |
2247 | -} |
2248 | - |
2249 | - |
2250 | -// test that Status() returns empty if we haven't done anything yet |
2251 | -TEST_F(KeeperTemplateTest, TestEmptyStatus) |
2252 | -{ |
2253 | - EXPECT_TRUE(user_iface_->state().isEmpty()); |
2254 | -} |
2255 | - |
2256 | - |
2257 | -/*** |
2258 | -**** Make a real backup |
2259 | -***/ |
2260 | - |
2261 | -TEST_F(KeeperTemplateTest, BackupRun) |
2262 | -{ |
2263 | - QTemporaryDir sandbox; |
2264 | - |
2265 | - // build a backup choice |
2266 | - const auto uuid = QUuid::createUuid().toString(); |
2267 | - const QMap<QString,QVariant> props { |
2268 | - { KEY_NAME, QStringLiteral("Music") }, |
2269 | - { KEY_TYPE, QStringLiteral("folder") }, |
2270 | - { KEY_SUBTYPE, sandbox.path() }, |
2271 | - { KEY_HELPER, QString::fromUtf8(FAKE_BACKUP_HELPER_EXEC) } |
2272 | - }; |
2273 | - |
2274 | - // add it |
2275 | - auto msg = mock_iface_->call(QStringLiteral("AddBackupChoice"), uuid, props); |
2276 | - EXPECT_NE(QDBusMessage::ErrorMessage, msg.type()) << qPrintable(msg.errorMessage()); |
2277 | - |
2278 | - // start the backup |
2279 | - QDBusReply<void> reply = user_iface_->call("StartBackup", QStringList{uuid}); |
2280 | - EXPECT_TRUE(reply.isValid()) << qPrintable(reply.error().message()); |
2281 | - ASSERT_TRUE(wait_for_tasks_to_finish()); |
2282 | - |
2283 | - // ask keeper for the blob |
2284 | - QDBusReply<QByteArray> blob = mock_iface_->call(QStringLiteral("GetBackupData"), uuid); |
2285 | - EXPECT_TRUE(reply.isValid()) << qPrintable(reply.error().message()); |
2286 | - |
2287 | - // check the results |
2288 | - const auto expected_blob = QByteArray(FAKE_BACKUP_HELPER_PAYLOAD); |
2289 | - ASSERT_EQ(expected_blob, blob); |
2290 | -} |
2291 | + QDBusPendingReply<keeper::KeeperItemsMap> choices_reply = user_iface_->call("GetBackupChoices"); |
2292 | + choices_reply.waitForFinished(); |
2293 | + if (!choices_reply.isValid()) |
2294 | + { |
2295 | + qDebug() << "-------------------" << choices_reply.error().message(); |
2296 | + } |
2297 | + EXPECT_TRUE(choices_reply.isValid()) << qPrintable(choices_reply.error().message()); |
2298 | + |
2299 | + auto choices = choices_reply.value(); |
2300 | + // check the results |
2301 | + const auto expected_choices = QVariantDictMap{{uuid, props}}; |
2302 | + auto iter = choices.find(uuid); |
2303 | + ASSERT_NE(iter, choices.end()); |
2304 | + |
2305 | + ASSERT_EQ((*iter), props); |
2306 | +} |
2307 | + |
2308 | + |
2309 | +//// test that StartBackup() fails if we pass an invalid arg |
2310 | +//TEST_F(KeeperTemplateTest, StartBackupWithInvalidArg) |
2311 | +//{ |
2312 | +// const auto invalid_uuid = QUuid::createUuid().toString(); |
2313 | +// |
2314 | +// QDBusReply<void> reply = user_iface_->call("StartBackup", QStringList{invalid_uuid}); |
2315 | +// EXPECT_FALSE(reply.isValid()); |
2316 | +// EXPECT_EQ(QDBusError::InvalidArgs, reply.error().type()); |
2317 | +//} |
2318 | +// |
2319 | +// |
2320 | +//// test GetRestoreChoices() returns what we give to AddRestoreChoice() |
2321 | +//TEST_F(KeeperTemplateTest, RestoreChoices) |
2322 | +//{ |
2323 | +// // build a restore choice |
2324 | +// const auto uuid = QUuid::createUuid().toString(); |
2325 | +// const auto blob = QUuid::createUuid().toByteArray(); |
2326 | +// const QMap<QString,QVariant> props { |
2327 | +// { KEY_NAME, QStringLiteral("some-name") }, |
2328 | +// { KEY_TYPE, QStringLiteral("some-type") }, |
2329 | +// { KEY_SUBTYPE, QStringLiteral("some-subtype") }, |
2330 | +// { KEY_HELPER, QString::fromUtf8("/dev/null") }, |
2331 | +// { KEY_SIZE, quint64(blob.size()) }, |
2332 | +// { KEY_CTIME, quint64(time(nullptr)) }, |
2333 | +// { KEY_BLOB, blob } |
2334 | +// }; |
2335 | +// |
2336 | +// // add it |
2337 | +// auto msg = mock_iface_->call(QStringLiteral("AddRestoreChoice"), uuid, props); |
2338 | +// EXPECT_NE(QDBusMessage::ErrorMessage, msg.type()) << qPrintable(msg.errorMessage()); |
2339 | +// |
2340 | +// // ask for a list of restore choices |
2341 | +// QDBusReply<QVariantDictMap> choices = user_iface_->call("GetRestoreChoices"); |
2342 | +// EXPECT_TRUE(choices.isValid()) << qPrintable(choices.error().message()); |
2343 | +// |
2344 | +// // check the results |
2345 | +// const auto expected_choices = QVariantDictMap{{uuid, props}}; |
2346 | +// ASSERT_EQ(expected_choices, choices); |
2347 | +//} |
2348 | +// |
2349 | +// |
2350 | +//// test that StartRestore() fails if we pass an invalid arg |
2351 | +//TEST_F(KeeperTemplateTest, StartRestoreWithInvalidArg) |
2352 | +//{ |
2353 | +// const auto invalid_uuid = QUuid::createUuid().toString(); |
2354 | +// |
2355 | +// QDBusReply<void> reply = user_iface_->call("StartRestore", QStringList{invalid_uuid}); |
2356 | +// EXPECT_FALSE(reply.isValid()); |
2357 | +// EXPECT_EQ(QDBusError::InvalidArgs, reply.error().type()); |
2358 | +//} |
2359 | +// |
2360 | +// |
2361 | +//// test that Status() returns empty if we haven't done anything yet |
2362 | +//TEST_F(KeeperTemplateTest, TestEmptyStatus) |
2363 | +//{ |
2364 | +// EXPECT_TRUE(user_iface_->state().isEmpty()); |
2365 | +//} |
2366 | +// |
2367 | +// |
2368 | +///*** |
2369 | +//**** Make a real backup |
2370 | +//***/ |
2371 | +// |
2372 | +//TEST_F(KeeperTemplateTest, BackupRun) |
2373 | +//{ |
2374 | +// QTemporaryDir sandbox; |
2375 | +// |
2376 | +// // build a backup choice |
2377 | +// const auto uuid = QUuid::createUuid().toString(); |
2378 | +// const QMap<QString,QVariant> props { |
2379 | +// { KEY_NAME, QStringLiteral("Music") }, |
2380 | +// { KEY_TYPE, QStringLiteral("folder") }, |
2381 | +// { KEY_SUBTYPE, sandbox.path() }, |
2382 | +// { KEY_HELPER, QString::fromUtf8(FAKE_BACKUP_HELPER_EXEC) } |
2383 | +// }; |
2384 | +// |
2385 | +// // add it |
2386 | +// auto msg = mock_iface_->call(QStringLiteral("AddBackupChoice"), uuid, props); |
2387 | +// EXPECT_NE(QDBusMessage::ErrorMessage, msg.type()) << qPrintable(msg.errorMessage()); |
2388 | +// |
2389 | +// // start the backup |
2390 | +// QDBusReply<void> reply = user_iface_->call("StartBackup", QStringList{uuid}); |
2391 | +// EXPECT_TRUE(reply.isValid()) << qPrintable(reply.error().message()); |
2392 | +// ASSERT_TRUE(wait_for_tasks_to_finish()); |
2393 | +// |
2394 | +// // ask keeper for the blob |
2395 | +// QDBusReply<QByteArray> blob = mock_iface_->call(QStringLiteral("GetBackupData"), uuid); |
2396 | +// EXPECT_TRUE(reply.isValid()) << qPrintable(reply.error().message()); |
2397 | +// |
2398 | +// // check the results |
2399 | +// const auto expected_blob = QByteArray(FAKE_BACKUP_HELPER_PAYLOAD); |
2400 | +// ASSERT_EQ(expected_blob, blob); |
2401 | +//} |
2402 | |
2403 | === modified file 'tests/integration/helpers/helpers-test-failure.cpp' |
2404 | --- tests/integration/helpers/helpers-test-failure.cpp 2016-12-14 11:00:21 +0000 |
2405 | +++ tests/integration/helpers/helpers-test-failure.cpp 2016-12-22 14:35:27 +0000 |
2406 | @@ -48,7 +48,7 @@ |
2407 | ASSERT_TRUE(user_iface->isValid()) << qPrintable(dbus_test_runner.sessionConnection().lastError().message()); |
2408 | |
2409 | // ask for a list of backup choices |
2410 | - QDBusReply<QVariantDictMap> choices = user_iface->call("GetBackupChoices"); |
2411 | + QDBusReply<keeper::KeeperItemsMap> choices = user_iface->call("GetBackupChoices"); |
2412 | EXPECT_TRUE(choices.isValid()) << qPrintable(choices.error().message()); |
2413 | |
2414 | auto user_option = QStringLiteral("XDG_MUSIC_DIR"); |
2415 | @@ -90,26 +90,26 @@ |
2416 | // this one uses pooling so it should just call Get once |
2417 | EXPECT_TRUE(wait_for_all_tasks_have_action_state({user_folder_uuid}, "failed", user_iface)); |
2418 | |
2419 | - QVariant error_value; |
2420 | - EXPECT_TRUE(get_task_property_now(user_folder_uuid, user_iface, "error", error_value)); |
2421 | + keeper::KeeperItem item_value; |
2422 | + EXPECT_TRUE(get_task_value_now(user_folder_uuid, user_iface, item_value)); |
2423 | bool conversion_ok; |
2424 | - auto keeper_error = keeper::convertFromDBusVariant(error_value, &conversion_ok); |
2425 | + auto keeper_error = item_value.get_error(&conversion_ok); |
2426 | EXPECT_TRUE(conversion_ok); |
2427 | - EXPECT_EQ(keeper_error, keeper::KeeperError::HELPER_WRITE_ERROR); |
2428 | + EXPECT_EQ(keeper::Error::HELPER_WRITE, keeper_error); |
2429 | |
2430 | // check that the content of the file is the expected |
2431 | EXPECT_EQ(0, StorageFrameworkLocalUtils::check_storage_framework_nb_files()); |
2432 | |
2433 | // check that the state is failed |
2434 | - QVariantDictMap state = user_iface->state(); |
2435 | + auto state = user_iface->state(); |
2436 | |
2437 | // check that the state has the uuid |
2438 | - QVariantDictMap::const_iterator iter = state.find(user_folder_uuid); |
2439 | + auto iter = state.find(user_folder_uuid); |
2440 | EXPECT_TRUE(iter != state.end()); |
2441 | auto state_values = state[user_folder_uuid]; |
2442 | |
2443 | - EXPECT_EQ(std::string{"failed"}, state_values["action"].toString().toStdString()); |
2444 | - EXPECT_EQ(std::string{"Music"}, state_values["display-name"].toString().toStdString()); |
2445 | + EXPECT_EQ("failed", state_values.get_status()); |
2446 | + EXPECT_EQ("Music", state_values.get_display_name()); |
2447 | // sent 1 byte more than the expected, so percentage has to be greater than 1.0 |
2448 | - EXPECT_GT(state_values["percent-done"].toFloat(), 1.0); |
2449 | + EXPECT_LT(1.0, state_values.get_percent_done()); |
2450 | } |
2451 | |
2452 | === modified file 'tests/integration/helpers/helpers-test.cc' |
2453 | --- tests/integration/helpers/helpers-test.cc 2016-12-21 08:36:57 +0000 |
2454 | +++ tests/integration/helpers/helpers-test.cc 2016-12-22 14:35:27 +0000 |
2455 | @@ -76,7 +76,7 @@ |
2456 | ASSERT_TRUE(user_iface->isValid()) << qPrintable(dbus_test_runner.sessionConnection().lastError().message()); |
2457 | |
2458 | // ask for a list of backup choices |
2459 | - QDBusReply<QVariantDictMap> choices = user_iface->call("GetBackupChoices"); |
2460 | + QDBusReply<keeper::KeeperItemsMap> choices = user_iface->call("GetBackupChoices"); |
2461 | EXPECT_TRUE(choices.isValid()) << qPrintable(choices.error().message()); |
2462 | |
2463 | QString user_option = QStringLiteral("XDG_MUSIC_DIR"); |
2464 | @@ -145,7 +145,7 @@ |
2465 | // finally check that we have a valid manifest file. |
2466 | EXPECT_TRUE(check_manifest_file(backup_items)); |
2467 | |
2468 | - QDBusPendingReply<QVariantDictMap> restore_choices_reply = user_iface->call("GetRestoreChoices"); |
2469 | + QDBusPendingReply<keeper::KeeperItemsMap> restore_choices_reply = user_iface->call("GetRestoreChoices"); |
2470 | restore_choices_reply.waitForFinished(); |
2471 | EXPECT_TRUE(restore_choices_reply.isValid()) << qPrintable(choices.error().message()); |
2472 | |
2473 | @@ -195,7 +195,7 @@ |
2474 | ASSERT_TRUE(user_iface->isValid()) << qPrintable(dbus_test_runner.sessionConnection().lastError().message()); |
2475 | |
2476 | // ask for a list of backup choices |
2477 | - QDBusReply<QVariantDictMap> choices = user_iface->call("GetBackupChoices"); |
2478 | + QDBusReply<keeper::KeeperItemsMap> choices = user_iface->call("GetBackupChoices"); |
2479 | EXPECT_TRUE(choices.isValid()) << qPrintable(choices.error().message()); |
2480 | |
2481 | QString user_option = QStringLiteral("XDG_MUSIC_DIR"); |
2482 | @@ -316,7 +316,7 @@ |
2483 | |
2484 | ASSERT_EQ(1, spy_error.count()); |
2485 | arguments = spy_error.takeFirst(); |
2486 | - EXPECT_EQ(keeper::KeeperError::HELPER_START_TIMEOUT, qvariant_cast<keeper::KeeperError>(arguments.at(0))); |
2487 | + EXPECT_EQ(keeper::Error::HELPER_START_TIMEOUT, qvariant_cast<keeper::Error>(arguments.at(0))); |
2488 | } |
2489 | |
2490 | TEST_F(TestHelpers, Inactivity) |
2491 | @@ -346,5 +346,5 @@ |
2492 | |
2493 | ASSERT_EQ(1, spy_error.count()); |
2494 | arguments = spy_error.takeFirst(); |
2495 | - EXPECT_EQ(keeper::KeeperError::HELPER_INACTIVITY_DETECTED, qvariant_cast<keeper::KeeperError>(arguments.at(0))); |
2496 | + EXPECT_EQ(keeper::Error::HELPER_INACTIVITY_DETECTED, qvariant_cast<keeper::Error>(arguments.at(0))); |
2497 | } |
2498 | |
2499 | === modified file 'tests/integration/helpers/restore-test.cpp' |
2500 | --- tests/integration/helpers/restore-test.cpp 2016-10-28 15:11:21 +0000 |
2501 | +++ tests/integration/helpers/restore-test.cpp 2016-12-22 14:35:27 +0000 |
2502 | @@ -92,7 +92,7 @@ |
2503 | ASSERT_TRUE(user_iface->isValid()) << qPrintable(dbus_test_runner.sessionConnection().lastError().message()); |
2504 | |
2505 | // ask for a list of backup choices |
2506 | - QDBusPendingReply<QVariantDictMap> choices_reply = user_iface->call("GetRestoreChoices"); |
2507 | + QDBusPendingReply<keeper::KeeperItemsMap> choices_reply = user_iface->call("GetRestoreChoices"); |
2508 | choices_reply.waitForFinished(); |
2509 | EXPECT_TRUE(choices_reply.isFinished()); |
2510 | EXPECT_TRUE(choices_reply.isValid()) << qPrintable(choices_reply.error().message()); |
2511 | |
2512 | === modified file 'tests/integration/helpers/test-helpers-base.cpp' |
2513 | --- tests/integration/helpers/test-helpers-base.cpp 2016-12-21 08:36:57 +0000 |
2514 | +++ tests/integration/helpers/test-helpers-base.cpp 2016-12-22 14:35:27 +0000 |
2515 | @@ -35,6 +35,7 @@ |
2516 | |
2517 | bool qvariant_to_map(QVariant const& variant, QVariantMap& map) |
2518 | { |
2519 | + qDebug() << "VARIANT TYPE FOR STATE: " << variant.typeName(); |
2520 | if (variant.type() == QMetaType::QVariantMap) |
2521 | { |
2522 | map = variant.toMap(); |
2523 | @@ -45,11 +46,13 @@ |
2524 | return false; |
2525 | } |
2526 | |
2527 | -bool qdbus_argument_to_variant_dict_map(QVariant const& variant, QVariantDictMap& map) |
2528 | +bool qdbus_argument_to_keeper_items_map(QVariant const& variant, keeper::KeeperItemsMap& map) |
2529 | { |
2530 | + qDebug() << "**** VARIANT TYPE FOR STATE: " << variant.typeName(); |
2531 | if (variant.canConvert<QDBusArgument>()) |
2532 | { |
2533 | QDBusArgument value(variant.value<QDBusArgument>()); |
2534 | + qDebug() << "VALUE CURRENT TYPE: " << value.currentType() << " SIGNATURE: " << value.currentSignature(); |
2535 | if (value.currentType() == QDBusArgument::MapType) |
2536 | { |
2537 | value >> map; |
2538 | @@ -57,7 +60,7 @@ |
2539 | } |
2540 | else |
2541 | { |
2542 | - qWarning() << Q_FUNC_INFO << ": Could not convert variant to QVariantDictMap. Variant received has type " << value.currentType(); |
2543 | + qWarning() << Q_FUNC_INFO << ": Could not convert variant to keeper::KeeperItemsMap. Variant received has type " << value.currentType(); |
2544 | } |
2545 | } |
2546 | else |
2547 | @@ -67,7 +70,7 @@ |
2548 | return false; |
2549 | } |
2550 | |
2551 | -bool get_property_qvariant_dict_map(QString const & property, QVariant const &variant, QVariantDictMap & map) |
2552 | +bool get_property_qvariant_keeper_items_map(QString const & property, QVariant const &variant, keeper::KeeperItemsMap & map) |
2553 | { |
2554 | QVariantMap properties_map; |
2555 | if (!qvariant_to_map(variant, properties_map)) |
2556 | @@ -83,7 +86,7 @@ |
2557 | return false; |
2558 | } |
2559 | |
2560 | - if(!qdbus_argument_to_variant_dict_map((*iter), map)) |
2561 | + if(!qdbus_argument_to_keeper_items_map((*iter), map)) |
2562 | { |
2563 | qWarning() << Q_FUNC_INFO << ": Error converting property [" << property << "] to QVariantDictMap"; |
2564 | return false; |
2565 | @@ -441,7 +444,7 @@ |
2566 | return finished; |
2567 | } |
2568 | |
2569 | -bool TestHelpersBase::get_task_property_now(QString const & uuid, QSharedPointer<DBusInterfaceKeeperUser> const & keeper_user_iface, QString const & property, QVariant & value) const |
2570 | +bool TestHelpersBase::get_task_value_now(QString const & uuid, QSharedPointer<DBusInterfaceKeeperUser> const & keeper_user_iface, keeper::KeeperItem & value) const |
2571 | { |
2572 | auto state = keeper_user_iface->state(); |
2573 | auto iter = state.find(uuid); |
2574 | @@ -450,29 +453,23 @@ |
2575 | qWarning() << "Task " << uuid << " was not found in State"; |
2576 | return false; |
2577 | } |
2578 | - |
2579 | - auto iter_props = (*iter).find(property); |
2580 | - if (iter_props == (*iter).end()) |
2581 | - { |
2582 | - qWarning() << "Property " << property << " was not found for task " << uuid; |
2583 | - return false; |
2584 | - } |
2585 | - |
2586 | - value = (*iter_props); |
2587 | + value = (*iter); |
2588 | + |
2589 | return true; |
2590 | } |
2591 | |
2592 | -bool TestHelpersBase::check_task_has_action_state(QVariantDictMap const & state, QString const & uuid, QString const & action_state) |
2593 | +bool TestHelpersBase::check_task_has_action_state(keeper::KeeperItemsMap const & state, QString const & uuid, QString const & action_state) |
2594 | { |
2595 | auto iter = state.find(uuid); |
2596 | if (iter == state.end()) |
2597 | return false; |
2598 | |
2599 | - auto iter_props = (*iter).find("action"); |
2600 | - if (iter_props == (*iter).end()) |
2601 | + bool valid_status; |
2602 | + auto status = (*iter).get_status(&valid_status); |
2603 | + if (!valid_status) |
2604 | return false; |
2605 | |
2606 | - return (*iter_props).toString() == action_state; |
2607 | + return status == action_state; |
2608 | } |
2609 | |
2610 | bool TestHelpersBase::capture_and_check_state_until_all_tasks_complete(QSignalSpy & spy, QStringList const & uuids, QString const & action_state, int max_timeout_msec) |
2611 | @@ -510,8 +507,8 @@ |
2612 | { |
2613 | return false; |
2614 | } |
2615 | - QVariantDictMap keeper_state; |
2616 | - if (!get_property_qvariant_dict_map("State", arguments.at(1), keeper_state)) |
2617 | + keeper::KeeperItemsMap keeper_state; |
2618 | + if (!get_property_qvariant_keeper_items_map("State", arguments.at(1), keeper_state)) |
2619 | { |
2620 | return false; |
2621 | } |
2622 | @@ -595,8 +592,8 @@ |
2623 | { |
2624 | return false; |
2625 | } |
2626 | - QVariantDictMap keeper_state; |
2627 | - if (!get_property_qvariant_dict_map("State", arguments.at(1), keeper_state)) |
2628 | + keeper::KeeperItemsMap keeper_state; |
2629 | + if (!get_property_qvariant_keeper_items_map("State", arguments.at(1), keeper_state)) |
2630 | { |
2631 | return false; |
2632 | } |
2633 | @@ -655,7 +652,7 @@ |
2634 | return false; |
2635 | } |
2636 | |
2637 | -QString TestHelpersBase::get_uuid_for_xdg_folder_path(QString const &path, QVariantDictMap const & choices) const |
2638 | +QString TestHelpersBase::get_uuid_for_xdg_folder_path(QString const &path, keeper::KeeperItemsMap const & choices) const |
2639 | { |
2640 | for(auto iter = choices.begin(); iter != choices.end(); ++iter) |
2641 | { |
2642 | @@ -674,7 +671,7 @@ |
2643 | return QString(); |
2644 | } |
2645 | |
2646 | -QString TestHelpersBase::get_type_for_xdg_folder_path(QString const &path, QVariantDictMap const & choices) const |
2647 | +QString TestHelpersBase::get_type_for_xdg_folder_path(QString const &path, keeper::KeeperItemsMap const & choices) const |
2648 | { |
2649 | for(auto iter = choices.begin(); iter != choices.end(); ++iter) |
2650 | { |
2651 | @@ -698,7 +695,7 @@ |
2652 | return QString(); |
2653 | } |
2654 | |
2655 | -QString TestHelpersBase::get_display_name_for_xdg_folder_path(QString const &path, QVariantDictMap const & choices) const |
2656 | +QString TestHelpersBase::get_display_name_for_xdg_folder_path(QString const &path, keeper::KeeperItemsMap const & choices) const |
2657 | { |
2658 | for(auto iter = choices.begin(); iter != choices.end(); ++iter) |
2659 | { |
2660 | |
2661 | === modified file 'tests/integration/helpers/test-helpers-base.h' |
2662 | --- tests/integration/helpers/test-helpers-base.h 2016-12-21 08:36:57 +0000 |
2663 | +++ tests/integration/helpers/test-helpers-base.h 2016-12-22 14:35:27 +0000 |
2664 | @@ -95,17 +95,17 @@ |
2665 | |
2666 | bool wait_for_all_tasks_have_action_state(QStringList const & uuids, QString const & action_state, QSharedPointer<DBusInterfaceKeeperUser> const & keeper_user_iface, int max_timeout_msec = 15000); |
2667 | |
2668 | - bool check_task_has_action_state(QVariantDictMap const & state, QString const & uuid, QString const & action_state); |
2669 | + bool check_task_has_action_state(keeper::KeeperItemsMap const & state, QString const & uuid, QString const & action_state); |
2670 | |
2671 | - bool get_task_property_now(QString const & uuid, QSharedPointer<DBusInterfaceKeeperUser> const & keeper_user_iface, QString const & property, QVariant & value) const; |
2672 | + bool get_task_value_now(QString const & uuid, QSharedPointer<DBusInterfaceKeeperUser> const & keeper_user_iface, keeper::KeeperItem & value) const; |
2673 | |
2674 | bool capture_and_check_state_until_all_tasks_complete(QSignalSpy & spy, QStringList const & uuids, QString const & action_state, int max_timeout_msec = 15000); |
2675 | |
2676 | bool cancel_first_task_at_percentage(QSignalSpy & spy, double expected_percentage, QSharedPointer<DBusInterfaceKeeperUser> const & user_iface, int max_timeout_msec = 15000); |
2677 | |
2678 | - QString get_uuid_for_xdg_folder_path(QString const &path, QVariantDictMap const & choices) const; |
2679 | - QString get_type_for_xdg_folder_path(QString const &path, QVariantDictMap const & choices) const; |
2680 | - QString get_display_name_for_xdg_folder_path(QString const &path, QVariantDictMap const & choices) const; |
2681 | + QString get_uuid_for_xdg_folder_path(QString const &path, keeper::KeeperItemsMap const & choices) const; |
2682 | + QString get_type_for_xdg_folder_path(QString const &path, keeper::KeeperItemsMap const & choices) const; |
2683 | + QString get_display_name_for_xdg_folder_path(QString const &path, keeper::KeeperItemsMap const & choices) const; |
2684 | |
2685 | bool check_manifest_file(QVector<BackupItem> const & backup_items); |
2686 |
FAILED: Continuous integration, rev:134 /jenkins. canonical. com/unity- api-1/job/ lp-keeper- ci/158/ /jenkins. canonical. com/unity- api-1/job/ build/1293/ console /jenkins. canonical. com/unity- api-1/job/ build-0- fetch/1300/ console
https:/
Executed test runs:
FAILURE: https:/
FAILURE: https:/
Click here to trigger a rebuild: /jenkins. canonical. com/unity- api-1/job/ lp-keeper- ci/158/ rebuild
https:/