Skip to content

Commit

Permalink
appstream: support legacy ids without desktop suffix
Browse files Browse the repository at this point in the history
If no launchables are found and component id does not have `.desktop`
suffix, use the component id + .desktop as possible desktop file id.

This is not required per the spec, but some applications such
as Foliate use this and other tools such as Flatpak support it.

LP: #1778546
  • Loading branch information
merlijn-sebrechts committed Oct 21, 2019
1 parent 1cc980d commit dab126a
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
7 changes: 5 additions & 2 deletions snapcraft/extractors/appstream.py
Expand Up @@ -87,8 +87,11 @@ def extract(relpath: str, *, workdir: str) -> ExtractedMetadata:
desktop_file_ids = _get_desktop_file_ids_from_nodes(dom.findall("launchable"))
# if there are no launchables, use the appstream id to take into
# account the legacy appstream definitions
if common_id and common_id.endswith(".desktop") and not desktop_file_ids:
desktop_file_ids.append(common_id)
if common_id and not desktop_file_ids:
if common_id.endswith(".desktop"):
desktop_file_ids.append(common_id)
else:
desktop_file_ids.append(common_id + ".desktop")

for desktop_file_id in desktop_file_ids:
desktop_file_path = _desktop_file_id_to_path(desktop_file_id, workdir=workdir)
Expand Down
20 changes: 20 additions & 0 deletions tests/unit/extractors/test_appstream.py
Expand Up @@ -557,6 +557,26 @@ def test_appstream_with_launchable(self):
extracted.get_desktop_file_paths(), Equals([self.desktop_file_path])
)

def test_appstream_no_desktop_suffix(self):
with open("foo.metainfo.xml", "w") as f:
f.write(
textwrap.dedent(
"""\
<?xml version="1.0" encoding="UTF-8"?>
<component type="desktop">
<id>com.example.test-app</id>
</component>"""
)
)

_create_desktop_file(self.desktop_file_path)

extracted = appstream.extract("foo.metainfo.xml", workdir=".")

self.assertThat(
extracted.get_desktop_file_paths(), Equals([self.desktop_file_path])
)


class AppstreamMultipleLaunchableTestCase(unit.TestCase):
def test_appstream_with_multiple_launchables(self):
Expand Down

0 comments on commit dab126a

Please sign in to comment.