Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

daemon: look for snap icon in icons directory as fallback #15027

Draft
wants to merge 19 commits into
base: master
Choose a base branch
from

Conversation

olivercalder
Copy link
Member

This PR is based on #15003.

If a snap doesn't ship an icon in meta/gui/icon.*, then look for an icon for the snap in question in the snap icons install directory.

This work is tracked internally by https://warthogs.atlassian.net/browse/SNAPDENG-34437

These new functions, `downloadIconImpl` and `DownloadIcon`, mirror their
non-icon counterparts `downloadImpl` and `Download`, except that because
snap icons are small, simple assets on a fileserver, there is no need
for snap-specific headers, authentication, partial downloads, or
caching.

These will be used in the future in order to download a snap's icon
whenever the new `.snap` blob is downloaded for that snap and linked to
a snap icons directory so that the snapd API can serve snap icons from
local icon files, rather than returning an error if the snap does not
ship an icon at `meta/gui/icon.*`.

Signed-off-by: Oliver Calder <[email protected]>
During the "download-snap" task, download the snap icon as well.

During "link-snap" and "unlink-snap", link/unlink the snap icon from the
downloaded icons pool to the the installed icons directory, managed much
the same way is snap auxinfo. This is because snap icons, like auxinfo,
are not revision-specific. Instead, they reflect the current state of
the snap listing in the snap store.

Lastly, discard the downloaded snap icon when the final revision of the
snap is discarded from disk. We want to ensure that the snap icon
remains in the pool during any situation when it's possible to install
the snap without doing another "download-snap" task, such as via a
revert.

Signed-off-by: Oliver Calder <[email protected]>
The lifecycle of snap icons in the icons pool directory should mirror
that of `.snap` files, and only be cleaned up during `doDiscardSnap`, if
there are no other revisions of the snap present on the system. There is
no need for the `undoDownloadSnap` callback to remove the icon from the
pool, since that would prevent an immediately subsequent `doLinkSnap`
from finding the icon in the directory.

Signed-off-by: Oliver Calder <[email protected]>
…dy linked

It may be useful to revise this behavior in the future, to allow
linkSnapIcon to be idempotent. Otherwise, if a snap icon is already
linked to the icons directory, but a new icon is downloaded, attempting
to link that new icon will fail and the old icon will still be linked.

Signed-off-by: Oliver Calder <[email protected]>
These functions work with snap icons, not app-specific icons.

Signed-off-by: Oliver Calder <[email protected]>
If a snap doesn't ship an icon in `meta/gui/icon.*`, then look for an
icon for the snap in question in the snap icons install directory.

Signed-off-by: Oliver Calder <[email protected]>
@github-actions github-actions bot added the Needs Documentation -auto- Label automatically added which indicates the change needs documentation label Feb 5, 2025
Copy link

codecov bot commented Feb 5, 2025

Codecov Report

Attention: Patch coverage is 68.72428% with 76 lines in your changes missing coverage. Please review.

Please upload report for BASE (master@103b4eb). Learn more about missing BASE report.
Report is 69 commits behind head on master.

Files with missing lines Patch % Lines
store/store_download.go 67.32% 22 Missing and 11 partials ⚠️
overlord/snapstate/icon.go 58.13% 12 Missing and 6 partials ⚠️
overlord/snapstate/handlers.go 70.68% 12 Missing and 5 partials ⚠️
daemon/snap.go 66.66% 2 Missing and 1 partial ⚠️
store/store.go 72.72% 2 Missing and 1 partial ⚠️
logger/logger.go 60.00% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff            @@
##             master   #15027   +/-   ##
=========================================
  Coverage          ?   78.00%           
=========================================
  Files             ?     1143           
  Lines             ?   153486           
  Branches          ?        0           
=========================================
  Hits              ?   119725           
  Misses            ?    26368           
  Partials          ?     7393           
Flag Coverage Δ
unittests 78.00% <68.72%> (?)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link

github-actions bot commented Feb 5, 2025

Wed Feb 5 03:02:27 UTC 2025
The following results are from: https://github.com/canonical/snapd/actions/runs/13147982110

Failures:

Executing:

  • google-core:ubuntu-core-18-64:tests/core/services
  • google:ubuntu-20.04-64:tests/main/interfaces-microstack-support
  • google:ubuntu-24.10-64:tests/main/try
  • google:ubuntu-24.04-64:tests/main/cgroup-devices-v2

Copy link
Contributor

@sergio-costas sergio-costas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a little idea.

if len(found) == 0 {
return ""
if len(found) > 0 {
return found[0]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe it would be better to prioritize .svg over .png, in the case that both do exist?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Needs Documentation -auto- Label automatically added which indicates the change needs documentation
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants