-
Notifications
You must be signed in to change notification settings - Fork 66
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(SelfUpdate): added check for version being out of date
while we're here, might as well use an ipns dnslink entry to check if the qri verion if out of date by comparing a hard-coded version of the 2-n back version of qri against the hardcoded hash of the 1-n back version stored within the app itself.
- Loading branch information
Showing
2 changed files
with
50 additions
and
0 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package core | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
|
||
namesys "gx/ipfs/QmViBzgruNUoLNBnXcx8YWbDNwV8MNGEGKkLo6JGetygdw/go-ipfs/namesys" | ||
) | ||
|
||
/* | ||
* self-updating checks IPNS entry that represents the desired hash of the previous version of | ||
* this program, which is the result of adding the complied binary of this program to IPFS. | ||
* If the returned value of a lookup differs, we have a version mismatch, and need to perform | ||
* an update. | ||
* | ||
* In the future we'll do this automatically, but for now we can at least warn users that they need | ||
* to update their version | ||
*/ | ||
|
||
// previousVersion is a hard-coded reference the gx "lastpubver" file of the previous release | ||
const previousVersion = "/ipfs/QmcXZCLAgUdvXpt1fszjNGVGn6WnhsrJahkQXY3JJqxUWJ" | ||
|
||
// prevIPNSName is the dnslink address to check for version agreement | ||
const prevIPNSName = "/ipns/cli.previous.qri.io" | ||
|
||
// ErrUpdateRequired means this version of qri is out of date | ||
var ErrUpdateRequired = fmt.Errorf("update required") | ||
|
||
// CheckVersion uses a name resolver to lookup prevIPNSName, checking if the hard-coded previousVersion | ||
// and the returned lookup match. If they don't, CheckVersion returns ErrUpdateRequired | ||
func CheckVersion(ctx context.Context, res namesys.Resolver) error { | ||
p, err := res.Resolve(ctx, prevIPNSName) | ||
if err != nil { | ||
return fmt.Errorf("error resolving name: %s", err.Error()) | ||
} | ||
|
||
if p.String() != previousVersion { | ||
return ErrUpdateRequired | ||
} | ||
return nil | ||
} |