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

o/snapstate: download, link, unlink, and discard snap icon in snapstate handlers #15070

Open
wants to merge 9 commits into
base: master
Choose a base branch
from

Conversation

olivercalder
Copy link
Member

This PR is based on #15051, and replaces #15003.

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 installed icons directory. Do this by adding snap icon management helpers, and calling them from the store metadata helpers in the backend.

Lastly, discard the downloaded snap icon when the final revision of the snap is discarded from disk (and there are no other instances). 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.

This PR is tracked internally by https://warthogs.atlassian.net/browse/SNAPDENG-34436

@olivercalder olivercalder changed the title o/snapstate: download, link, unlink, and discard snap icon in snapstate helpers o/snapstate: download, link, unlink, and discard snap icon in snapstate handlers Feb 13, 2025
Copy link

github-actions bot commented Feb 13, 2025

Wed Feb 19 16:19:29 UTC 2025
The following results are from: https://github.com/canonical/snapd/actions/runs/13414511928

Failures:

Executing:

  • google:ubuntu-20.04-64:tests/main/lxd:snapd_cgroup_both
  • google:ubuntu-20.04-64:tests/main/preseed-core20
  • google:ubuntu-24.04-64:tests/main/progress

Copy link

codecov bot commented Feb 13, 2025

Codecov Report

Attention: Patch coverage is 36.36364% with 56 lines in your changes missing coverage. Please review.

Project coverage is 78.06%. Comparing base (a272aac) to head (33e02b0).
Report is 23 commits behind head on master.

Files with missing lines Patch % Lines
overlord/snapstate/backend/icon.go 37.20% 18 Missing and 9 partials ⚠️
overlord/snapstate/backend/metadata.go 11.11% 12 Missing and 4 partials ⚠️
overlord/snapstate/handlers.go 64.70% 4 Missing and 2 partials ⚠️
overlord/snapstate/backend/aux_store_info.go 0.00% 5 Missing ⚠️
store/storetest/storetest.go 0.00% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master   #15070      +/-   ##
==========================================
- Coverage   78.07%   78.06%   -0.02%     
==========================================
  Files        1182     1185       +3     
  Lines      157743   157993     +250     
==========================================
+ Hits       123154   123332     +178     
- Misses      26943    26994      +51     
- Partials     7646     7667      +21     
Flag Coverage Δ
unittests 78.06% <36.36%> (-0.02%) ⬇️

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.

During `InstallStoreMetadata`, link snap icon from the icons download
pool to the icons install directory.

During `UninstallStoreMetadata`, remove the linked icon from the icons
install directory, if it exists there.

During `DiscardStoreMetadata`, remove the linked icon from both the
icons install directory and the icons download pool, if it exists there.

Signed-off-by: Oliver Calder <[email protected]>
@olivercalder olivercalder force-pushed the snap-icons-metadata-management branch from 54c4013 to e7b453f Compare February 14, 2025 16:27
Copy link
Contributor

@bboozzoo bboozzoo left a comment

Choose a reason for hiding this comment

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

looks good, mostly comments about logging & errors

overlord/snapstate/backend/metadata.go Outdated Show resolved Hide resolved
overlord/snapstate/backend/icon.go Outdated Show resolved Hide resolved
overlord/snapstate/backend/icon.go Outdated Show resolved Hide resolved
overlord/snapstate/backend/icon.go Outdated Show resolved Hide resolved
overlord/snapstate/backend/icon.go Outdated Show resolved Hide resolved
overlord/snapstate/backend/metadata.go Outdated Show resolved Hide resolved
overlord/snapstate/backend/metadata.go Outdated Show resolved Hide resolved
overlord/snapstate/backend/metadata.go Outdated Show resolved Hide resolved
iconURL = resultIconURL
}

ctx := tomb.Context(nil) // XXX: should this be a real context?
Copy link
Contributor

Choose a reason for hiding this comment

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

you mean for e.g. context.Background() as a parent?

AFAIU we want the 'tomb' wrapped context as it allows us to detect someone calling Kill() on the associated tomb, and thus allows for the download to be interrupted.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, I was thinking context.Background(). But it previously had nil passed as the ctx parameter directly, so I'm not sure what's correct. Would this work?

Suggested change
ctx := tomb.Context(nil) // XXX: should this be a real context?
ctx := tomb.Context(context.Background())

overlord/snapstate/handlers.go Outdated Show resolved Hide resolved
Copy link
Collaborator

@pedronis pedronis left a comment

Choose a reason for hiding this comment

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

thanks, did a pass

overlord/snapstate/backend_test.go Show resolved Hide resolved
overlord/snapstate/handlers.go Outdated Show resolved Hide resolved
@@ -753,17 +755,53 @@ func (m *SnapManager) doDownloadSnap(t *state.Task, tomb *tomb.Tomb) error {
if err != nil {
return err
}

// Re-compute icon download filepath and URL if the result info has the
Copy link
Collaborator

Choose a reason for hiding this comment

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

this is a very old compatibility path I'm not sure we should worry adding icon support here

Copy link
Collaborator

@pedronis pedronis left a comment

Choose a reason for hiding this comment

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

thank you

Copy link
Contributor

@bboozzoo bboozzoo left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Member

@andrewphelpsj andrewphelpsj left a comment

Choose a reason for hiding this comment

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

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants