9 "github.com/mjl-/mox/moxvar"
10 "github.com/mjl-/mox/updates"
13// StoreLastKnown stores the the last known version. Future update checks compare
14// against it, or the currently running version, whichever is newer.
15func StoreLastKnown(v updates.Version) error {
16 return os.WriteFile(DataDirPath("lastknownversion"), []byte(v.String()), 0660)
19// LastKnown returns the last known version that has been mentioned in an update
20// email, or the current application.
21func LastKnown() (current, lastknown updates.Version, mtime time.Time, rerr error) {
22 curv, curerr := updates.ParseVersion(moxvar.Version)
24 p := DataDirPath("lastknownversion")
30 vbuf, err := os.ReadFile(p)
31 if err != nil && !os.IsNotExist(err) {
32 return curv, updates.Version{}, mtime, err
35 lastknown, lasterr := updates.ParseVersion(strings.TrimSpace(string(vbuf)))
37 if curerr == nil && lasterr == nil {
38 if curv.After(lastknown) {
39 return curv, curv, mtime, nil
41 return curv, lastknown, mtime, nil
42 } else if curerr == nil {
43 return curv, curv, mtime, nil
44 } else if lasterr == nil {
45 return curv, lastknown, mtime, nil
47 if moxvar.Version == "(devel)" {
48 return curv, updates.Version{}, mtime, fmt.Errorf("development version")
50 return curv, updates.Version{}, mtime, fmt.Errorf("parsing version: %w", err)