Pre-refresh hook: can we determine the upgrade version?

I have a check to compare versions. If the user is trying to downgrade, or skip a major version, it’s something the software in my snap doesn’t support. I have a post-refresh hook doing this comparison right now; I save the old $SNAP_VERSION with snapctl set while it’s running, then I compare it to $SNAP_VERSION in the post-refresh hook. If it looks unsupported, the hook exits non-zero and the refresh fails, rolling back to the old revision.

That works nicely, but it seems like it’s more work than necessary. The refresh very nearly is complete (old services are down, profiles are created) by the time the snap realizes it’s not going to work and rolls back. In an ideal world I could do this check in the pre-refresh hook of the existing snap: if I can take a peek at the SNAP_VERSION that we’re about to upgrade to, I could halt the upgrade before it even really begins, without any negative side effect for the services.

1 Like