all: Add build constants for runtime.GOOS comparisons (#8442)

all: Add package runtimeos for runtime.GOOS comparisons

I grew tired of hand written string comparisons. This adds generated
constants for the GOOS values, and predefined Is$OS constants that can
be iffed on. In a couple of places I rewrote trivial switch:es to if:s,
and added Illumos where we checked for Solaris (because they are
effectively the same, and if we're going to target one of them that
would be Illumos...).
This commit is contained in:
Jakob Borg
2022-07-28 19:36:39 +02:00
committed by GitHub
parent f13d65262a
commit a3c724f2c3
51 changed files with 282 additions and 192 deletions
+1 -1
View File
@@ -1925,7 +1925,7 @@ func shouldRegenerateCertificate(cert tls.Certificate) error {
// On macOS, check for certificates issued on or after July 1st, 2019,
// with a longer validity time than 825 days.
cutoff := time.Date(2019, 7, 1, 0, 0, 0, 0, time.UTC)
if runtime.GOOS == "darwin" &&
if build.IsDarwin &&
leaf.NotBefore.After(cutoff) &&
leaf.NotAfter.Sub(leaf.NotBefore) > 825*24*time.Hour {
return errors.New("certificate incompatible with macOS 10.15 (Catalina)")
+3 -3
View File
@@ -19,7 +19,6 @@ import (
"os"
"path/filepath"
"reflect"
"runtime"
"strconv"
"strings"
"testing"
@@ -27,6 +26,7 @@ import (
"github.com/d4l3k/messagediff"
"github.com/syncthing/syncthing/lib/assets"
"github.com/syncthing/syncthing/lib/build"
"github.com/syncthing/syncthing/lib/config"
connmocks "github.com/syncthing/syncthing/lib/connections/mocks"
discovermocks "github.com/syncthing/syncthing/lib/discover/mocks"
@@ -1255,7 +1255,7 @@ func TestShouldRegenerateCertificate(t *testing.T) {
t.Error("expected no error:", err)
}
if runtime.GOOS == "darwin" {
if build.IsDarwin {
// Certificates with too long an expiry time are not allowed on macOS
crt, err = tlsutil.NewCertificateInMemory("foo.example.com", 1000)
if err != nil {
@@ -1416,7 +1416,7 @@ func TestSanitizedHostname(t *testing.T) {
// be prone to false negatives if things change in the future, but likely
// not false positives.
func runningInContainer() bool {
if runtime.GOOS != "linux" {
if !build.IsLinux {
return false
}