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
-3
@@ -10,9 +10,10 @@ import (
|
||||
"fmt"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"runtime"
|
||||
"strings"
|
||||
"unicode"
|
||||
|
||||
"github.com/syncthing/syncthing/lib/build"
|
||||
)
|
||||
|
||||
const pathSeparatorString = string(PathSeparator)
|
||||
@@ -35,7 +36,7 @@ func ExpandTilde(path string) (string, error) {
|
||||
}
|
||||
|
||||
func getHomeDir() (string, error) {
|
||||
if runtime.GOOS == "windows" {
|
||||
if build.IsWindows {
|
||||
// Legacy -- we prioritize this for historical reasons, whereas
|
||||
// os.UserHomeDir uses %USERPROFILE% always.
|
||||
home := filepath.Join(os.Getenv("HomeDrive"), os.Getenv("HomePath"))
|
||||
@@ -196,7 +197,7 @@ func CommonPrefix(first, second string) string {
|
||||
}
|
||||
|
||||
if isAbs {
|
||||
if runtime.GOOS == "windows" && isVolumeNameOnly(common) {
|
||||
if build.IsWindows && isVolumeNameOnly(common) {
|
||||
// Because strings.Split strips out path separators, if we're at the volume name, we end up without a separator
|
||||
// Wedge an empty element to be joined with.
|
||||
common = append(common, "")
|
||||
|
||||
Reference in New Issue
Block a user