Merge lp:~mardy/ubuntu-system-settings-online-accounts/hooks-timestamp into lp:ubuntu-system-settings-online-accounts

Proposed by Alberto Mardegan
Status: Merged
Approved by: dobey
Approved revision: 302
Merge reported by: Alberto Mardegan
Merged at revision: not available
Proposed branch: lp:~mardy/ubuntu-system-settings-online-accounts/hooks-timestamp
Merge into: lp:ubuntu-system-settings-online-accounts
Diff against target: 126 lines (+49/-3)
3 files modified
click-hooks/accounts.cpp (+11/-2)
click-hooks/main.cpp (+7/-1)
tests/click-hooks/tst_online_accounts_hooks.cpp (+31/-0)
To merge this branch: bzr merge lp:~mardy/ubuntu-system-settings-online-accounts/hooks-timestamp
Reviewer Review Type Date Requested Status
dobey (community) Approve
PS Jenkins bot (community) continuous-integration Approve
Review via email: mp+275959@code.launchpad.net

Commit message

Regenerate hooks whenever file time changes

Description of the change

Regenerate hooks whenever file time changes

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

Looks ok to me.

review: Approve
302. By Alberto Mardegan

Close file before setting timestamp

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'click-hooks/accounts.cpp'
2--- click-hooks/accounts.cpp 2015-09-28 14:35:19 +0000
3+++ click-hooks/accounts.cpp 2015-10-28 13:59:26 +0000
4@@ -35,6 +35,8 @@
5 #include <QStandardPaths>
6 #include <QStringList>
7 #include <click.h>
8+#include <sys/types.h>
9+#include <utime.h>
10 #include "acl-updater.h"
11
12 static QString findPackageDir(const QString &appId)
13@@ -692,7 +694,7 @@
14 */
15 QFileInfo processedInfo(fileInfo.filePath() + ".processed");
16 if (processedInfo.exists() &&
17- processedInfo.lastModified() >= fileInfo.lastModified()) {
18+ processedInfo.lastModified() == fileInfo.lastModified()) {
19 continue;
20 }
21
22@@ -704,7 +706,14 @@
23
24 if (manifest.writeFiles(accountsDir)) {
25 QFile file(processedInfo.filePath());
26- if (!file.open(QIODevice::WriteOnly | QIODevice::Text)) {
27+ if (file.open(QIODevice::WriteOnly | QIODevice::Text)) {
28+ file.close();
29+ struct utimbuf sourceTime;
30+ sourceTime.actime = sourceTime.modtime =
31+ fileInfo.lastModified().toTime_t();
32+ utime(processedInfo.filePath().toUtf8().constData(),
33+ &sourceTime);
34+ } else {
35 qWarning() << "Could not create timestamp file" <<
36 processedInfo.filePath();
37 }
38
39=== modified file 'click-hooks/main.cpp'
40--- click-hooks/main.cpp 2015-08-28 10:20:33 +0000
41+++ click-hooks/main.cpp 2015-10-28 13:59:26 +0000
42@@ -30,6 +30,8 @@
43 #include <QStandardPaths>
44 #include <QStringList>
45 #include <click.h>
46+#include <sys/types.h>
47+#include <utime.h>
48
49 static QString findPackageDir(const QString &appId)
50 {
51@@ -212,6 +214,10 @@
52 file.close();
53
54 if (ok) {
55+ struct utimbuf sourceTime;
56+ sourceTime.actime = sourceTime.modtime =
57+ m_hookFileInfo.lastModified().toTime_t();
58+ utime(fileName.toUtf8().constData(), &sourceTime);
59 return true;
60 } else {
61 QFile::remove(fileName);
62@@ -342,7 +348,7 @@
63 QFileInfo destinationInfo(destination);
64 /* If the destination is there and up to date, we have nothing to do */
65 if (destinationInfo.exists() &&
66- destinationInfo.lastModified() >= fileInfo.lastModified()) {
67+ destinationInfo.lastModified() == fileInfo.lastModified()) {
68 continue;
69 }
70
71
72=== modified file 'tests/click-hooks/tst_online_accounts_hooks.cpp'
73--- tests/click-hooks/tst_online_accounts_hooks.cpp 2015-08-28 10:20:33 +0000
74+++ tests/click-hooks/tst_online_accounts_hooks.cpp 2015-10-28 13:59:26 +0000
75@@ -28,6 +28,9 @@
76 #include <QProcess>
77 #include <QSignalSpy>
78 #include <QTest>
79+#include <sys/types.h>
80+#include <time.h>
81+#include <utime.h>
82
83 #define TEST_DIR "/tmp/hooks-test"
84
85@@ -465,6 +468,8 @@
86 clearHooksDir();
87 clearInstallDir();
88
89+ time_t oldTime = time(NULL) - 3;
90+
91 writeHookFile("com-ubuntu.test_MyApp_1.0.application",
92 "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n"
93 "<application>\n"
94@@ -511,6 +516,32 @@
95 root = doc.documentElement();
96 QCOMPARE(root.firstChildElement("profile").text(),
97 QString("com-ubuntu.test_MyApp_1.1"));
98+
99+ // Create an *older* file
100+ clearHooksDir();
101+ QString fileName("com-ubuntu.test_MyApp_1.2.application");
102+ writeHookFile(fileName,
103+ "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n"
104+ "<application>\n"
105+ " <description>My application</description>\n"
106+ " <service-types>\n"
107+ " <service-type>some type</service-type>\n"
108+ " </service-types>\n"
109+ "</application>");
110+ struct utimbuf sourceTime;
111+ sourceTime.actime = sourceTime.modtime = oldTime;
112+ utime(m_hooksDir.filePath(fileName).toUtf8().constData(), &sourceTime);
113+
114+ QVERIFY(runHookProcess());
115+
116+ // check that the file has been updated with the correct profile
117+ file.close();
118+ file.setFileName(m_installDir.absoluteFilePath(installedName));
119+ QVERIFY(file.open(QIODevice::ReadOnly));
120+ QVERIFY(doc.setContent(&file));
121+ root = doc.documentElement();
122+ QCOMPARE(root.firstChildElement("profile").text(),
123+ QString("com-ubuntu.test_MyApp_1.2"));
124 }
125
126 void OnlineAccountsHooksTest::testDesktopEntry_data()

Subscribers

People subscribed via source and target branches