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
+2 -2
View File
@@ -15,13 +15,13 @@ import (
"net"
"net/url"
"os"
"runtime"
"sort"
"strconv"
"strings"
"github.com/pkg/errors"
"github.com/syncthing/syncthing/lib/build"
"github.com/syncthing/syncthing/lib/fs"
"github.com/syncthing/syncthing/lib/protocol"
"github.com/syncthing/syncthing/lib/util"
@@ -549,7 +549,7 @@ loop:
}
func cleanSymlinks(filesystem fs.Filesystem, dir string) {
if runtime.GOOS == "windows" {
if build.IsWindows {
// We don't do symlinks on Windows. Additionally, there may
// be things that look like symlinks that are not, which we
// should leave alone. Deduplicated files, for example.
+4 -3
View File
@@ -23,6 +23,7 @@ import (
"github.com/d4l3k/messagediff"
"github.com/syncthing/syncthing/lib/build"
"github.com/syncthing/syncthing/lib/events"
"github.com/syncthing/syncthing/lib/fs"
"github.com/syncthing/syncthing/lib/protocol"
@@ -445,7 +446,7 @@ func TestVersioningConfig(t *testing.T) {
}
func TestIssue1262(t *testing.T) {
if runtime.GOOS != "windows" {
if !build.IsWindows {
t.Skipf("path gets converted to absolute as part of the filesystem initialization on linux")
}
@@ -538,7 +539,7 @@ func TestFolderCheckPath(t *testing.T) {
path: "link",
err: nil,
})
} else if runtime.GOOS != "windows" {
} else if !build.IsWindows {
t.Log("running without symlink check")
t.Fatal(err)
}
@@ -593,7 +594,7 @@ func TestNewSaveLoad(t *testing.T) {
}
func TestWindowsLineEndings(t *testing.T) {
if runtime.GOOS != "windows" {
if !build.IsWindows {
t.Skip("Windows specific")
}
+4 -4
View File
@@ -9,13 +9,13 @@ package config
import (
"errors"
"fmt"
"runtime"
"sort"
"strings"
"time"
"github.com/shirou/gopsutil/v3/disk"
"github.com/syncthing/syncthing/lib/build"
"github.com/syncthing/syncthing/lib/db"
"github.com/syncthing/syncthing/lib/fs"
"github.com/syncthing/syncthing/lib/protocol"
@@ -64,7 +64,7 @@ func (f FolderConfiguration) Filesystem(fset *db.FileSet) fs.Filesystem {
func (f FolderConfiguration) ModTimeWindow() time.Duration {
dur := time.Duration(f.RawModTimeWindowS) * time.Second
if f.RawModTimeWindowS < 1 && runtime.GOOS == "android" {
if f.RawModTimeWindowS < 1 && build.IsAndroid {
if usage, err := disk.Usage(f.Filesystem(nil).URI()); err != nil {
dur = 2 * time.Second
l.Debugf(`Detecting FS at "%v" on android: Setting mtime window to 2s: err == "%v"`, f.Path, err)
@@ -90,7 +90,7 @@ func (f *FolderConfiguration) CreateMarker() error {
}
permBits := fs.FileMode(0777)
if runtime.GOOS == "windows" {
if build.IsWindows {
// Windows has no umask so we must chose a safer set of bits to
// begin with.
permBits = 0700
@@ -145,7 +145,7 @@ func (f *FolderConfiguration) CreateRoot() (err error) {
// Directory permission bits. Will be filtered down to something
// sane by umask on Unixes.
permBits := fs.FileMode(0777)
if runtime.GOOS == "windows" {
if build.IsWindows {
// Windows has no umask so we must chose a safer set of bits to
// begin with.
permBits = 0700
+2 -2
View File
@@ -11,11 +11,11 @@ import (
"os"
"path"
"path/filepath"
"runtime"
"sort"
"strings"
"sync"
"github.com/syncthing/syncthing/lib/build"
"github.com/syncthing/syncthing/lib/fs"
"github.com/syncthing/syncthing/lib/upgrade"
"github.com/syncthing/syncthing/lib/util"
@@ -189,7 +189,7 @@ func migrateToConfigV24(cfg *Configuration) {
func migrateToConfigV23(cfg *Configuration) {
permBits := fs.FileMode(0777)
if runtime.GOOS == "windows" {
if build.IsWindows {
// Windows has no umask so we must chose a safer set of bits to
// begin with.
permBits = 0700