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:
+4
-4
@@ -11,13 +11,13 @@ import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"path/filepath"
|
||||
"runtime"
|
||||
"strings"
|
||||
"sync/atomic"
|
||||
"time"
|
||||
"unicode/utf8"
|
||||
|
||||
metrics "github.com/rcrowley/go-metrics"
|
||||
"github.com/syncthing/syncthing/lib/build"
|
||||
"github.com/syncthing/syncthing/lib/events"
|
||||
"github.com/syncthing/syncthing/lib/fs"
|
||||
"github.com/syncthing/syncthing/lib/ignore"
|
||||
@@ -470,7 +470,7 @@ func (w *walker) walkDir(ctx context.Context, relPath string, info fs.FileInfo,
|
||||
func (w *walker) walkSymlink(ctx context.Context, relPath string, info fs.FileInfo, finishedChan chan<- ScanResult) error {
|
||||
// Symlinks are not supported on Windows. We ignore instead of returning
|
||||
// an error.
|
||||
if runtime.GOOS == "windows" {
|
||||
if build.IsWindows {
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -519,7 +519,7 @@ func (w *walker) walkSymlink(ctx context.Context, relPath string, info fs.FileIn
|
||||
// normalizePath returns the normalized relative path (possibly after fixing
|
||||
// it on disk), or skip is true.
|
||||
func (w *walker) normalizePath(path string, info fs.FileInfo) (normPath string, err error) {
|
||||
if runtime.GOOS == "darwin" {
|
||||
if build.IsDarwin {
|
||||
// Mac OS X file names should always be NFD normalized.
|
||||
normPath = norm.NFD.String(path)
|
||||
} else {
|
||||
@@ -579,7 +579,7 @@ func (w *walker) normalizePath(path string, info fs.FileInfo) (normPath string,
|
||||
// do not depend on type, and things that should be preserved from the
|
||||
// previous version of the FileInfo.
|
||||
func (w *walker) updateFileInfo(dst, src protocol.FileInfo) protocol.FileInfo {
|
||||
if dst.Type == protocol.FileInfoTypeFile && runtime.GOOS == "windows" {
|
||||
if dst.Type == protocol.FileInfoTypeFile && build.IsWindows {
|
||||
// If we have an existing index entry, copy the executable bits
|
||||
// from there.
|
||||
dst.Permissions |= (src.Permissions & 0111)
|
||||
|
||||
Reference in New Issue
Block a user