version/mkversion: enforce synology versions within int32 range

Synology requires version numbers are within int32 range. This
change updates the version logic to keep things closer within the
range, and errors on building when the range is exceeded.

Updates #cleanup

Signed-off-by: Sonia Appasamy <sonia@tailscale.com>
This commit is contained in:
Sonia Appasamy 2024-03-08 12:26:38 -05:00 committed by Sonia Appasamy
parent 74e33b9c50
commit 54e52532eb
2 changed files with 18 additions and 3 deletions

View File

@ -9,6 +9,7 @@ import (
"bytes"
"compress/gzip"
"embed"
"errors"
"fmt"
"io"
"io/fs"
@ -42,7 +43,8 @@ func (t *target) Build(b *dist.Build) ([]string, error) {
}
func (t *target) buildSPK(b *dist.Build, inner *innerPkg) ([]string, error) {
filename := fmt.Sprintf("tailscale-%s-%s-%d-dsm%d.spk", t.filenameArch, b.Version.Short, b.Version.Synology[t.dsmMajorVersion], t.dsmMajorVersion)
synoVersion := b.Version.Synology[t.dsmMajorVersion]
filename := fmt.Sprintf("tailscale-%s-%s-%d-dsm%d.spk", t.filenameArch, b.Version.Short, synoVersion, t.dsmMajorVersion)
out := filepath.Join(b.Out, filename)
if t.packageCenter {
log.Printf("Building %s (for package center)", filename)
@ -50,6 +52,14 @@ func (t *target) buildSPK(b *dist.Build, inner *innerPkg) ([]string, error) {
log.Printf("Building %s (for sideloading)", filename)
}
if synoVersion > 2147483647 {
// Synology requires that version number is within int32 range.
// Erroring here if we create a build with a higher version.
// In this case, we'll want to adjust the VersionInfo.Synology logic in
// the mkversion package.
return nil, errors.New("syno version exceeds int32 range")
}
privFile := fmt.Sprintf("privilege-dsm%d", t.dsmMajorVersion)
if t.packageCenter && t.dsmMajorVersion == 7 {
privFile += ".for-package-center"

View File

@ -251,8 +251,13 @@ func mkOutput(v verInfo) (VersionInfo, error) {
GitDate: fmt.Sprintf("%s", v.date),
Track: track,
Synology: map[int]int64{
6: 6*1_000_000_000 + int64(v.major-1)*1_000_000 + int64(v.minor)*1_000 + int64(v.patch),
7: 7*1_000_000_000 + int64(v.major-1)*1_000_000 + int64(v.minor)*1_000 + int64(v.patch),
// Synology requires that version numbers be in a specific format.
// Builds with version numbers that don't start with "60" or "70" will fail,
// and the full version number must be within int32 range.
// So, we do the following mapping from our Tailscale version to Synology version,
// giving major version three decimal places, minor version three, and patch two.
6: 6*100_000_000 + int64(v.major-1)*1_000_000 + int64(v.minor)*1_000 + int64(v.patch),
7: 7*100_000_000 + int64(v.major-1)*1_000_000 + int64(v.minor)*1_000 + int64(v.patch),
},
}