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:
@@ -11,7 +11,6 @@ import (
|
||||
"fmt"
|
||||
"io"
|
||||
"path/filepath"
|
||||
"runtime"
|
||||
"sort"
|
||||
"strconv"
|
||||
"strings"
|
||||
@@ -19,6 +18,7 @@ import (
|
||||
|
||||
"github.com/pkg/errors"
|
||||
|
||||
"github.com/syncthing/syncthing/lib/build"
|
||||
"github.com/syncthing/syncthing/lib/config"
|
||||
"github.com/syncthing/syncthing/lib/db"
|
||||
"github.com/syncthing/syncthing/lib/events"
|
||||
@@ -344,7 +344,7 @@ func (f *sendReceiveFolder) processNeeded(snap *db.Snapshot, dbUpdateChan chan<-
|
||||
l.Debugln(f, "Handling ignored file", file)
|
||||
dbUpdateChan <- dbUpdateJob{file, dbUpdateInvalidate}
|
||||
|
||||
case runtime.GOOS == "windows" && fs.WindowsInvalidFilename(file.Name) != nil:
|
||||
case build.IsWindows && fs.WindowsInvalidFilename(file.Name) != nil:
|
||||
if file.IsDeleted() {
|
||||
// Just pretend we deleted it, no reason to create an error
|
||||
// about a deleted file that we can't have anyway.
|
||||
@@ -394,7 +394,7 @@ func (f *sendReceiveFolder) processNeeded(snap *db.Snapshot, dbUpdateChan chan<-
|
||||
f.queue.Push(file.Name, file.Size, file.ModTime())
|
||||
}
|
||||
|
||||
case runtime.GOOS == "windows" && file.IsSymlink():
|
||||
case build.IsWindows && file.IsSymlink():
|
||||
if err := f.handleSymlinkCheckExisting(file, snap, scanChan); err != nil {
|
||||
f.newPullError(file.Name, fmt.Errorf("handling unsupported symlink: %w", err))
|
||||
break
|
||||
@@ -2115,7 +2115,7 @@ func (f *sendReceiveFolder) maybeAdjustOwnership(file *protocol.FileInfo, name s
|
||||
}
|
||||
|
||||
func (f *sendReceiveFolder) copyOwnershipFromParent(path string) error {
|
||||
if runtime.GOOS == "windows" {
|
||||
if build.IsWindows {
|
||||
// Can't do anything.
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -15,12 +15,12 @@ import (
|
||||
"io"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"runtime"
|
||||
"strconv"
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/syncthing/syncthing/lib/build"
|
||||
"github.com/syncthing/syncthing/lib/events"
|
||||
"github.com/syncthing/syncthing/lib/fs"
|
||||
"github.com/syncthing/syncthing/lib/ignore"
|
||||
@@ -205,7 +205,7 @@ func TestHandleFileWithTemp(t *testing.T) {
|
||||
|
||||
func TestCopierFinder(t *testing.T) {
|
||||
methods := []fs.CopyRangeMethod{fs.CopyRangeMethodStandard, fs.CopyRangeMethodAllWithFallback}
|
||||
if runtime.GOOS == "linux" {
|
||||
if build.IsLinux {
|
||||
methods = append(methods, fs.CopyRangeMethodSendFile)
|
||||
}
|
||||
for _, method := range methods {
|
||||
@@ -789,7 +789,7 @@ func TestCopyOwner(t *testing.T) {
|
||||
// Verifies that owner and group are copied from the parent, for both
|
||||
// files and directories.
|
||||
|
||||
if runtime.GOOS == "windows" {
|
||||
if build.IsWindows {
|
||||
t.Skip("copying owner not supported on Windows")
|
||||
}
|
||||
|
||||
@@ -986,7 +986,7 @@ func TestDeleteBehindSymlink(t *testing.T) {
|
||||
must(t, ffs.RemoveAll(link))
|
||||
|
||||
if err := fs.DebugSymlinkForTestsOnly(destFs, ffs, "", link); err != nil {
|
||||
if runtime.GOOS == "windows" {
|
||||
if build.IsWindows {
|
||||
// Probably we require permissions we don't have.
|
||||
t.Skip("Need admin permissions or developer mode to run symlink test on Windows: " + err.Error())
|
||||
} else {
|
||||
@@ -1145,7 +1145,7 @@ func TestPullCaseOnlyDir(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestPullCaseOnlySymlink(t *testing.T) {
|
||||
if runtime.GOOS == "windows" {
|
||||
if build.IsWindows {
|
||||
t.Skip("symlinks not supported on windows")
|
||||
}
|
||||
testPullCaseOnlyDirOrSymlink(t, false)
|
||||
@@ -1275,7 +1275,7 @@ func TestPullCaseOnlyRename(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestPullSymlinkOverExistingWindows(t *testing.T) {
|
||||
if runtime.GOOS != "windows" {
|
||||
if !build.IsWindows {
|
||||
t.Skip()
|
||||
}
|
||||
|
||||
|
||||
@@ -8,11 +8,11 @@ package model
|
||||
|
||||
import (
|
||||
"path/filepath"
|
||||
"runtime"
|
||||
"testing"
|
||||
|
||||
"github.com/d4l3k/messagediff"
|
||||
|
||||
"github.com/syncthing/syncthing/lib/build"
|
||||
"github.com/syncthing/syncthing/lib/config"
|
||||
)
|
||||
|
||||
@@ -96,7 +96,7 @@ func unifySubsCases() []unifySubsCase {
|
||||
},
|
||||
}
|
||||
|
||||
if runtime.GOOS == "windows" {
|
||||
if build.IsWindows {
|
||||
// Fixup path separators
|
||||
for i := range cases {
|
||||
for j, p := range cases[i].in {
|
||||
|
||||
+2
-1
@@ -27,6 +27,7 @@ import (
|
||||
"github.com/pkg/errors"
|
||||
"github.com/thejerf/suture/v4"
|
||||
|
||||
"github.com/syncthing/syncthing/lib/build"
|
||||
"github.com/syncthing/syncthing/lib/config"
|
||||
"github.com/syncthing/syncthing/lib/connections"
|
||||
"github.com/syncthing/syncthing/lib/db"
|
||||
@@ -2399,7 +2400,7 @@ func (m *model) numHashers(folder string) int {
|
||||
return folderCfg.Hashers
|
||||
}
|
||||
|
||||
if runtime.GOOS == "windows" || runtime.GOOS == "darwin" || runtime.GOOS == "android" {
|
||||
if build.IsWindows || build.IsDarwin || build.IsAndroid {
|
||||
// Interactive operating systems; don't load the system too heavily by
|
||||
// default.
|
||||
return 1
|
||||
|
||||
@@ -15,7 +15,6 @@ import (
|
||||
"math/rand"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"runtime"
|
||||
"runtime/pprof"
|
||||
"sort"
|
||||
"strconv"
|
||||
@@ -26,6 +25,7 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
"github.com/syncthing/syncthing/lib/build"
|
||||
"github.com/syncthing/syncthing/lib/config"
|
||||
"github.com/syncthing/syncthing/lib/db"
|
||||
"github.com/syncthing/syncthing/lib/db/backend"
|
||||
@@ -1463,7 +1463,7 @@ func changeIgnores(t *testing.T, m *testModel, expected []string) {
|
||||
t.Errorf("Incorrect ignores: %v != %v", ignores2, ignores)
|
||||
}
|
||||
|
||||
if runtime.GOOS == "darwin" {
|
||||
if build.IsDarwin {
|
||||
// see above
|
||||
time.Sleep(time.Second)
|
||||
} else {
|
||||
@@ -2130,7 +2130,7 @@ func TestIssue4357(t *testing.T) {
|
||||
func TestIssue2782(t *testing.T) {
|
||||
// CheckHealth should accept a symlinked folder, when using tilde-expanded path.
|
||||
|
||||
if runtime.GOOS == "windows" {
|
||||
if build.IsWindows {
|
||||
t.Skip("not reliable on Windows")
|
||||
return
|
||||
}
|
||||
@@ -2471,7 +2471,7 @@ func TestNoRequestsFromPausedDevices(t *testing.T) {
|
||||
|
||||
// TestIssue2571 tests replacing a directory with content with a symlink
|
||||
func TestIssue2571(t *testing.T) {
|
||||
if runtime.GOOS == "windows" {
|
||||
if build.IsWindows {
|
||||
t.Skip("Scanning symlinks isn't supported on windows")
|
||||
}
|
||||
|
||||
@@ -2510,7 +2510,7 @@ func TestIssue2571(t *testing.T) {
|
||||
|
||||
// TestIssue4573 tests that contents of an unavailable dir aren't marked deleted
|
||||
func TestIssue4573(t *testing.T) {
|
||||
if runtime.GOOS == "windows" {
|
||||
if build.IsWindows {
|
||||
t.Skip("Can't make the dir inaccessible on windows")
|
||||
}
|
||||
|
||||
@@ -2802,7 +2802,7 @@ func TestVersionRestore(t *testing.T) {
|
||||
"dir/file.txt",
|
||||
"dir/existing.txt",
|
||||
} {
|
||||
if runtime.GOOS == "windows" {
|
||||
if build.IsWindows {
|
||||
file = filepath.FromSlash(file)
|
||||
}
|
||||
dir := filepath.Dir(file)
|
||||
@@ -2886,7 +2886,7 @@ func TestVersionRestore(t *testing.T) {
|
||||
|
||||
// Check that content of files matches to the version they've been restored.
|
||||
for file, version := range restore {
|
||||
if runtime.GOOS == "windows" {
|
||||
if build.IsWindows {
|
||||
file = filepath.FromSlash(file)
|
||||
}
|
||||
tag := version.In(time.Local).Truncate(time.Second).Format(versioner.TimeFormat)
|
||||
@@ -2918,7 +2918,7 @@ func TestVersionRestore(t *testing.T) {
|
||||
must(t, err)
|
||||
for file, versions := range allFileVersions {
|
||||
key := file
|
||||
if runtime.GOOS == "windows" {
|
||||
if build.IsWindows {
|
||||
file = filepath.FromSlash(file)
|
||||
}
|
||||
for _, version := range versions {
|
||||
|
||||
@@ -12,13 +12,13 @@ import (
|
||||
"errors"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"runtime"
|
||||
"strconv"
|
||||
"strings"
|
||||
"sync"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/syncthing/syncthing/lib/build"
|
||||
"github.com/syncthing/syncthing/lib/config"
|
||||
"github.com/syncthing/syncthing/lib/events"
|
||||
"github.com/syncthing/syncthing/lib/fs"
|
||||
@@ -72,7 +72,7 @@ func TestRequestSimple(t *testing.T) {
|
||||
func TestSymlinkTraversalRead(t *testing.T) {
|
||||
// Verify that a symlink can not be traversed for reading.
|
||||
|
||||
if runtime.GOOS == "windows" {
|
||||
if build.IsWindows {
|
||||
t.Skip("no symlink support on CI")
|
||||
return
|
||||
}
|
||||
@@ -115,7 +115,7 @@ func TestSymlinkTraversalRead(t *testing.T) {
|
||||
func TestSymlinkTraversalWrite(t *testing.T) {
|
||||
// Verify that a symlink can not be traversed for writing.
|
||||
|
||||
if runtime.GOOS == "windows" {
|
||||
if build.IsWindows {
|
||||
t.Skip("no symlink support on CI")
|
||||
return
|
||||
}
|
||||
@@ -214,7 +214,7 @@ func TestRequestCreateTmpSymlink(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestRequestVersioningSymlinkAttack(t *testing.T) {
|
||||
if runtime.GOOS == "windows" {
|
||||
if build.IsWindows {
|
||||
t.Skip("no symlink support on Windows")
|
||||
}
|
||||
|
||||
@@ -613,7 +613,7 @@ func TestParentDeletion(t *testing.T) {
|
||||
// TestRequestSymlinkWindows checks that symlinks aren't marked as deleted on windows
|
||||
// Issue: https://github.com/syncthing/syncthing/issues/5125
|
||||
func TestRequestSymlinkWindows(t *testing.T) {
|
||||
if runtime.GOOS != "windows" {
|
||||
if !build.IsWindows {
|
||||
t.Skip("windows specific test")
|
||||
}
|
||||
|
||||
|
||||
@@ -7,9 +7,9 @@
|
||||
package model
|
||||
|
||||
import (
|
||||
"runtime"
|
||||
"testing"
|
||||
|
||||
"github.com/syncthing/syncthing/lib/build"
|
||||
"github.com/syncthing/syncthing/lib/fs"
|
||||
)
|
||||
|
||||
@@ -70,7 +70,7 @@ func TestInWriteableDir(t *testing.T) {
|
||||
func TestOSWindowsRemove(t *testing.T) {
|
||||
// os.Remove should remove read only things on windows
|
||||
|
||||
if runtime.GOOS != "windows" {
|
||||
if !build.IsWindows {
|
||||
t.Skipf("Tests not required")
|
||||
return
|
||||
}
|
||||
@@ -107,7 +107,7 @@ func TestOSWindowsRemove(t *testing.T) {
|
||||
func TestOSWindowsRemoveAll(t *testing.T) {
|
||||
// os.RemoveAll should remove read only things on windows
|
||||
|
||||
if runtime.GOOS != "windows" {
|
||||
if !build.IsWindows {
|
||||
t.Skipf("Tests not required")
|
||||
return
|
||||
}
|
||||
@@ -139,7 +139,7 @@ func TestOSWindowsRemoveAll(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestInWritableDirWindowsRename(t *testing.T) {
|
||||
if runtime.GOOS != "windows" {
|
||||
if !build.IsWindows {
|
||||
t.Skipf("Tests not required")
|
||||
return
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user