-
Notifications
You must be signed in to change notification settings - Fork 599
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: move auxinfo functions to snapstate backend with metadata helpers #15051
Merged
bboozzoo
merged 14 commits into
canonical:master
from
olivercalder:backend-metadata-management
Feb 14, 2025
Merged
Changes from 13 commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
2aaf366
o/snapstate: move auxinfo functions to snapstate backend with metadat…
olivercalder ea63622
o/snapstate: only discard store metadata if no other instances present
olivercalder c21b939
o/snapstate: remove unnecessary check for non-empty snapID before ins…
olivercalder f7fefa1
o/snapstate: make InstallStoreMetadata return an undo callback
olivercalder 06c89d8
o/snapstate/backend: disambiguate metadata management test cases
olivercalder 025b681
o/snapstate: revise comments around handling of empty snap id in inst…
olivercalder 2e56a77
o/snapstate: use LinkContext in InstallStoreMetadata instead of indiv…
olivercalder 92b4513
o/snapstate: pass aux store info by value, not pointer
olivercalder e590adc
o/snapstate: move store metadata calls to within backend methods
olivercalder 5f12e92
Revert "o/snapstate: move store metadata calls to within backend meth…
olivercalder 066392d
o/snapstate: pass link context into DiscardStoreMetadata
olivercalder 37e95bf
o/snapstate{,/backend}: split metadata removal helper into uninstall …
olivercalder bc79190
o/snapstate: remove outdated comment
olivercalder b16c644
o/snapstate/backend: DiscardStoreMetadata directly removes metadata
olivercalder File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
// -*- Mode: Go; indent-tabs-mode: t -*- | ||
|
||
/* | ||
* Copyright (C) 2025 Canonical Ltd | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License version 3 as | ||
* published by the Free Software Foundation. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
* | ||
*/ | ||
|
||
package backend | ||
|
||
// InstallStoreMetadata saves revision-agnostic metadata to disk for the snap | ||
// with the given snap ID. At the moment, this metadata includes auxiliary | ||
// store information. Returns a closure to undo the function's actions, | ||
// depending on whether it's a first install or if there are other instances. | ||
func InstallStoreMetadata(snapID string, aux AuxStoreInfo, linkCtx LinkContext) (undo func(), err error) { | ||
if snapID == "" { | ||
return func() {}, nil | ||
} | ||
if err := keepAuxStoreInfo(snapID, aux); err != nil { | ||
return nil, err | ||
} | ||
// TODO: install other types of revision-agnostic metadata | ||
return func() { | ||
UninstallStoreMetadata(snapID, linkCtx) | ||
}, nil | ||
} | ||
|
||
// UninstallStoreMetadata removes revision-agnostic metadata from disk for the | ||
// snap with the given snap ID. At the moment, this metadata includes auxiliary | ||
// store information. The given linkCtx governs what metadata is removed and | ||
// what is preserved. | ||
func UninstallStoreMetadata(snapID string, linkCtx LinkContext) error { | ||
if linkCtx.HasOtherInstances || snapID == "" { | ||
return nil | ||
} | ||
if linkCtx.FirstInstall { | ||
// only discard aux store info if there are no other revision of the | ||
// snap present, in case we want to roll-back the discard, and need the | ||
// auxinfo on disk to re-populate an old snap.Info. This might occur if | ||
// e.g. we unlinked the snap and now need to undoUnlinkSnap. | ||
if err := discardAuxStoreInfo(snapID); err != nil { | ||
return err | ||
} | ||
} | ||
// TODO: discard other types of revision-agnostic metadata | ||
return nil | ||
} | ||
|
||
// DiscardStoreMetadata removes revision-agnostic metadata from disk for the | ||
// snap with the given snap ID, and is intended to be called when the final | ||
// revision of that snap is being discarded. At the moment, this only calls | ||
// UninstallStoreMetadata. If hasOtherInstances is false, this function does | ||
// nothing, as another instance of the same snap may still require this | ||
// metadata. | ||
func DiscardStoreMetadata(snapID string, hasOtherInstances bool) error { | ||
if hasOtherInstances || snapID == "" { | ||
return nil | ||
} | ||
linkCtx := LinkContext{ | ||
// since the final revision is being discarded, we're effectively | ||
// removing the "first" install of the snap | ||
FirstInstall: true, | ||
HasOtherInstances: hasOtherInstances, | ||
} | ||
if err := UninstallStoreMetadata(snapID, linkCtx); err != nil { | ||
return err | ||
} | ||
// TODO: discard other types of revision-agnostic metadata which should be | ||
// removed when the final revision of the snap is discarded | ||
return nil | ||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the reuse here doesn't seem very valuable to me, better to just call discardAuxStoreInfo(snapID)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure, good point, probably easier to unconditionally remove auxinfo (and icon in the future) than construct a special
LinkContext
to getUninstallStoreMetadata
to do what we want.