Merge lp:~mardy/ubuntu-system-settings-online-accounts/remove-stale-accounts into lp:~online-accounts/ubuntu-system-settings-online-accounts/master

Proposed by Alberto Mardegan on 2015-01-22
Status: Merged
Merged at revision: 229
Proposed branch: lp:~mardy/ubuntu-system-settings-online-accounts/remove-stale-accounts
Merge into: lp:~online-accounts/ubuntu-system-settings-online-accounts/master
Diff against target: 190 lines (+96/-7)
3 files modified
click-hooks/main.cpp (+28/-6)
tests/click-hooks/click-hooks.pro (+5/-1)
tests/click-hooks/tst_online_accounts_hooks.cpp (+63/-0)
To merge this branch: bzr merge lp:~mardy/ubuntu-system-settings-online-accounts/remove-stale-accounts
Reviewer Review Type Date Requested Status
Justin McPherson 2015-01-22 Approve on 2015-02-17
Review via email: mp+247272@code.launchpad.net

Commit message

Delete accounts when their plugin is removed

Description of the change

Delete accounts when their plugin is removed

To post a comment you must log in.
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'click-hooks/main.cpp'
2--- click-hooks/main.cpp 2015-01-21 15:11:36 +0000
3+++ click-hooks/main.cpp 2015-01-22 10:59:52 +0000
4@@ -217,7 +217,20 @@
5 }
6 }
7
8-static void removeStaleFiles(const QStringList &fileTypes,
9+static void removeStaleAccounts(Accounts::Manager *manager,
10+ const QString &providerName)
11+{
12+ Q_FOREACH(Accounts::AccountId id, manager->accountList()) {
13+ Accounts::Account *account = manager->account(id);
14+ if (account->providerName() == providerName) {
15+ account->remove();
16+ account->syncAndBlock();
17+ }
18+ }
19+}
20+
21+static void removeStaleFiles(Accounts::Manager *manager,
22+ const QStringList &fileTypes,
23 const QString &localShare,
24 const QDir &hooksDirIn)
25 {
26@@ -245,8 +258,13 @@
27 * means that the click package was removed, and we must remove our
28 * copy as well. */
29 QString hookFileName = profile + "." + fileType;
30- if (!hooksDirIn.exists(hookFileName)) {
31- QFile::remove(fileInfo.filePath());
32+ if (hooksDirIn.exists(hookFileName)) continue;
33+
34+ QFile::remove(fileInfo.filePath());
35+ /* If this is a provider, we must also remove any accounts
36+ * associated with it */
37+ if (fileType == QStringLiteral("provider")) {
38+ removeStaleAccounts(manager, fileInfo.completeBaseName());
39 }
40 }
41 }
42@@ -256,6 +274,12 @@
43 {
44 QCoreApplication app(argc, argv);
45
46+ Accounts::Manager::Options managerOptions;
47+ if (qgetenv("DBUS_SESSION_BUS_ADDRESS").isEmpty()) {
48+ managerOptions |= Accounts::Manager::DisableNotifications;
49+ }
50+ Accounts::Manager *manager = new Accounts::Manager(managerOptions);
51+
52 /* Go through the hook files in ~/.local/share/online-accounts-hooks/ and
53 * check if they have already been processed into a file under
54 * ~/.local/share/accounts/{providers,services,service-types,applications}/;
55@@ -274,7 +298,7 @@
56 QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation);
57 QDir hooksDirIn(localShare + "/" HOOK_FILES_SUBDIR);
58
59- removeStaleFiles(fileTypes, localShare, hooksDirIn);
60+ removeStaleFiles(manager, fileTypes, localShare, hooksDirIn);
61
62 Q_FOREACH(const QFileInfo &fileInfo, hooksDirIn.entryInfoList()) {
63 const QString fileType = fileInfo.suffix();
64@@ -320,8 +344,6 @@
65 /* To ensure that all the installed services are parsed into
66 * libaccounts' DB, we enumerate them now.
67 */
68- Accounts::Manager *manager =
69- new Accounts::Manager(Accounts::Manager::DisableNotifications);
70 manager->serviceList();
71 delete manager;
72
73
74=== modified file 'tests/click-hooks/click-hooks.pro'
75--- tests/click-hooks/click-hooks.pro 2014-05-16 09:42:06 +0000
76+++ tests/click-hooks/click-hooks.pro 2015-01-22 10:59:52 +0000
77@@ -3,13 +3,17 @@
78 TARGET = tst_online_accounts_hooks
79
80 CONFIG += \
81- debug
82+ debug \
83+ link_pkgconfig
84
85 QT += \
86 core \
87 testlib \
88 xml
89
90+PKGCONFIG += \
91+ accounts-qt5
92+
93 DEFINES += \
94 DEBUG_ENABLED \
95 HOOK_PROCESS=\\\"../../click-hooks/online-accounts-hooks\\\"
96
97=== modified file 'tests/click-hooks/tst_online_accounts_hooks.cpp'
98--- tests/click-hooks/tst_online_accounts_hooks.cpp 2014-11-04 12:26:46 +0000
99+++ tests/click-hooks/tst_online_accounts_hooks.cpp 2015-01-22 10:59:52 +0000
100@@ -18,6 +18,8 @@
101 * with this program. If not, see <http://www.gnu.org/licenses/>.
102 */
103
104+#include <Accounts/Account>
105+#include <Accounts/Manager>
106 #include <QDebug>
107 #include <QDir>
108 #include <QDomDocument>
109@@ -42,6 +44,7 @@
110 void testValidHooks_data();
111 void testValidHooks();
112 void testRemoval();
113+ void testAccountRemoval();
114 void testUpdate();
115 void testDesktopEntry_data();
116 void testDesktopEntry();
117@@ -139,6 +142,8 @@
118 {
119 qputenv("XDG_DATA_HOME", TEST_DIR);
120 qputenv("OAH_CLICK_DIR", m_packageDir.path().toUtf8());
121+ qputenv("ACCOUNTS", TEST_DIR);
122+
123 // The hook must be able to run without a D-Bus session
124 qunsetenv("DBUS_SESSION_BUS_ADDRESS");
125
126@@ -377,6 +382,64 @@
127 QVERIFY(m_installDir.exists(noProfile));
128 }
129
130+void OnlineAccountsHooksTest::testAccountRemoval()
131+{
132+ clearHooksDir();
133+ clearInstallDir();
134+
135+ Accounts::Manager *manager =
136+ new Accounts::Manager(Accounts::Manager::DisableNotifications);
137+
138+ QString stillInstalled("providers/com.ubuntu.test_StillInstalled.provider");
139+ writeInstalledFile(stillInstalled,
140+ "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n"
141+ "<provider>\n"
142+ " <profile>com-ubuntu.test_StillInstalled_2.0</profile>\n"
143+ "</provider>");
144+ QVERIFY(m_installDir.exists(stillInstalled));
145+
146+ writeHookFile("com-ubuntu.test_StillInstalled_2.0.provider",
147+ "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n"
148+ "<provider>\n"
149+ "</provider>");
150+
151+ Accounts::Account *account =
152+ manager->createAccount("com.ubuntu.test_StillInstalled");
153+ account->setDisplayName("Still alive");
154+ account->syncAndBlock();
155+ Accounts::AccountId idPreserved = account->id();
156+ QVERIFY(idPreserved > 0);
157+
158+ QString myProvider("providers/com.ubuntu.test_MyProvider.provider");
159+ writeInstalledFile(myProvider,
160+ "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n"
161+ "<provider>\n"
162+ " <profile>com-ubuntu.test_MyProvider_3.0</profile>\n"
163+ "</provider>");
164+ QVERIFY(m_installDir.exists(myProvider));
165+
166+ account = manager->createAccount("com.ubuntu.test_MyProvider");
167+ account->setDisplayName("Must die");
168+ account->syncAndBlock();
169+ Accounts::AccountId idRemoved = account->id();
170+ QVERIFY(idRemoved > 0);
171+
172+ delete manager;
173+
174+ QVERIFY(runHookProcess());
175+
176+ QVERIFY(m_installDir.exists(stillInstalled));
177+ QVERIFY(!m_installDir.exists(myProvider));
178+
179+ manager = new Accounts::Manager(Accounts::Manager::DisableNotifications);
180+ account = manager->account(idPreserved);
181+ QVERIFY(account != 0);
182+ account = manager->account(idRemoved);
183+ QVERIFY(account == 0);
184+
185+ delete manager;
186+}
187+
188 void OnlineAccountsHooksTest::testUpdate()
189 {
190 clearHooksDir();

Subscribers

People subscribed via source and target branches