Merge lp:~mterry/ubuntu-app-launch/persistentid into lp:ubuntu-app-launch

Proposed by Michael Terry
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
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...

To post a comment you must log in.
Revision history for this message
unity-api-1-bot (unity-api-1-bot) wrote :
review: Needs Fixing (continuous-integration)
297. By Michael Terry

Drop prototype for removed function

Revision history for this message
Michael Terry (mterry) wrote :

Instead of homegrown escaping, we could use nih_dbus_path?

Revision history for this message
unity-api-1-bot (unity-api-1-bot) wrote :

FAILED: Continuous integration, rev:297
https://jenkins.canonical.com/unity-api-1/job/lp-ubuntu-app-launch-ci/240/
Executed test runs:
    FAILURE: https://jenkins.canonical.com/unity-api-1/job/build/1738/console
    SUCCESS: https://jenkins.canonical.com/unity-api-1/job/build-0-fetch/1745
    SUCCESS: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=amd64,release=xenial+overlay/1520
        deb: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=amd64,release=xenial+overlay/1520/artifact/output/*zip*/output.zip
    FAILURE: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=amd64,release=zesty/1520/console
    SUCCESS: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=armhf,release=xenial+overlay/1520
        deb: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=armhf,release=xenial+overlay/1520/artifact/output/*zip*/output.zip
    FAILURE: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=armhf,release=zesty/1520/console
    SUCCESS: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=i386,release=xenial+overlay/1520
        deb: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=i386,release=xenial+overlay/1520/artifact/output/*zip*/output.zip
    FAILURE: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=i386,release=zesty/1520/console

Click here to trigger a rebuild:
https://jenkins.canonical.com/unity-api-1/job/lp-ubuntu-app-launch-ci/240/rebuild

review: Needs Fixing (continuous-integration)
Revision history for this message
Ted Gould (ted) wrote :

> Instead of homegrown escaping, we could use nih_dbus_path?

We're dropping deps on libnih, so no :-)

Revision history for this message
Ted Gould (ted) wrote :

Slight comment, but glad to get the dbus stuff C++-ified.

Revision history for this message
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

Revision history for this message
Michael Terry (mterry) wrote :

OK fixed to use isalpha and isdigit.

Revision history for this message
unity-api-1-bot (unity-api-1-bot) wrote :

FAILED: Continuous integration, rev:298
https://jenkins.canonical.com/unity-api-1/job/lp-ubuntu-app-launch-ci/252/
Executed test runs:
    FAILURE: https://jenkins.canonical.com/unity-api-1/job/build/1760/console
    SUCCESS: https://jenkins.canonical.com/unity-api-1/job/build-0-fetch/1767
    SUCCESS: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=amd64,release=xenial+overlay/1543
        deb: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=amd64,release=xenial+overlay/1543/artifact/output/*zip*/output.zip
    FAILURE: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=amd64,release=zesty/1543/console
    SUCCESS: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=armhf,release=xenial+overlay/1543
        deb: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=armhf,release=xenial+overlay/1543/artifact/output/*zip*/output.zip
    SUCCESS: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=armhf,release=zesty/1543
        deb: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=armhf,release=zesty/1543/artifact/output/*zip*/output.zip
    SUCCESS: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=i386,release=xenial+overlay/1543
        deb: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=i386,release=xenial+overlay/1543/artifact/output/*zip*/output.zip
    SUCCESS: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=i386,release=zesty/1543
        deb: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=i386,release=zesty/1543/artifact/output/*zip*/output.zip

Click here to trigger a rebuild:
https://jenkins.canonical.com/unity-api-1/job/lp-ubuntu-app-launch-ci/252/rebuild

review: Needs Fixing (continuous-integration)
Revision history for this message
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

Revision history for this message
Michael Terry (mterry) wrote :

OK, restored the i != 0 check.

Revision history for this message
unity-api-1-bot (unity-api-1-bot) wrote :

FAILED: Continuous integration, rev:299
https://jenkins.canonical.com/unity-api-1/job/lp-ubuntu-app-launch-ci/255/
Executed test runs:
    FAILURE: https://jenkins.canonical.com/unity-api-1/job/build/1775/console
    SUCCESS: https://jenkins.canonical.com/unity-api-1/job/build-0-fetch/1782
    SUCCESS: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=amd64,release=xenial+overlay/1558
        deb: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=amd64,release=xenial+overlay/1558/artifact/output/*zip*/output.zip
    FAILURE: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=amd64,release=zesty/1558/console
    SUCCESS: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=armhf,release=xenial+overlay/1558
        deb: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=armhf,release=xenial+overlay/1558/artifact/output/*zip*/output.zip
    FAILURE: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=armhf,release=zesty/1558/console
    SUCCESS: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=i386,release=xenial+overlay/1558
        deb: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=i386,release=xenial+overlay/1558/artifact/output/*zip*/output.zip
    SUCCESS: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=i386,release=zesty/1558
        deb: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=i386,release=zesty/1558/artifact/output/*zip*/output.zip

Click here to trigger a rebuild:
https://jenkins.canonical.com/unity-api-1/job/lp-ubuntu-app-launch-ci/255/rebuild

review: Needs Fixing (continuous-integration)
Revision history for this message
Michael Terry (mterry) wrote :

Is that CI failure related? Doesn't look it to me, but if other branches are passing...

Revision history for this message
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.

review: Needs Fixing
300. By Michael Terry

Merge trunk

301. By Michael Terry

Fix tests now that click apps are gone

302. By Michael Terry

Fix version

Revision history for this message
Michael Terry (mterry) wrote :

Fixed the conflict.

Revision history for this message
unity-api-1-bot (unity-api-1-bot) wrote :

FAILED: Continuous integration, rev:302
https://jenkins.canonical.com/unity-api-1/job/lp-ubuntu-app-launch-ci/283/
Executed test runs:
    FAILURE: https://jenkins.canonical.com/unity-api-1/job/build/1891/console
    SUCCESS: https://jenkins.canonical.com/unity-api-1/job/build-0-fetch/1898
    FAILURE: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=amd64,release=xenial+overlay/1680/console
    SUCCESS: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=amd64,release=zesty/1680
        deb: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=amd64,release=zesty/1680/artifact/output/*zip*/output.zip
    SUCCESS: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=armhf,release=xenial+overlay/1680
        deb: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=armhf,release=xenial+overlay/1680/artifact/output/*zip*/output.zip
    SUCCESS: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=armhf,release=zesty/1680
        deb: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=armhf,release=zesty/1680/artifact/output/*zip*/output.zip
    SUCCESS: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=i386,release=xenial+overlay/1680
        deb: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=i386,release=xenial+overlay/1680/artifact/output/*zip*/output.zip
    FAILURE: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=i386,release=zesty/1680/console

Click here to trigger a rebuild:
https://jenkins.canonical.com/unity-api-1/job/lp-ubuntu-app-launch-ci/283/rebuild

review: Needs Fixing (continuous-integration)
Revision history for this message
Ted Gould (ted) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'debian/changelog'
--- debian/changelog 2017-03-21 03:29:09 +0000
+++ debian/changelog 2017-03-30 13:56:23 +0000
@@ -1,3 +1,9 @@
1ubuntu-app-launch (0.12) UNRELEASED; urgency=medium
2
3 * Bump version for new AppID methods
4
5 -- Michael Terry <mterry@ubuntu.com> Tue, 28 Feb 2017 15:59:05 -0500
6
1ubuntu-app-launch (0.11+17.04.20170321-0ubuntu1) zesty; urgency=medium7ubuntu-app-launch (0.11+17.04.20170321-0ubuntu1) zesty; urgency=medium
28
3 [ Ted Gould ]9 [ Ted Gould ]
410
=== modified file 'libubuntu-app-launch/appid.h'
--- libubuntu-app-launch/appid.h 2016-08-24 21:52:19 +0000
+++ libubuntu-app-launch/appid.h 2017-03-30 13:56:23 +0000
@@ -1,5 +1,5 @@
1/*1/*
2 * Copyright © 2016 Canonical Ltd.2 * Copyright © 2016-2017 Canonical Ltd.
3 *3 *
4 * This program is free software: you can redistribute it and/or modify it4 * This program is free software: you can redistribute it and/or modify it
5 * under the terms of the GNU General Public License version 3, as published5 * under the terms of the GNU General Public License version 3, as published
@@ -82,6 +82,16 @@
82 anyting other than debug messages. */82 anyting other than debug messages. */
83 operator std::string() const;83 operator std::string() const;
8484
85 /** Turn the structure into a string suitable for use in DBus paths.
86 Turn this back into an AppID with parseDBusID(). This is otherwise not
87 a valid AppID string. */
88 std::string dbusID() const;
89
90 /** Turn the structure into a string without any revision information.
91 This is suitable for writing the AppID to disk. Turn this back into
92 an AppID with find(). This is otherwise not a valid AppID string. */
93 std::string persistentID() const;
94
85 /** Empty constructor for an AppID. Makes coding with them easier, but generally95 /** Empty constructor for an AppID. Makes coding with them easier, but generally
86 there is nothing useful about an empty AppID. */96 there is nothing useful about an empty AppID. */
87 AppID();97 AppID();
@@ -98,6 +108,13 @@
98 */108 */
99 AppID(Package pkg, AppName app, Version ver);109 AppID(Package pkg, AppName app, Version ver);
100110
111 /** Parse a string from DBus and turn it into an AppID. This assumes that
112 the string was originally produced by dbusID(), the result is otherwise
113 undefined.
114
115 \param dbusid String from a DBus path
116 */
117 static AppID parseDBusID(const std::string& dbusid);
101 /** Parse a string and turn it into an AppID. This assumes that the string is118 /** Parse a string and turn it into an AppID. This assumes that the string is
102 in the form: $(package)_$(app)_$(version) and will return an empty AppID119 in the form: $(package)_$(app)_$(version) and will return an empty AppID
103 if not.120 if not.
@@ -106,7 +123,7 @@
106 */123 */
107 static AppID parse(const std::string& appid);124 static AppID parse(const std::string& appid);
108 /** Find is a more tollerant version of parse(), it handles legacy applications,125 /** Find is a more tollerant version of parse(), it handles legacy applications,
109 short AppIDs ($package_$app) and other forms of that are in common usage.126 persistent IDs and other forms of that are in common usage.
110 It can be used, but is slower than parse() if you've got well formed data127 It can be used, but is slower than parse() if you've got well formed data
111 already.128 already.
112129
@@ -117,7 +134,7 @@
117 */134 */
118 static AppID find(const std::string& sappid);135 static AppID find(const std::string& sappid);
119 /** Find is a more tollerant version of parse(), it handles legacy applications,136 /** Find is a more tollerant version of parse(), it handles legacy applications,
120 short AppIDs ($package_$app) and other forms of that are in common usage.137 persistent IDs and other forms of that are in common usage.
121 It can be used, but is slower than parse() if you've got well formed data138 It can be used, but is slower than parse() if you've got well formed data
122 already.139 already.
123140
124141
=== modified file 'libubuntu-app-launch/application.cpp'
--- libubuntu-app-launch/application.cpp 2017-02-25 15:58:27 +0000
+++ libubuntu-app-launch/application.cpp 2017-03-30 13:56:23 +0000
@@ -28,7 +28,9 @@
28#include "registry.h"28#include "registry.h"
2929
30#include <functional>30#include <functional>
31#include <iomanip>
31#include <iostream>32#include <iostream>
33#include <locale>
32#include <regex>34#include <regex>
3335
34namespace ubuntu36namespace ubuntu
@@ -153,6 +155,66 @@
153 return package.value() + "_" + appname.value() + "_" + version.value();155 return package.value() + "_" + appname.value() + "_" + version.value();
154}156}
155157
158std::string AppID::persistentID() const
159{
160 if (package.value().empty())
161 {
162 if (appname.value().empty())
163 {
164 return {};
165 }
166 else
167 {
168 return appname.value();
169 }
170 }
171
172 return package.value() + "_" + appname.value();
173}
174
175std::string AppID::dbusID() const
176{
177 std::string bytes = operator std::string();
178 std::string encoded;
179
180 for (size_t i = 0; i < bytes.size(); ++i) {
181 char chr = bytes[i];
182
183 if (std::isalpha(chr, std::locale::classic()) ||
184 (std::isdigit(chr, std::locale::classic()) && i != 0)) {
185 encoded += chr;
186 } else {
187 std::ostringstream hex;
188 hex << std::setw(2) << std::setfill('0') << std::hex;
189 hex << int(chr);
190 encoded += '_' + hex.str();
191 }
192 }
193
194 return encoded;
195}
196
197AppID AppID::parseDBusID(const std::string& dbusid)
198{
199 std::string decoded;
200
201 for (size_t i = 0; i < dbusid.size(); ++i) {
202 char chr = dbusid[i];
203
204 if (chr == '_' && i + 2 < dbusid.size()) {
205 int result;
206 std::istringstream hex(dbusid.substr(i + 1, 2));
207 hex >> std::hex >> result;
208 decoded += (char)result;
209 i += 2;
210 } else {
211 decoded += chr;
212 }
213 }
214
215 return parse(decoded);
216}
217
156bool operator==(const AppID& a, const AppID& b)218bool operator==(const AppID& a, const AppID& b)
157{219{
158 return a.package.value() == b.package.value() && a.appname.value() == b.appname.value() &&220 return a.package.value() == b.package.value() && a.appname.value() == b.appname.value() &&
159221
=== modified file 'libubuntu-app-launch/helper.cpp'
--- libubuntu-app-launch/helper.cpp 2017-03-20 12:28:10 +0000
+++ libubuntu-app-launch/helper.cpp 2017-03-30 13:56:23 +0000
@@ -277,7 +277,7 @@
277 skel);277 skel);
278278
279 /* Find a path to export on */279 /* Find a path to export on */
280 auto dbusAppid = dbusSafe(std::string{appid});280 auto dbusAppid = appid.dbusID();
281 std::string path;281 std::string path;
282282
283 while (path.empty())283 while (path.empty())
@@ -319,13 +319,6 @@
319 timeout = timeoutin;319 timeout = timeoutin;
320 }320 }
321321
322 static std::string dbusSafe(const std::string& in)
323 {
324 std::string out = in;
325 std::transform(out.begin(), out.end(), out.begin(), [](char in) { return std::isalpha(in) ? in : '_'; });
326 return out;
327 }
328
329 bool proxyCb(GDBusMethodInvocation* invocation)322 bool proxyCb(GDBusMethodInvocation* invocation)
330 {323 {
331 if (mirfd.get() == 0)324 if (mirfd.get() == 0)
332325
=== modified file 'tests/libual-cpp-test.cc'
--- tests/libual-cpp-test.cc 2017-03-20 15:17:02 +0000
+++ tests/libual-cpp-test.cc 2017-03-30 13:56:23 +0000
@@ -586,6 +586,30 @@
586 return;586 return;
587}587}
588588
589TEST_F(LibUAL, DBusID)
590{
591 auto id = ubuntu::app_launch::AppID::parse("container-name_test_0.0");
592 ASSERT_FALSE(id.empty());
593 EXPECT_EQ("container_2dname_5ftest_5f0_2e0", id.dbusID());
594 EXPECT_FALSE(ubuntu::app_launch::AppID::valid(id.dbusID()));
595
596 auto parsed = ubuntu::app_launch::AppID::parseDBusID(id.dbusID());
597 ASSERT_FALSE(parsed.empty());
598 EXPECT_EQ(id, parsed);
599}
600
601TEST_F(LibUAL, PersistentID)
602{
603 auto id = ubuntu::app_launch::AppID::parse("container-name_test_0.0");
604 ASSERT_FALSE(id.empty());
605 EXPECT_EQ("container-name_test", id.persistentID());
606 EXPECT_FALSE(ubuntu::app_launch::AppID::valid(id.persistentID()));
607
608 auto found = ubuntu::app_launch::AppID::find(registry, id.persistentID());
609 ASSERT_FALSE(found.empty());
610 EXPECT_EQ(id, found);
611}
612
589TEST_F(LibUAL, ApplicationList)613TEST_F(LibUAL, ApplicationList)
590{614{
591 SnapdMock snapd{LOCAL_SNAPD_TEST_SOCKET, {u8Package, interfaces, u8Package}};615 SnapdMock snapd{LOCAL_SNAPD_TEST_SOCKET, {u8Package, interfaces, u8Package}};

Subscribers

People subscribed via source and target branches