Merge lp:~mterry/ubuntu-app-launch/persistentid into lp:ubuntu-app-launch
- persistentid
- Merge into trunk.17.04
Status: | Merged |
---|---|
Approved by: | Ted Gould |
Approved revision: | 302 |
Merged at revision: | 313 |
Proposed branch: | lp:~mterry/ubuntu-app-launch/persistentid |
Merge into: | lp:ubuntu-app-launch |
Diff against target: |
216 lines (+113/-11) 5 files modified
debian/changelog (+6/-0) libubuntu-app-launch/appid.h (+20/-3) libubuntu-app-launch/application.cpp (+62/-0) libubuntu-app-launch/helper.cpp (+1/-8) tests/libual-cpp-test.cc (+24/-0) |
To merge this branch: | bzr merge lp:~mterry/ubuntu-app-launch/persistentid |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Ted Gould (community) | Approve | ||
unity-api-1-bot | continuous-integration | Needs Fixing | |
Review via email: mp+318682@code.launchpad.net |
Commit message
Add persistentID and dbusID methods to ual::AppID
Description of the change
This branch adds two pieces of AppID API:
- persistentID which provides a string that is suitable for writing to disk and back again (i.e. no revision information)
- dbusID which is syntactic sugar for apps that may expose their appID over DBus paths or consume such paths by other apps.
With persistentID, other apps should no longer will have to embed information about appID formats (like manually combining package and command with an underscore). dbusID I care less about, but we talked about it before and since I was there...
unity-api-1-bot (unity-api-1-bot) wrote : | # |
- 297. By Michael Terry
-
Drop prototype for removed function
Michael Terry (mterry) wrote : | # |
Instead of homegrown escaping, we could use nih_dbus_path?
unity-api-1-bot (unity-api-1-bot) wrote : | # |
FAILED: Continuous integration, rev:297
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:/
Ted Gould (ted) wrote : | # |
> Instead of homegrown escaping, we could use nih_dbus_path?
We're dropping deps on libnih, so no :-)
Ted Gould (ted) wrote : | # |
Slight comment, but glad to get the dbus stuff C++-ified.
Michael Terry (mterry) wrote : | # |
Fixing your isalpha comment. But I wanted to quickly make explicit that this new API is making a promise that UAL hasn't made yet, and just confirm we are cool with it.
So UAL is saying that if you write this AppID to disk, in a year or two, AppID::find() will definitely still recognize it. That's a longevity of format/parsing that I don't think we have made yet.
And since I'm doing this set of changes to consolidate parsing in UAL, and perhaps give us flexibility to change appID format in the future, when we do so, we'd have to carefully consider what that does to persistentIDs out in the wild.
Not a problem necessarily, just wanted to make sure you were OK with signing up for that.
(We already had this problem -- unity8 was already making its own persistentIDs. But now UAL is making that promise to everyone that uses its API.)
- 298. By Michael Terry
-
Use isalpha and isdigit
Michael Terry (mterry) wrote : | # |
OK fixed to use isalpha and isdigit.
unity-api-1-bot (unity-api-1-bot) wrote : | # |
FAILED: Continuous integration, rev:298
https:/
Executed test runs:
FAILURE: https:/
SUCCESS: https:/
SUCCESS: https:/
deb: https:/
FAILURE: https:/
SUCCESS: https:/
deb: https:/
SUCCESS: https:/
deb: https:/
SUCCESS: https:/
deb: https:/
SUCCESS: https:/
deb: https:/
Click here to trigger a rebuild:
https:/
Ted Gould (ted) wrote : | # |
I think we have to, don't love it, but I think that we can handle that part of the persistent IDs.
Your isdigit() change dropped the i != 0 check, which is because dbus names can't have a digit as their first character.
- 299. By Michael Terry
-
Restore i != 0 check
Michael Terry (mterry) wrote : | # |
OK, restored the i != 0 check.
unity-api-1-bot (unity-api-1-bot) wrote : | # |
FAILED: Continuous integration, rev:299
https:/
Executed test runs:
FAILURE: https:/
SUCCESS: https:/
SUCCESS: https:/
deb: https:/
FAILURE: https:/
SUCCESS: https:/
deb: https:/
FAILURE: https:/
SUCCESS: https:/
deb: https:/
SUCCESS: https:/
deb: https:/
Click here to trigger a rebuild:
https:/
Michael Terry (mterry) wrote : | # |
Is that CI failure related? Doesn't look it to me, but if other branches are passing...
Ted Gould (ted) wrote : | # |
Not worried about the CI as much as the conflict in the branch. I'm guessing there might be another with Pete's branches landing.
- 300. By Michael Terry
-
Merge trunk
- 301. By Michael Terry
-
Fix tests now that click apps are gone
- 302. By Michael Terry
-
Fix version
Michael Terry (mterry) wrote : | # |
Fixed the conflict.
unity-api-1-bot (unity-api-1-bot) wrote : | # |
FAILED: Continuous integration, rev:302
https:/
Executed test runs:
FAILURE: https:/
SUCCESS: https:/
FAILURE: https:/
SUCCESS: https:/
deb: https:/
SUCCESS: https:/
deb: https:/
SUCCESS: https:/
deb: https:/
SUCCESS: https:/
deb: https:/
FAILURE: https:/
Click here to trigger a rebuild:
https:/
Ted Gould (ted) : | # |
Preview Diff
1 | === modified file 'debian/changelog' |
2 | --- debian/changelog 2017-03-21 03:29:09 +0000 |
3 | +++ debian/changelog 2017-03-30 13:56:23 +0000 |
4 | @@ -1,3 +1,9 @@ |
5 | +ubuntu-app-launch (0.12) UNRELEASED; urgency=medium |
6 | + |
7 | + * Bump version for new AppID methods |
8 | + |
9 | + -- Michael Terry <mterry@ubuntu.com> Tue, 28 Feb 2017 15:59:05 -0500 |
10 | + |
11 | ubuntu-app-launch (0.11+17.04.20170321-0ubuntu1) zesty; urgency=medium |
12 | |
13 | [ Ted Gould ] |
14 | |
15 | === modified file 'libubuntu-app-launch/appid.h' |
16 | --- libubuntu-app-launch/appid.h 2016-08-24 21:52:19 +0000 |
17 | +++ libubuntu-app-launch/appid.h 2017-03-30 13:56:23 +0000 |
18 | @@ -1,5 +1,5 @@ |
19 | /* |
20 | - * Copyright © 2016 Canonical Ltd. |
21 | + * Copyright © 2016-2017 Canonical Ltd. |
22 | * |
23 | * This program is free software: you can redistribute it and/or modify it |
24 | * under the terms of the GNU General Public License version 3, as published |
25 | @@ -82,6 +82,16 @@ |
26 | anyting other than debug messages. */ |
27 | operator std::string() const; |
28 | |
29 | + /** Turn the structure into a string suitable for use in DBus paths. |
30 | + Turn this back into an AppID with parseDBusID(). This is otherwise not |
31 | + a valid AppID string. */ |
32 | + std::string dbusID() const; |
33 | + |
34 | + /** Turn the structure into a string without any revision information. |
35 | + This is suitable for writing the AppID to disk. Turn this back into |
36 | + an AppID with find(). This is otherwise not a valid AppID string. */ |
37 | + std::string persistentID() const; |
38 | + |
39 | /** Empty constructor for an AppID. Makes coding with them easier, but generally |
40 | there is nothing useful about an empty AppID. */ |
41 | AppID(); |
42 | @@ -98,6 +108,13 @@ |
43 | */ |
44 | AppID(Package pkg, AppName app, Version ver); |
45 | |
46 | + /** Parse a string from DBus and turn it into an AppID. This assumes that |
47 | + the string was originally produced by dbusID(), the result is otherwise |
48 | + undefined. |
49 | + |
50 | + \param dbusid String from a DBus path |
51 | + */ |
52 | + static AppID parseDBusID(const std::string& dbusid); |
53 | /** Parse a string and turn it into an AppID. This assumes that the string is |
54 | in the form: $(package)_$(app)_$(version) and will return an empty AppID |
55 | if not. |
56 | @@ -106,7 +123,7 @@ |
57 | */ |
58 | static AppID parse(const std::string& appid); |
59 | /** Find is a more tollerant version of parse(), it handles legacy applications, |
60 | - short AppIDs ($package_$app) and other forms of that are in common usage. |
61 | + persistent IDs and other forms of that are in common usage. |
62 | It can be used, but is slower than parse() if you've got well formed data |
63 | already. |
64 | |
65 | @@ -117,7 +134,7 @@ |
66 | */ |
67 | static AppID find(const std::string& sappid); |
68 | /** Find is a more tollerant version of parse(), it handles legacy applications, |
69 | - short AppIDs ($package_$app) and other forms of that are in common usage. |
70 | + persistent IDs and other forms of that are in common usage. |
71 | It can be used, but is slower than parse() if you've got well formed data |
72 | already. |
73 | |
74 | |
75 | === modified file 'libubuntu-app-launch/application.cpp' |
76 | --- libubuntu-app-launch/application.cpp 2017-02-25 15:58:27 +0000 |
77 | +++ libubuntu-app-launch/application.cpp 2017-03-30 13:56:23 +0000 |
78 | @@ -28,7 +28,9 @@ |
79 | #include "registry.h" |
80 | |
81 | #include <functional> |
82 | +#include <iomanip> |
83 | #include <iostream> |
84 | +#include <locale> |
85 | #include <regex> |
86 | |
87 | namespace ubuntu |
88 | @@ -153,6 +155,66 @@ |
89 | return package.value() + "_" + appname.value() + "_" + version.value(); |
90 | } |
91 | |
92 | +std::string AppID::persistentID() const |
93 | +{ |
94 | + if (package.value().empty()) |
95 | + { |
96 | + if (appname.value().empty()) |
97 | + { |
98 | + return {}; |
99 | + } |
100 | + else |
101 | + { |
102 | + return appname.value(); |
103 | + } |
104 | + } |
105 | + |
106 | + return package.value() + "_" + appname.value(); |
107 | +} |
108 | + |
109 | +std::string AppID::dbusID() const |
110 | +{ |
111 | + std::string bytes = operator std::string(); |
112 | + std::string encoded; |
113 | + |
114 | + for (size_t i = 0; i < bytes.size(); ++i) { |
115 | + char chr = bytes[i]; |
116 | + |
117 | + if (std::isalpha(chr, std::locale::classic()) || |
118 | + (std::isdigit(chr, std::locale::classic()) && i != 0)) { |
119 | + encoded += chr; |
120 | + } else { |
121 | + std::ostringstream hex; |
122 | + hex << std::setw(2) << std::setfill('0') << std::hex; |
123 | + hex << int(chr); |
124 | + encoded += '_' + hex.str(); |
125 | + } |
126 | + } |
127 | + |
128 | + return encoded; |
129 | +} |
130 | + |
131 | +AppID AppID::parseDBusID(const std::string& dbusid) |
132 | +{ |
133 | + std::string decoded; |
134 | + |
135 | + for (size_t i = 0; i < dbusid.size(); ++i) { |
136 | + char chr = dbusid[i]; |
137 | + |
138 | + if (chr == '_' && i + 2 < dbusid.size()) { |
139 | + int result; |
140 | + std::istringstream hex(dbusid.substr(i + 1, 2)); |
141 | + hex >> std::hex >> result; |
142 | + decoded += (char)result; |
143 | + i += 2; |
144 | + } else { |
145 | + decoded += chr; |
146 | + } |
147 | + } |
148 | + |
149 | + return parse(decoded); |
150 | +} |
151 | + |
152 | bool operator==(const AppID& a, const AppID& b) |
153 | { |
154 | return a.package.value() == b.package.value() && a.appname.value() == b.appname.value() && |
155 | |
156 | === modified file 'libubuntu-app-launch/helper.cpp' |
157 | --- libubuntu-app-launch/helper.cpp 2017-03-20 12:28:10 +0000 |
158 | +++ libubuntu-app-launch/helper.cpp 2017-03-30 13:56:23 +0000 |
159 | @@ -277,7 +277,7 @@ |
160 | skel); |
161 | |
162 | /* Find a path to export on */ |
163 | - auto dbusAppid = dbusSafe(std::string{appid}); |
164 | + auto dbusAppid = appid.dbusID(); |
165 | std::string path; |
166 | |
167 | while (path.empty()) |
168 | @@ -319,13 +319,6 @@ |
169 | timeout = timeoutin; |
170 | } |
171 | |
172 | - static std::string dbusSafe(const std::string& in) |
173 | - { |
174 | - std::string out = in; |
175 | - std::transform(out.begin(), out.end(), out.begin(), [](char in) { return std::isalpha(in) ? in : '_'; }); |
176 | - return out; |
177 | - } |
178 | - |
179 | bool proxyCb(GDBusMethodInvocation* invocation) |
180 | { |
181 | if (mirfd.get() == 0) |
182 | |
183 | === modified file 'tests/libual-cpp-test.cc' |
184 | --- tests/libual-cpp-test.cc 2017-03-20 15:17:02 +0000 |
185 | +++ tests/libual-cpp-test.cc 2017-03-30 13:56:23 +0000 |
186 | @@ -586,6 +586,30 @@ |
187 | return; |
188 | } |
189 | |
190 | +TEST_F(LibUAL, DBusID) |
191 | +{ |
192 | + auto id = ubuntu::app_launch::AppID::parse("container-name_test_0.0"); |
193 | + ASSERT_FALSE(id.empty()); |
194 | + EXPECT_EQ("container_2dname_5ftest_5f0_2e0", id.dbusID()); |
195 | + EXPECT_FALSE(ubuntu::app_launch::AppID::valid(id.dbusID())); |
196 | + |
197 | + auto parsed = ubuntu::app_launch::AppID::parseDBusID(id.dbusID()); |
198 | + ASSERT_FALSE(parsed.empty()); |
199 | + EXPECT_EQ(id, parsed); |
200 | +} |
201 | + |
202 | +TEST_F(LibUAL, PersistentID) |
203 | +{ |
204 | + auto id = ubuntu::app_launch::AppID::parse("container-name_test_0.0"); |
205 | + ASSERT_FALSE(id.empty()); |
206 | + EXPECT_EQ("container-name_test", id.persistentID()); |
207 | + EXPECT_FALSE(ubuntu::app_launch::AppID::valid(id.persistentID())); |
208 | + |
209 | + auto found = ubuntu::app_launch::AppID::find(registry, id.persistentID()); |
210 | + ASSERT_FALSE(found.empty()); |
211 | + EXPECT_EQ(id, found); |
212 | +} |
213 | + |
214 | TEST_F(LibUAL, ApplicationList) |
215 | { |
216 | SnapdMock snapd{LOCAL_SNAPD_TEST_SOCKET, {u8Package, interfaces, u8Package}}; |
FAILED: Continuous integration, rev:296 /jenkins. canonical. com/unity- api-1/job/ lp-ubuntu- app-launch- ci/239/ /jenkins. canonical. com/unity- api-1/job/ build/1736/ console /jenkins. canonical. com/unity- api-1/job/ build-0- fetch/1743 /jenkins. canonical. com/unity- api-1/job/ build-2- binpkg/ arch=amd64, release= xenial+ overlay/ 1518/console /jenkins. canonical. com/unity- api-1/job/ build-2- binpkg/ arch=amd64, release= zesty/1518/ console /jenkins. canonical. com/unity- api-1/job/ build-2- binpkg/ arch=armhf, release= xenial+ overlay/ 1518/console /jenkins. canonical. com/unity- api-1/job/ build-2- binpkg/ arch=armhf, release= zesty/1518/ console /jenkins. canonical. com/unity- api-1/job/ build-2- binpkg/ arch=i386, release= xenial+ overlay/ 1518/console /jenkins. canonical. com/unity- api-1/job/ build-2- binpkg/ arch=i386, release= zesty/1518/ console
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: /jenkins. canonical. com/unity- api-1/job/ lp-ubuntu- app-launch- ci/239/ rebuild
https:/