Merge lp:~michihenning/thumbnailer/fix-admin-relative-paths into lp:thumbnailer/devel

Proposed by Michi Henning
Status: Merged
Approved by: James Henstridge
Approved revision: 343
Merged at revision: 342
Proposed branch: lp:~michihenning/thumbnailer/fix-admin-relative-paths
Merge into: lp:thumbnailer/devel
Diff against target: 137 lines (+42/-11)
5 files modified
src/libthumbnailer-qt/libthumbnailer-qt.cpp (+12/-1)
src/thumbnailer-admin/thumbnailer-admin.cpp (+0/-2)
src/thumbnailer.cpp (+5/-0)
tests/thumbnailer-admin/thumbnailer-admin_test.cpp (+3/-7)
tests/thumbnailer/thumbnailer_test.cpp (+22/-1)
To merge this branch: bzr merge lp:~michihenning/thumbnailer/fix-admin-relative-paths
Reviewer Review Type Date Requested Status
James Henstridge Approve
PS Jenkins bot (community) continuous-integration Approve
Review via email: mp+284192@code.launchpad.net

Commit message

Canonicalise paths on the client side because relative paths on the server side don't make sense.

Description of the change

Canonicalise paths on the client side because relative paths on the server side don't make sense.

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
James Henstridge (jamesh) wrote :

Looks like a good change. But can we get rid of the multiple canonical() calls on the client side?

343. By Michi Henning

Review comments from James.

Revision history for this message
James Henstridge (jamesh) wrote :

Looks good.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/libthumbnailer-qt/libthumbnailer-qt.cpp'
2--- src/libthumbnailer-qt/libthumbnailer-qt.cpp 2016-01-13 07:07:45 +0000
3+++ src/libthumbnailer-qt/libthumbnailer-qt.cpp 2016-02-10 08:09:05 +0000
4@@ -24,6 +24,7 @@
5 #include <thumbnailerinterface.h>
6 #include <service/dbus_names.h>
7
8+#include <boost/filesystem.hpp>
9 #include <QSharedPointer>
10
11 #include <memory>
12@@ -400,7 +401,17 @@
13 s << "getThumbnail: (" << requestedSize.width() << "," << requestedSize.height() << ") " << filename;
14 auto job = [this, filename, requestedSize]
15 {
16- return iface_->GetThumbnail(filename, requestedSize);
17+ // Remote end requires an absolute path.
18+ QString canonical_name = filename;
19+ try
20+ {
21+ canonical_name = QString::fromStdString(boost::filesystem::canonical(filename.toStdString()).native());
22+ }
23+ catch (std::exception const&)
24+ {
25+ // If name can't be canonicalised, errors will be dealt with on the server side.
26+ }
27+ return iface_->GetThumbnail(canonical_name, requestedSize);
28 };
29 return createRequest(details, requestedSize, job);
30 }
31
32=== modified file 'src/thumbnailer-admin/thumbnailer-admin.cpp'
33--- src/thumbnailer-admin/thumbnailer-admin.cpp 2015-09-29 14:05:53 +0000
34+++ src/thumbnailer-admin/thumbnailer-admin.cpp 2016-02-10 08:09:05 +0000
35@@ -123,7 +123,6 @@
36 {
37 cerr << prog_name << ": " << e.what() << endl;
38 }
39- // LCOV_EXCL_STOP
40 catch (QString const& msg)
41 {
42 cerr << prog_name << ": " << msg.toStdString() << endl;
43@@ -132,7 +131,6 @@
44 {
45 cerr << prog_name << ": " << msg << endl;
46 }
47- // LCOV_EXCL_START
48 catch (char const* msg)
49 {
50 cerr << prog_name << ": " << msg << endl;
51
52=== modified file 'src/thumbnailer.cpp'
53--- src/thumbnailer.cpp 2016-01-19 16:21:00 +0000
54+++ src/thumbnailer.cpp 2016-02-10 08:09:05 +0000
55@@ -497,6 +497,11 @@
56 : RequestBase(thumbnailer, "", requested_size, timeout)
57 , filename_(filename)
58 {
59+ if (!boost::filesystem::path(filename).is_absolute())
60+ {
61+ throw runtime_error("LocalThumbnailRequest(): " + filename_ + ": file name must be an absolute path");
62+ }
63+
64 // We canonicalise the path name both to avoid caching the file
65 // multiple times, and to ensure our access checks are against the
66 // real file rather than a symlink.
67
68=== modified file 'tests/thumbnailer-admin/thumbnailer-admin_test.cpp'
69--- tests/thumbnailer-admin/thumbnailer-admin_test.cpp 2016-01-08 02:42:41 +0000
70+++ tests/thumbnailer-admin/thumbnailer-admin_test.cpp 2016-02-10 08:09:05 +0000
71@@ -557,7 +557,7 @@
72 EXPECT_EQ(1, ar.run(QStringList{"get", "--help"}));
73 EXPECT_TRUE(starts_with(ar.stderr(), "thumbnailer-admin: Usage: ")) << ar.stderr();
74
75- EXPECT_EQ(1, ar.run(QStringList{"get", "--size=abc", TESTDATADIR "/orientation-1/jpg"}));
76+ EXPECT_EQ(1, ar.run(QStringList{"get", "--size=abc", TESTDATADIR "/orientation-1.jpg"}));
77 EXPECT_EQ("thumbnailer-admin: GetLocalThumbnail(): invalid size: abc\n", ar.stderr()) << ar.stderr();
78 }
79
80@@ -566,14 +566,10 @@
81 AdminRunner ar;
82
83 EXPECT_EQ(1, ar.run(QStringList{"get", "no_such_file", QString::fromStdString(temp_dir())}));
84- EXPECT_TRUE(starts_with(ar.stderr(),
85- "thumbnailer-admin: DBusInterface::GetThumbnail(): no_such_file: unity::ResourceException: Thumbnailer::get_thumbnail():\n boost::filesystem::canonical: No such file or directory:"))
86- << ar.stderr();
87+ EXPECT_TRUE(ends_with(ar.stderr(), ": no_such_file: file name must be an absolute path\n")) << ar.stderr();
88
89 EXPECT_EQ(1, ar.run(QStringList{"get", TESTDATADIR "/orientation-2.jpg", "no_such_directory"}));
90- EXPECT_TRUE(starts_with(ar.stderr(),
91- "thumbnailer-admin: GetLocalThumbnail::run(): write_file(): mkstemp() failed for "))
92- << ar.stderr();
93+ EXPECT_TRUE(ends_with(ar.stderr(), ": No such file or directory\n")) << ar.stderr();
94 }
95
96 TEST_F(AdminTest, shutdown)
97
98=== modified file 'tests/thumbnailer/thumbnailer_test.cpp'
99--- tests/thumbnailer/thumbnailer_test.cpp 2016-01-19 16:21:00 +0000
100+++ tests/thumbnailer/thumbnailer_test.cpp 2016-02-10 08:09:05 +0000
101@@ -761,7 +761,7 @@
102 auto old_stats = tn.stats();
103 try
104 {
105- auto request = tn.get_thumbnail("no_such_file", QSize(10, 10));
106+ auto request = tn.get_thumbnail("/no_such_file", QSize(10, 10));
107 FAIL();
108 }
109 catch (unity::ResourceException const& e)
110@@ -775,6 +775,27 @@
111 }
112 }
113
114+TEST_F(RemoteServer, relative_path)
115+{
116+ Thumbnailer tn;
117+
118+ auto old_stats = tn.stats();
119+ try
120+ {
121+ auto request = tn.get_thumbnail("xxx", QSize(10, 10));
122+ FAIL();
123+ }
124+ catch (unity::ResourceException const& e)
125+ {
126+ string msg = e.to_string();
127+ EXPECT_TRUE(boost::starts_with(msg,
128+ "unity::ResourceException: Thumbnailer::get_thumbnail():\n"
129+ " LocalThumbnailRequest(): xxx: file name must be an absolute path")) << msg;
130+ auto new_stats = tn.stats();
131+ EXPECT_EQ(old_stats.failure_stats.size(), new_stats.failure_stats.size());
132+ }
133+}
134+
135 TEST_F(RemoteServer, bad_request)
136 {
137 Thumbnailer tn;

Subscribers

People subscribed via source and target branches

to all changes: