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

Proposed by Alberto Mardegan
Status: Merged
Approved by: David Barth
Approved revision: 369
Merged at revision: 370
Proposed branch: lp:~mardy/ubuntu-system-settings-online-accounts/stale-hooks-1596478
Merge into: lp:ubuntu-system-settings-online-accounts
Diff against target: 100 lines (+32/-4)
2 files modified
click-hooks/accounts.cpp (+16/-2)
click-hooks/main.cpp (+16/-2)
To merge this branch: bzr merge lp:~mardy/ubuntu-system-settings-online-accounts/stale-hooks-1596478
Reviewer Review Type Date Requested Status
PS Jenkins bot continuous-integration Pending
Online Accounts Pending
Review via email: mp+298497@code.launchpad.net

Commit message

Read time from symlink file, not target

It looks like click does not updates the time of installed files when upgrading a click package. QFileInfo::lastModified() method returns the time of the target file of a symlink, which causes our hooks not to detect a change.

Description of the change

Read time from symlink file, not target

It looks like click does not updates the time of installed files when upgrading a click package. QFileInfo::lastModified() method returns the time of the target file of a symlink, which causes our hooks not to detect a change.

To post a comment you must log in.

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-11-30 09:54:01 +0000
3+++ click-hooks/accounts.cpp 2016-06-28 09:08:26 +0000
4@@ -35,7 +35,9 @@
5 #include <QStandardPaths>
6 #include <QStringList>
7 #include <click.h>
8+#include <sys/stat.h>
9 #include <sys/types.h>
10+#include <unistd.h>
11 #include <utime.h>
12 #include "acl-updater.h"
13
14@@ -624,6 +626,18 @@
15 }
16 }
17
18+/* Get the modification time of a file; this differs from
19+ * QFileInfo::lastModified() in that if the file is a symlink here we take the
20+ * info from the symlink itself. */
21+static QDateTime lastModified(const QFileInfo &fileInfo)
22+{
23+ struct stat data;
24+ if (lstat(fileInfo.filePath().toUtf8().constData(), &data) < 0) {
25+ return QDateTime();
26+ }
27+ return QDateTime::fromTime_t(data.st_mtime);
28+}
29+
30 int main(int argc, char **argv)
31 {
32 QCoreApplication app(argc, argv);
33@@ -678,7 +692,7 @@
34 */
35 QFileInfo processedInfo(fileInfo.filePath() + ".processed");
36 if (processedInfo.exists() &&
37- processedInfo.lastModified() == fileInfo.lastModified()) {
38+ processedInfo.lastModified() == lastModified(fileInfo)) {
39 continue;
40 }
41
42@@ -694,7 +708,7 @@
43 file.close();
44 struct utimbuf sourceTime;
45 sourceTime.actime = sourceTime.modtime =
46- fileInfo.lastModified().toTime_t();
47+ lastModified(fileInfo).toTime_t();
48 utime(processedInfo.filePath().toUtf8().constData(),
49 &sourceTime);
50 } else {
51
52=== modified file 'click-hooks/main.cpp'
53--- click-hooks/main.cpp 2015-10-30 06:30:09 +0000
54+++ click-hooks/main.cpp 2016-06-28 09:08:26 +0000
55@@ -30,7 +30,9 @@
56 #include <QStandardPaths>
57 #include <QStringList>
58 #include <click.h>
59+#include <sys/stat.h>
60 #include <sys/types.h>
61+#include <unistd.h>
62 #include <utime.h>
63
64 static QString findPackageDir(const QString &appId)
65@@ -82,6 +84,18 @@
66 return components.join('_');
67 }
68
69+/* Get the modification time of a file; this differs from
70+ * QFileInfo::lastModified() in that if the file is a symlink here we take the
71+ * info from the symlink itself. */
72+static QDateTime lastModified(const QFileInfo &fileInfo)
73+{
74+ struct stat data;
75+ if (lstat(fileInfo.filePath().toUtf8().constData(), &data) < 0) {
76+ return QDateTime();
77+ }
78+ return QDateTime::fromTime_t(data.st_mtime);
79+}
80+
81 class LibAccountsFile: public QDomDocument {
82 public:
83 LibAccountsFile(const QFileInfo &hookFileInfo);
84@@ -216,7 +230,7 @@
85 if (ok) {
86 struct utimbuf sourceTime;
87 sourceTime.actime = sourceTime.modtime =
88- m_hookFileInfo.lastModified().toTime_t();
89+ lastModified(m_hookFileInfo).toTime_t();
90 utime(fileName.toUtf8().constData(), &sourceTime);
91 return true;
92 } else {
93@@ -348,7 +362,7 @@
94 QFileInfo destinationInfo(destination);
95 /* If the destination is there and up to date, we have nothing to do */
96 if (destinationInfo.exists() &&
97- destinationInfo.lastModified() == fileInfo.lastModified()) {
98+ destinationInfo.lastModified() == lastModified(fileInfo)) {
99 continue;
100 }
101

Subscribers

People subscribed via source and target branches