Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
o/snapstate: move auxinfo functions to snapstate backend with metadat…
…a helpers (#15051) * o/snapstate: move auxinfo functions to snapstate backend with metadata helpers Signed-off-by: Oliver Calder <[email protected]> * o/snapstate: only discard store metadata if no other instances present Since store metadata is not specific to any particular revision or instance of a snap, it should not be removed if there are other instances of the snap still present. By making `hasOtherInstances` a parameter to `DiscardStoreMetadata`, callers are encouraged to compute and check `hasOtherInstances` beforehand, thus avoiding accidentally removing metadata which is expected for another instance of the same snap. Signed-off-by: Oliver Calder <[email protected]> * o/snapstate: remove unnecessary check for non-empty snapID before installing metadata The `keepAuxStoreInfo` helper was already a no-op if `snapID == ""`, so remove the additional check in the calling handler. Additionally, make the backend store metadata helpers explicitly return `nil` early if `snapID` is `""`, rather than relying on all functions called within to guarantee this. Signed-off-by: Oliver Calder <[email protected]> * o/snapstate: make InstallStoreMetadata return an undo callback Signed-off-by: Oliver Calder <[email protected]> * o/snapstate/backend: disambiguate metadata management test cases Signed-off-by: Oliver Calder <[email protected]> * o/snapstate: revise comments around handling of empty snap id in install handler Signed-off-by: Oliver Calder <[email protected]> * o/snapstate: use LinkContext in InstallStoreMetadata instead of individual flags Signed-off-by: Oliver Calder <[email protected]> * o/snapstate: pass aux store info by value, not pointer Signed-off-by: Oliver Calder <[email protected]> * o/snapstate: move store metadata calls to within backend methods Move `installStoreMetadata` call from the snapstate handler into the backend `LinkSnap` method call, and move `uninstallStoreMetadata` into `UnlinkSnap`. This reduces the complexity of the snapstate handlers. Since `doDiscardSnap` still needs to discard store metadata if there are no other revisions/instances of the snap present, and it is not inherently associated with a particular install/uninstall operation, there is an additional new metadata helper which, instead of taking a `LinkContext`, simply takes a `hasOtherInstances` bool, and uses it to construct a `LinkContext` and then call `uninstallStoreMetadata`. Auxiliary store info is removed regardless of whether `UnlinkSnap` or `doDiscardSnap` are the callers, but other store metadata (such as cached snap icons) may behave differently, so this wrapper will enable this distinction in the future. One important note: auxinfo for a snap should not be removed unless there are no other revisions of the snap present, because in case the unlink snap is reverted, `undoUnlinkSnap` needs to read the auxinfo from disk in order to populate `oldInfo`, so it can be re-linked. Signed-off-by: Oliver Calder <[email protected]> * Revert "o/snapstate: move store metadata calls to within backend methods" This reverts commit e590adc. Since `backend.LinkSnap` is about a particular revision but the metadata is revision-agnostic, and the requirement of discarding metadata manually in `doDiscardSnap` means it's probably clearer to leave the metadata calls all within the snapstate handlers, not backend methods. Signed-off-by: Oliver Calder <[email protected]> * o/snapstate: pass link context into DiscardStoreMetadata Some store metadata should only be removed if there are no other revisions of the snap present, but others may need to be removed regardless. By passing a `LinkContext` including both `FirstInstall` and `HasOtherInstances`, the function can decide for itself what metadata should be discarded, and what should be preserved, rather than the caller being responsible for this. As such, moved calls to `DiscardStoreMetadata` out of some checks for the presence of other revisions. This also means that the undo closure returned by `InstallStoreMetadata` can simply call `DiscardStoreMetadata`, without any additional checks. Signed-off-by: Oliver Calder <[email protected]> * o/snapstate{,/backend}: split metadata removal helper into uninstall and discard When a snap is being unlinked or a link is being undone, the snapstate handler should call `UnlinkStoreMetadata`, which takes a `LinkContext` and checks whether there are other revisions of the snap present. When the final revision of a snap is being discarded, the snapstate handler should call `DiscardStoreMetadata`, which takes a `hasOtherInstances bool` and assumes that there are no other revisions of that instance of the snap present. At the moment, the latter simply calls the former, but in the future, other store metadata which should be handled differently during unlink and discard can be handled appropriately. Signed-off-by: Oliver Calder <[email protected]> * o/snapstate: remove outdated comment Signed-off-by: Oliver Calder <[email protected]> * o/snapstate/backend: DiscardStoreMetadata directly removes metadata Signed-off-by: Oliver Calder <[email protected]> --------- Signed-off-by: Oliver Calder <[email protected]>
- Loading branch information