mirror of
https://github.com/octoleo/syncthing.git
synced 2025-01-02 22:50:18 +00:00
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:
parent
f13d65262a
commit
a3c724f2c3
4
build.go
4
build.go
@ -31,6 +31,8 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
"text/template"
|
"text/template"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
buildpkg "github.com/syncthing/syncthing/lib/build"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
@ -393,7 +395,7 @@ func test(tags []string, pkgs ...string) {
|
|||||||
|
|
||||||
if runtime.GOARCH == "amd64" {
|
if runtime.GOARCH == "amd64" {
|
||||||
switch runtime.GOOS {
|
switch runtime.GOOS {
|
||||||
case "darwin", "linux", "freebsd": // , "windows": # See https://github.com/golang/go/issues/27089
|
case buildpkg.Darwin, buildpkg.Linux, buildpkg.FreeBSD: // , "windows": # See https://github.com/golang/go/issues/27089
|
||||||
args = append(args, "-race")
|
args = append(args, "-race")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -14,7 +14,6 @@ import (
|
|||||||
"os"
|
"os"
|
||||||
"os/signal"
|
"os/signal"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"runtime"
|
|
||||||
"strings"
|
"strings"
|
||||||
"sync/atomic"
|
"sync/atomic"
|
||||||
"syscall"
|
"syscall"
|
||||||
@ -146,7 +145,7 @@ func main() {
|
|||||||
log.Println("Connection limit", descriptorLimit)
|
log.Println("Connection limit", descriptorLimit)
|
||||||
|
|
||||||
go monitorLimits()
|
go monitorLimits()
|
||||||
} else if err != nil && runtime.GOOS != "windows" {
|
} else if err != nil && !build.IsWindows {
|
||||||
log.Println("Assuming no connection limit, due to error retrieving rlimits:", err)
|
log.Println("Assuming no connection limit, due to error retrieving rlimits:", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -199,7 +199,7 @@ func defaultVars() kong.Vars {
|
|||||||
// Windows, the "default" options.logFile will later be replaced with the
|
// Windows, the "default" options.logFile will later be replaced with the
|
||||||
// default path, unless the user has manually specified "-" or
|
// default path, unless the user has manually specified "-" or
|
||||||
// something else.
|
// something else.
|
||||||
if runtime.GOOS == "windows" {
|
if build.IsWindows {
|
||||||
vars["logFile"] = "default"
|
vars["logFile"] = "default"
|
||||||
} else {
|
} else {
|
||||||
vars["logFile"] = "-"
|
vars["logFile"] = "-"
|
||||||
|
@ -15,11 +15,11 @@ import (
|
|||||||
"os/exec"
|
"os/exec"
|
||||||
"os/signal"
|
"os/signal"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"runtime"
|
|
||||||
"strings"
|
"strings"
|
||||||
"syscall"
|
"syscall"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/syncthing/syncthing/lib/build"
|
||||||
"github.com/syncthing/syncthing/lib/fs"
|
"github.com/syncthing/syncthing/lib/fs"
|
||||||
"github.com/syncthing/syncthing/lib/locations"
|
"github.com/syncthing/syncthing/lib/locations"
|
||||||
"github.com/syncthing/syncthing/lib/osutil"
|
"github.com/syncthing/syncthing/lib/osutil"
|
||||||
@ -66,7 +66,7 @@ func monitorMain(options serveOptions) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
l.Warnln("Failed to setup logging to file, proceeding with logging to stdout only:", err)
|
l.Warnln("Failed to setup logging to file, proceeding with logging to stdout only:", err)
|
||||||
} else {
|
} else {
|
||||||
if runtime.GOOS == "windows" {
|
if build.IsWindows {
|
||||||
// Translate line breaks to Windows standard
|
// Translate line breaks to Windows standard
|
||||||
fileDst = osutil.ReplacingWriter{
|
fileDst = osutil.ReplacingWriter{
|
||||||
Writer: fileDst,
|
Writer: fileDst,
|
||||||
@ -315,7 +315,7 @@ func restartMonitor(args []string) error {
|
|||||||
// opening the browser on startup.
|
// opening the browser on startup.
|
||||||
os.Setenv("STRESTART", "yes")
|
os.Setenv("STRESTART", "yes")
|
||||||
|
|
||||||
if runtime.GOOS != "windows" {
|
if !build.IsWindows {
|
||||||
// syscall.Exec is the cleanest way to restart on Unixes as it
|
// syscall.Exec is the cleanest way to restart on Unixes as it
|
||||||
// replaces the current process with the new one, keeping the pid and
|
// replaces the current process with the new one, keeping the pid and
|
||||||
// controlling terminal and so on
|
// controlling terminal and so on
|
||||||
|
@ -11,20 +11,18 @@ package main
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"runtime"
|
|
||||||
"syscall"
|
"syscall"
|
||||||
|
|
||||||
|
"github.com/syncthing/syncthing/lib/build"
|
||||||
)
|
)
|
||||||
|
|
||||||
func openURL(url string) error {
|
func openURL(url string) error {
|
||||||
switch runtime.GOOS {
|
if build.IsDarwin {
|
||||||
case "darwin":
|
|
||||||
return exec.Command("open", url).Run()
|
return exec.Command("open", url).Run()
|
||||||
|
|
||||||
default:
|
|
||||||
cmd := exec.Command("xdg-open", url)
|
|
||||||
cmd.SysProcAttr = &syscall.SysProcAttr{
|
|
||||||
Setpgid: true,
|
|
||||||
}
|
|
||||||
return cmd.Run()
|
|
||||||
}
|
}
|
||||||
|
cmd := exec.Command("xdg-open", url)
|
||||||
|
cmd.SysProcAttr = &syscall.SysProcAttr{
|
||||||
|
Setpgid: true,
|
||||||
|
}
|
||||||
|
return cmd.Run()
|
||||||
}
|
}
|
||||||
|
@ -1925,7 +1925,7 @@ func shouldRegenerateCertificate(cert tls.Certificate) error {
|
|||||||
// On macOS, check for certificates issued on or after July 1st, 2019,
|
// On macOS, check for certificates issued on or after July 1st, 2019,
|
||||||
// with a longer validity time than 825 days.
|
// with a longer validity time than 825 days.
|
||||||
cutoff := time.Date(2019, 7, 1, 0, 0, 0, 0, time.UTC)
|
cutoff := time.Date(2019, 7, 1, 0, 0, 0, 0, time.UTC)
|
||||||
if runtime.GOOS == "darwin" &&
|
if build.IsDarwin &&
|
||||||
leaf.NotBefore.After(cutoff) &&
|
leaf.NotBefore.After(cutoff) &&
|
||||||
leaf.NotAfter.Sub(leaf.NotBefore) > 825*24*time.Hour {
|
leaf.NotAfter.Sub(leaf.NotBefore) > 825*24*time.Hour {
|
||||||
return errors.New("certificate incompatible with macOS 10.15 (Catalina)")
|
return errors.New("certificate incompatible with macOS 10.15 (Catalina)")
|
||||||
|
@ -19,7 +19,6 @@ import (
|
|||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"reflect"
|
"reflect"
|
||||||
"runtime"
|
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
@ -27,6 +26,7 @@ import (
|
|||||||
|
|
||||||
"github.com/d4l3k/messagediff"
|
"github.com/d4l3k/messagediff"
|
||||||
"github.com/syncthing/syncthing/lib/assets"
|
"github.com/syncthing/syncthing/lib/assets"
|
||||||
|
"github.com/syncthing/syncthing/lib/build"
|
||||||
"github.com/syncthing/syncthing/lib/config"
|
"github.com/syncthing/syncthing/lib/config"
|
||||||
connmocks "github.com/syncthing/syncthing/lib/connections/mocks"
|
connmocks "github.com/syncthing/syncthing/lib/connections/mocks"
|
||||||
discovermocks "github.com/syncthing/syncthing/lib/discover/mocks"
|
discovermocks "github.com/syncthing/syncthing/lib/discover/mocks"
|
||||||
@ -1255,7 +1255,7 @@ func TestShouldRegenerateCertificate(t *testing.T) {
|
|||||||
t.Error("expected no error:", err)
|
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
|
// Certificates with too long an expiry time are not allowed on macOS
|
||||||
crt, err = tlsutil.NewCertificateInMemory("foo.example.com", 1000)
|
crt, err = tlsutil.NewCertificateInMemory("foo.example.com", 1000)
|
||||||
if err != nil {
|
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
|
// be prone to false negatives if things change in the future, but likely
|
||||||
// not false positives.
|
// not false positives.
|
||||||
func runningInContainer() bool {
|
func runningInContainer() bool {
|
||||||
if runtime.GOOS != "linux" {
|
if !build.IsLinux {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
38
lib/build/runtimeos.gen.go
Normal file
38
lib/build/runtimeos.gen.go
Normal file
@ -0,0 +1,38 @@
|
|||||||
|
// Code generated by runtimeos.sh. DO NOT EDIT.
|
||||||
|
package build
|
||||||
|
|
||||||
|
import "runtime"
|
||||||
|
|
||||||
|
const (
|
||||||
|
AIX = "aix"
|
||||||
|
Android = "android"
|
||||||
|
Darwin = "darwin"
|
||||||
|
Dragonfly = "dragonfly"
|
||||||
|
FreeBSD = "freebsd"
|
||||||
|
Illumos = "illumos"
|
||||||
|
IOS = "ios"
|
||||||
|
JS = "js"
|
||||||
|
Linux = "linux"
|
||||||
|
NetBSD = "netbsd"
|
||||||
|
OpenBSD = "openbsd"
|
||||||
|
Plan9 = "plan9"
|
||||||
|
Solaris = "solaris"
|
||||||
|
Windows = "windows"
|
||||||
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
IsAIX = runtime.GOOS == AIX
|
||||||
|
IsAndroid = runtime.GOOS == Android
|
||||||
|
IsDarwin = runtime.GOOS == Darwin
|
||||||
|
IsDragonfly = runtime.GOOS == Dragonfly
|
||||||
|
IsFreeBSD = runtime.GOOS == FreeBSD
|
||||||
|
IsIllumos = runtime.GOOS == Illumos
|
||||||
|
IsIOS = runtime.GOOS == IOS
|
||||||
|
IsJS = runtime.GOOS == JS
|
||||||
|
IsLinux = runtime.GOOS == Linux
|
||||||
|
IsNetBSD = runtime.GOOS == NetBSD
|
||||||
|
IsOpenBSD = runtime.GOOS == OpenBSD
|
||||||
|
IsPlan9 = runtime.GOOS == Plan9
|
||||||
|
IsSolaris = runtime.GOOS == Solaris
|
||||||
|
IsWindows = runtime.GOOS == Windows
|
||||||
|
)
|
43
lib/build/runtimeos.sh
Executable file
43
lib/build/runtimeos.sh
Executable file
@ -0,0 +1,43 @@
|
|||||||
|
# Copyright (C) 2022 The Syncthing Authors.
|
||||||
|
#
|
||||||
|
# This Source Code Form is subject to the terms of the Mozilla Public
|
||||||
|
# License, v. 2.0. If a copy of the MPL was not distributed with this file,
|
||||||
|
# You can obtain one at https://mozilla.org/MPL/2.0/.
|
||||||
|
|
||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
# List known operating system/architecture combos, removing the
|
||||||
|
# architecture, and making constants of them.
|
||||||
|
|
||||||
|
osname() {
|
||||||
|
echo "$1" | awk '{print toupper(substr($1, 1, 1)) substr($1, 2)}' \
|
||||||
|
| sed s/aix/AIX/i \
|
||||||
|
| sed s/bsd/BSD/i \
|
||||||
|
| sed s/ios/IOS/i \
|
||||||
|
| sed s/js/JS/i
|
||||||
|
}
|
||||||
|
|
||||||
|
osconstants() {
|
||||||
|
echo "// Code generated by runtimeos.sh. DO NOT EDIT."
|
||||||
|
echo "package build"
|
||||||
|
echo "import \"runtime\""
|
||||||
|
|
||||||
|
echo "const ("
|
||||||
|
for OS in $(go tool dist list | sed 's|/.*||' | sort | uniq) ; do
|
||||||
|
name=$(osname "$OS")
|
||||||
|
echo "$name = \"$OS\""
|
||||||
|
done
|
||||||
|
echo ")"
|
||||||
|
echo
|
||||||
|
|
||||||
|
echo "const ("
|
||||||
|
for OS in $(go tool dist list | sed 's|/.*||' | sort | uniq) ; do
|
||||||
|
name=$(osname "$OS")
|
||||||
|
echo "Is$name = runtime.GOOS == $name"
|
||||||
|
done
|
||||||
|
echo ")"
|
||||||
|
}
|
||||||
|
|
||||||
|
osconstants > runtimeos.gen.go
|
||||||
|
|
||||||
|
gofmt -w -s runtimeos.gen.go
|
@ -15,13 +15,13 @@ import (
|
|||||||
"net"
|
"net"
|
||||||
"net/url"
|
"net/url"
|
||||||
"os"
|
"os"
|
||||||
"runtime"
|
|
||||||
"sort"
|
"sort"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
|
|
||||||
|
"github.com/syncthing/syncthing/lib/build"
|
||||||
"github.com/syncthing/syncthing/lib/fs"
|
"github.com/syncthing/syncthing/lib/fs"
|
||||||
"github.com/syncthing/syncthing/lib/protocol"
|
"github.com/syncthing/syncthing/lib/protocol"
|
||||||
"github.com/syncthing/syncthing/lib/util"
|
"github.com/syncthing/syncthing/lib/util"
|
||||||
@ -549,7 +549,7 @@ loop:
|
|||||||
}
|
}
|
||||||
|
|
||||||
func cleanSymlinks(filesystem fs.Filesystem, dir string) {
|
func cleanSymlinks(filesystem fs.Filesystem, dir string) {
|
||||||
if runtime.GOOS == "windows" {
|
if build.IsWindows {
|
||||||
// We don't do symlinks on Windows. Additionally, there may
|
// We don't do symlinks on Windows. Additionally, there may
|
||||||
// be things that look like symlinks that are not, which we
|
// be things that look like symlinks that are not, which we
|
||||||
// should leave alone. Deduplicated files, for example.
|
// should leave alone. Deduplicated files, for example.
|
||||||
|
@ -23,6 +23,7 @@ import (
|
|||||||
|
|
||||||
"github.com/d4l3k/messagediff"
|
"github.com/d4l3k/messagediff"
|
||||||
|
|
||||||
|
"github.com/syncthing/syncthing/lib/build"
|
||||||
"github.com/syncthing/syncthing/lib/events"
|
"github.com/syncthing/syncthing/lib/events"
|
||||||
"github.com/syncthing/syncthing/lib/fs"
|
"github.com/syncthing/syncthing/lib/fs"
|
||||||
"github.com/syncthing/syncthing/lib/protocol"
|
"github.com/syncthing/syncthing/lib/protocol"
|
||||||
@ -445,7 +446,7 @@ func TestVersioningConfig(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestIssue1262(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")
|
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",
|
path: "link",
|
||||||
err: nil,
|
err: nil,
|
||||||
})
|
})
|
||||||
} else if runtime.GOOS != "windows" {
|
} else if !build.IsWindows {
|
||||||
t.Log("running without symlink check")
|
t.Log("running without symlink check")
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
@ -593,7 +594,7 @@ func TestNewSaveLoad(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestWindowsLineEndings(t *testing.T) {
|
func TestWindowsLineEndings(t *testing.T) {
|
||||||
if runtime.GOOS != "windows" {
|
if !build.IsWindows {
|
||||||
t.Skip("Windows specific")
|
t.Skip("Windows specific")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -9,13 +9,13 @@ package config
|
|||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"runtime"
|
|
||||||
"sort"
|
"sort"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/shirou/gopsutil/v3/disk"
|
"github.com/shirou/gopsutil/v3/disk"
|
||||||
|
|
||||||
|
"github.com/syncthing/syncthing/lib/build"
|
||||||
"github.com/syncthing/syncthing/lib/db"
|
"github.com/syncthing/syncthing/lib/db"
|
||||||
"github.com/syncthing/syncthing/lib/fs"
|
"github.com/syncthing/syncthing/lib/fs"
|
||||||
"github.com/syncthing/syncthing/lib/protocol"
|
"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 {
|
func (f FolderConfiguration) ModTimeWindow() time.Duration {
|
||||||
dur := time.Duration(f.RawModTimeWindowS) * time.Second
|
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 {
|
if usage, err := disk.Usage(f.Filesystem(nil).URI()); err != nil {
|
||||||
dur = 2 * time.Second
|
dur = 2 * time.Second
|
||||||
l.Debugf(`Detecting FS at "%v" on android: Setting mtime window to 2s: err == "%v"`, f.Path, err)
|
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)
|
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
|
// Windows has no umask so we must chose a safer set of bits to
|
||||||
// begin with.
|
// begin with.
|
||||||
permBits = 0700
|
permBits = 0700
|
||||||
@ -145,7 +145,7 @@ func (f *FolderConfiguration) CreateRoot() (err error) {
|
|||||||
// Directory permission bits. Will be filtered down to something
|
// Directory permission bits. Will be filtered down to something
|
||||||
// sane by umask on Unixes.
|
// sane by umask on Unixes.
|
||||||
permBits := fs.FileMode(0777)
|
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
|
// Windows has no umask so we must chose a safer set of bits to
|
||||||
// begin with.
|
// begin with.
|
||||||
permBits = 0700
|
permBits = 0700
|
||||||
|
@ -11,11 +11,11 @@ import (
|
|||||||
"os"
|
"os"
|
||||||
"path"
|
"path"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"runtime"
|
|
||||||
"sort"
|
"sort"
|
||||||
"strings"
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
|
"github.com/syncthing/syncthing/lib/build"
|
||||||
"github.com/syncthing/syncthing/lib/fs"
|
"github.com/syncthing/syncthing/lib/fs"
|
||||||
"github.com/syncthing/syncthing/lib/upgrade"
|
"github.com/syncthing/syncthing/lib/upgrade"
|
||||||
"github.com/syncthing/syncthing/lib/util"
|
"github.com/syncthing/syncthing/lib/util"
|
||||||
@ -189,7 +189,7 @@ func migrateToConfigV24(cfg *Configuration) {
|
|||||||
|
|
||||||
func migrateToConfigV23(cfg *Configuration) {
|
func migrateToConfigV23(cfg *Configuration) {
|
||||||
permBits := fs.FileMode(0777)
|
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
|
// Windows has no umask so we must chose a safer set of bits to
|
||||||
// begin with.
|
// begin with.
|
||||||
permBits = 0700
|
permBits = 0700
|
||||||
|
@ -11,11 +11,11 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"runtime"
|
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/shirou/gopsutil/v3/disk"
|
"github.com/shirou/gopsutil/v3/disk"
|
||||||
|
"github.com/syncthing/syncthing/lib/build"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
@ -79,7 +79,7 @@ func newBasicFilesystem(root string, opts ...Option) *BasicFilesystem {
|
|||||||
|
|
||||||
// Attempt to enable long filename support on Windows. We may still not
|
// Attempt to enable long filename support on Windows. We may still not
|
||||||
// have an absolute path here if the previous steps failed.
|
// have an absolute path here if the previous steps failed.
|
||||||
if runtime.GOOS == "windows" {
|
if build.IsWindows {
|
||||||
root = longFilenameSupport(root)
|
root = longFilenameSupport(root)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -9,13 +9,13 @@ package fs
|
|||||||
import (
|
import (
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"runtime"
|
|
||||||
"sort"
|
"sort"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/syncthing/syncthing/lib/build"
|
||||||
"github.com/syncthing/syncthing/lib/rand"
|
"github.com/syncthing/syncthing/lib/rand"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -55,7 +55,7 @@ func TestChmodFile(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestChownFile(t *testing.T) {
|
func TestChownFile(t *testing.T) {
|
||||||
if runtime.GOOS == "windows" {
|
if build.IsWindows {
|
||||||
t.Skip("Not supported on Windows")
|
t.Skip("Not supported on Windows")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -106,7 +106,7 @@ func TestChmodDir(t *testing.T) {
|
|||||||
path := filepath.Join(dir, "dir")
|
path := filepath.Join(dir, "dir")
|
||||||
|
|
||||||
mode := os.FileMode(0755)
|
mode := os.FileMode(0755)
|
||||||
if runtime.GOOS == "windows" {
|
if build.IsWindows {
|
||||||
mode = os.FileMode(0777)
|
mode = os.FileMode(0777)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -177,7 +177,7 @@ func TestCreate(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestCreateSymlink(t *testing.T) {
|
func TestCreateSymlink(t *testing.T) {
|
||||||
if runtime.GOOS == "windows" {
|
if build.IsWindows {
|
||||||
t.Skip("windows not supported")
|
t.Skip("windows not supported")
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -336,7 +336,7 @@ func TestUsage(t *testing.T) {
|
|||||||
fs, _ := setup(t)
|
fs, _ := setup(t)
|
||||||
usage, err := fs.Usage(".")
|
usage, err := fs.Usage(".")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if runtime.GOOS == "netbsd" || runtime.GOOS == "openbsd" || runtime.GOOS == "solaris" {
|
if build.IsNetBSD || build.IsOpenBSD || build.IsSolaris || build.IsIllumos {
|
||||||
t.Skip()
|
t.Skip()
|
||||||
}
|
}
|
||||||
t.Errorf("Unexpected error: %s", err)
|
t.Errorf("Unexpected error: %s", err)
|
||||||
@ -429,7 +429,7 @@ func TestRooted(t *testing.T) {
|
|||||||
{"/", ".", "/", true},
|
{"/", ".", "/", true},
|
||||||
}
|
}
|
||||||
|
|
||||||
if runtime.GOOS == "windows" {
|
if build.IsWindows {
|
||||||
extraCases := []testcase{
|
extraCases := []testcase{
|
||||||
{`c:\`, `foo`, `c:\foo`, true},
|
{`c:\`, `foo`, `c:\foo`, true},
|
||||||
{`\\?\c:\`, `foo`, `\\?\c:\foo`, true},
|
{`\\?\c:\`, `foo`, `\\?\c:\foo`, true},
|
||||||
@ -503,7 +503,7 @@ func TestRooted(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestNewBasicFilesystem(t *testing.T) {
|
func TestNewBasicFilesystem(t *testing.T) {
|
||||||
if runtime.GOOS == "windows" {
|
if build.IsWindows {
|
||||||
t.Skip("non-windows root paths")
|
t.Skip("non-windows root paths")
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -550,7 +550,7 @@ func TestRel(t *testing.T) {
|
|||||||
{"/", "/Test", "Test"},
|
{"/", "/Test", "Test"},
|
||||||
{"/Test", "/Test/test", "test"},
|
{"/Test", "/Test/test", "test"},
|
||||||
}
|
}
|
||||||
if runtime.GOOS == "windows" {
|
if build.IsWindows {
|
||||||
for i := range testCases {
|
for i := range testCases {
|
||||||
testCases[i].root = filepath.FromSlash(testCases[i].root)
|
testCases[i].root = filepath.FromSlash(testCases[i].root)
|
||||||
testCases[i].abs = filepath.FromSlash(testCases[i].abs)
|
testCases[i].abs = filepath.FromSlash(testCases[i].abs)
|
||||||
|
@ -15,7 +15,6 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"runtime"
|
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
"syscall"
|
"syscall"
|
||||||
@ -23,6 +22,7 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/syncthing/notify"
|
"github.com/syncthing/notify"
|
||||||
|
"github.com/syncthing/syncthing/lib/build"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestMain(m *testing.M) {
|
func TestMain(m *testing.M) {
|
||||||
@ -41,7 +41,7 @@ func TestMain(m *testing.M) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
testDirAbs = filepath.Join(dir, testDir)
|
testDirAbs = filepath.Join(dir, testDir)
|
||||||
if runtime.GOOS == "windows" {
|
if build.IsWindows {
|
||||||
testDirAbs = longFilenameSupport(testDirAbs)
|
testDirAbs = longFilenameSupport(testDirAbs)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -68,7 +68,7 @@ var (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func TestWatchIgnore(t *testing.T) {
|
func TestWatchIgnore(t *testing.T) {
|
||||||
if runtime.GOOS == "openbsd" {
|
if build.IsOpenBSD {
|
||||||
t.Skip(failsOnOpenBSD)
|
t.Skip(failsOnOpenBSD)
|
||||||
}
|
}
|
||||||
name := "ignore"
|
name := "ignore"
|
||||||
@ -92,7 +92,7 @@ func TestWatchIgnore(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestWatchInclude(t *testing.T) {
|
func TestWatchInclude(t *testing.T) {
|
||||||
if runtime.GOOS == "openbsd" {
|
if build.IsOpenBSD {
|
||||||
t.Skip(failsOnOpenBSD)
|
t.Skip(failsOnOpenBSD)
|
||||||
}
|
}
|
||||||
name := "include"
|
name := "include"
|
||||||
@ -119,7 +119,7 @@ func TestWatchInclude(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestWatchRename(t *testing.T) {
|
func TestWatchRename(t *testing.T) {
|
||||||
if runtime.GOOS == "openbsd" {
|
if build.IsOpenBSD {
|
||||||
t.Skip(failsOnOpenBSD)
|
t.Skip(failsOnOpenBSD)
|
||||||
}
|
}
|
||||||
name := "rename"
|
name := "rename"
|
||||||
@ -134,7 +134,7 @@ func TestWatchRename(t *testing.T) {
|
|||||||
destEvent := Event{new, Remove}
|
destEvent := Event{new, Remove}
|
||||||
// Only on these platforms the removed file can be differentiated from
|
// Only on these platforms the removed file can be differentiated from
|
||||||
// the created file during renaming
|
// the created file during renaming
|
||||||
if runtime.GOOS == "windows" || runtime.GOOS == "linux" || runtime.GOOS == "solaris" || runtime.GOOS == "freebsd" {
|
if build.IsWindows || build.IsLinux || build.IsSolaris || build.IsIllumos || build.IsFreeBSD {
|
||||||
destEvent = Event{new, NonRemove}
|
destEvent = Event{new, NonRemove}
|
||||||
}
|
}
|
||||||
expectedEvents := []Event{
|
expectedEvents := []Event{
|
||||||
@ -154,7 +154,7 @@ func TestWatchRename(t *testing.T) {
|
|||||||
// out of root event on every event.
|
// out of root event on every event.
|
||||||
// https://github.com/syncthing/syncthing/issues/5695
|
// https://github.com/syncthing/syncthing/issues/5695
|
||||||
func TestWatchWinRoot(t *testing.T) {
|
func TestWatchWinRoot(t *testing.T) {
|
||||||
if runtime.GOOS != "windows" {
|
if !build.IsWindows {
|
||||||
t.Skip("Windows specific test")
|
t.Skip("Windows specific test")
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -288,7 +288,7 @@ func TestWatchSubpath(t *testing.T) {
|
|||||||
|
|
||||||
// TestWatchOverflow checks that an event at the root is sent when maxFiles is reached
|
// TestWatchOverflow checks that an event at the root is sent when maxFiles is reached
|
||||||
func TestWatchOverflow(t *testing.T) {
|
func TestWatchOverflow(t *testing.T) {
|
||||||
if runtime.GOOS == "openbsd" {
|
if build.IsOpenBSD {
|
||||||
t.Skip(failsOnOpenBSD)
|
t.Skip(failsOnOpenBSD)
|
||||||
}
|
}
|
||||||
name := "overflow"
|
name := "overflow"
|
||||||
@ -313,7 +313,7 @@ func TestWatchOverflow(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestWatchErrorLinuxInterpretation(t *testing.T) {
|
func TestWatchErrorLinuxInterpretation(t *testing.T) {
|
||||||
if runtime.GOOS != "linux" {
|
if !build.IsLinux {
|
||||||
t.Skip("testing of linux specific error codes")
|
t.Skip("testing of linux specific error codes")
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -341,7 +341,7 @@ func TestWatchErrorLinuxInterpretation(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestWatchSymlinkedRoot(t *testing.T) {
|
func TestWatchSymlinkedRoot(t *testing.T) {
|
||||||
if runtime.GOOS == "windows" {
|
if build.IsWindows {
|
||||||
t.Skip("Involves symlinks")
|
t.Skip("Involves symlinks")
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -385,7 +385,7 @@ func TestUnrootedChecked(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestWatchIssue4877(t *testing.T) {
|
func TestWatchIssue4877(t *testing.T) {
|
||||||
if runtime.GOOS != "windows" {
|
if !build.IsWindows {
|
||||||
t.Skip("Windows specific test")
|
t.Skip("Windows specific test")
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -440,7 +440,7 @@ func TestWatchModTime(t *testing.T) {
|
|||||||
|
|
||||||
var allowedEvents []Event
|
var allowedEvents []Event
|
||||||
// Apparently an event for the parent is also sent on mac
|
// Apparently an event for the parent is also sent on mac
|
||||||
if runtime.GOOS == "darwin" {
|
if build.IsDarwin {
|
||||||
allowedEvents = []Event{
|
allowedEvents = []Event{
|
||||||
{name, NonRemove},
|
{name, NonRemove},
|
||||||
}
|
}
|
||||||
|
@ -17,6 +17,8 @@ import (
|
|||||||
"sort"
|
"sort"
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/syncthing/syncthing/lib/build"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestFakeFS(t *testing.T) {
|
func TestFakeFS(t *testing.T) {
|
||||||
@ -563,7 +565,7 @@ func testFakeFSRenameInsensitive(t *testing.T, fs Filesystem) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// not checking on darwin due to https://github.com/golang/go/issues/35222
|
// not checking on darwin due to https://github.com/golang/go/issues/35222
|
||||||
if runtime.GOOS != "darwin" {
|
if !build.IsDarwin {
|
||||||
if err := fs.Rename("/foo/bar/BAZ", "/FOO/BAR/bAz"); err != nil {
|
if err := fs.Rename("/foo/bar/BAZ", "/FOO/BAR/bAz"); err != nil {
|
||||||
t.Errorf("Could not perform in-place case-only directory rename: %s", err)
|
t.Errorf("Could not perform in-place case-only directory rename: %s", err)
|
||||||
}
|
}
|
||||||
@ -786,7 +788,7 @@ func testFakeFSSameFile(t *testing.T, fs Filesystem) {
|
|||||||
t.Fatalf("Could not create %s: %s", filename, err)
|
t.Fatalf("Could not create %s: %s", filename, err)
|
||||||
} else {
|
} else {
|
||||||
fd.Close()
|
fd.Close()
|
||||||
if runtime.GOOS == "windows" {
|
if build.IsWindows {
|
||||||
time.Sleep(1 * time.Millisecond)
|
time.Sleep(1 * time.Millisecond)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -8,8 +8,9 @@ package fs
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"runtime"
|
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
"github.com/syncthing/syncthing/lib/build"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestIsInternal(t *testing.T) {
|
func TestIsInternal(t *testing.T) {
|
||||||
@ -120,7 +121,7 @@ func TestIsParent(t *testing.T) {
|
|||||||
testBoth := func(path, parent string, expected bool) {
|
testBoth := func(path, parent string, expected bool) {
|
||||||
t.Helper()
|
t.Helper()
|
||||||
test(path, parent, expected)
|
test(path, parent, expected)
|
||||||
if runtime.GOOS == "windows" {
|
if build.IsWindows {
|
||||||
test("C:/"+path, "C:/"+parent, expected)
|
test("C:/"+path, "C:/"+parent, expected)
|
||||||
} else {
|
} else {
|
||||||
test("/"+path, "/"+parent, expected)
|
test("/"+path, "/"+parent, expected)
|
||||||
@ -130,7 +131,7 @@ func TestIsParent(t *testing.T) {
|
|||||||
// rel - abs
|
// rel - abs
|
||||||
for _, parent := range []string{"/", "/foo", "/foo/bar"} {
|
for _, parent := range []string{"/", "/foo", "/foo/bar"} {
|
||||||
for _, path := range []string{"", ".", "foo", "foo/bar", "bas", "bas/baz"} {
|
for _, path := range []string{"", ".", "foo", "foo/bar", "bas", "bas/baz"} {
|
||||||
if runtime.GOOS == "windows" {
|
if build.IsWindows {
|
||||||
parent = "C:/" + parent
|
parent = "C:/" + parent
|
||||||
}
|
}
|
||||||
test(parent, path, false)
|
test(parent, path, false)
|
||||||
@ -140,7 +141,7 @@ func TestIsParent(t *testing.T) {
|
|||||||
|
|
||||||
// equal
|
// equal
|
||||||
for i, path := range []string{"/", "/foo", "/foo/bar", "", ".", "foo", "foo/bar"} {
|
for i, path := range []string{"/", "/foo", "/foo/bar", "", ".", "foo", "foo/bar"} {
|
||||||
if i < 3 && runtime.GOOS == "windows" {
|
if i < 3 && build.IsWindows {
|
||||||
path = "C:" + path
|
path = "C:" + path
|
||||||
}
|
}
|
||||||
test(path, path, false)
|
test(path, path, false)
|
||||||
@ -164,7 +165,7 @@ func TestIsParent(t *testing.T) {
|
|||||||
for _, path := range []string{"foo/bar/baz", "foo/bar/baz/bas"} {
|
for _, path := range []string{"foo/bar/baz", "foo/bar/baz/bas"} {
|
||||||
testBoth(path, parent, true)
|
testBoth(path, parent, true)
|
||||||
testBoth(parent, path, false)
|
testBoth(parent, path, false)
|
||||||
if runtime.GOOS == "windows" {
|
if build.IsWindows {
|
||||||
test("C:/"+path, "D:/"+parent, false)
|
test("C:/"+path, "D:/"+parent, false)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -10,9 +10,10 @@ import (
|
|||||||
"errors"
|
"errors"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"runtime"
|
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/syncthing/syncthing/lib/build"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestMtimeFS(t *testing.T) {
|
func TestMtimeFS(t *testing.T) {
|
||||||
@ -181,11 +182,10 @@ func TestMtimeFSOpen(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestMtimeFSInsensitive(t *testing.T) {
|
func TestMtimeFSInsensitive(t *testing.T) {
|
||||||
switch runtime.GOOS {
|
if build.IsDarwin || build.IsWindows {
|
||||||
case "darwin", "windows":
|
|
||||||
// blatantly assume file systems here are case insensitive. Might be
|
// blatantly assume file systems here are case insensitive. Might be
|
||||||
// a spurious failure on oddly configured systems.
|
// a spurious failure on oddly configured systems.
|
||||||
default:
|
} else {
|
||||||
t.Skip("need case insensitive FS")
|
t.Skip("need case insensitive FS")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -9,9 +9,9 @@ package fs
|
|||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"runtime"
|
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
"github.com/syncthing/syncthing/lib/build"
|
||||||
"github.com/syncthing/syncthing/lib/sha256"
|
"github.com/syncthing/syncthing/lib/sha256"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -21,7 +21,7 @@ const (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func tempPrefix() string {
|
func tempPrefix() string {
|
||||||
if runtime.GOOS == "windows" {
|
if build.IsWindows {
|
||||||
return WindowsTempPrefix
|
return WindowsTempPrefix
|
||||||
} else {
|
} else {
|
||||||
return UnixTempPrefix
|
return UnixTempPrefix
|
||||||
|
@ -10,9 +10,10 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"runtime"
|
|
||||||
"strings"
|
"strings"
|
||||||
"unicode"
|
"unicode"
|
||||||
|
|
||||||
|
"github.com/syncthing/syncthing/lib/build"
|
||||||
)
|
)
|
||||||
|
|
||||||
const pathSeparatorString = string(PathSeparator)
|
const pathSeparatorString = string(PathSeparator)
|
||||||
@ -35,7 +36,7 @@ func ExpandTilde(path string) (string, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func getHomeDir() (string, error) {
|
func getHomeDir() (string, error) {
|
||||||
if runtime.GOOS == "windows" {
|
if build.IsWindows {
|
||||||
// Legacy -- we prioritize this for historical reasons, whereas
|
// Legacy -- we prioritize this for historical reasons, whereas
|
||||||
// os.UserHomeDir uses %USERPROFILE% always.
|
// os.UserHomeDir uses %USERPROFILE% always.
|
||||||
home := filepath.Join(os.Getenv("HomeDrive"), os.Getenv("HomePath"))
|
home := filepath.Join(os.Getenv("HomeDrive"), os.Getenv("HomePath"))
|
||||||
@ -196,7 +197,7 @@ func CommonPrefix(first, second string) string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if isAbs {
|
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
|
// 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.
|
// Wedge an empty element to be joined with.
|
||||||
common = append(common, "")
|
common = append(common, "")
|
||||||
|
@ -8,10 +8,11 @@ package fs
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"math/rand"
|
"math/rand"
|
||||||
"runtime"
|
|
||||||
"testing"
|
"testing"
|
||||||
"unicode"
|
"unicode"
|
||||||
"unicode/utf8"
|
"unicode/utf8"
|
||||||
|
|
||||||
|
"github.com/syncthing/syncthing/lib/build"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestCommonPrefix(t *testing.T) {
|
func TestCommonPrefix(t *testing.T) {
|
||||||
@ -23,7 +24,7 @@ func TestCommonPrefix(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if runtime.GOOS == "windows" {
|
if build.IsWindows {
|
||||||
test(`c:\Audrius\Downloads`, `c:\Audrius\Docs`, `c:\Audrius`)
|
test(`c:\Audrius\Downloads`, `c:\Audrius\Docs`, `c:\Audrius`)
|
||||||
test(`c:\Audrius\Downloads`, `C:\Audrius\Docs`, ``) // Case differences :(
|
test(`c:\Audrius\Downloads`, `C:\Audrius\Docs`, ``) // Case differences :(
|
||||||
test(`C:\Audrius-a\Downloads`, `C:\Audrius-b\Docs`, `C:\`)
|
test(`C:\Audrius-a\Downloads`, `C:\Audrius-b\Docs`, `C:\`)
|
||||||
|
@ -11,12 +11,13 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
osexec "os/exec"
|
osexec "os/exec"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"runtime"
|
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
"github.com/syncthing/syncthing/lib/build"
|
||||||
)
|
)
|
||||||
|
|
||||||
func testWalkSkipSymlink(t *testing.T, fsType FilesystemType, uri string) {
|
func testWalkSkipSymlink(t *testing.T, fsType FilesystemType, uri string) {
|
||||||
if runtime.GOOS == "windows" {
|
if build.IsWindows {
|
||||||
t.Skip("Symlinks skipping is not tested on windows")
|
t.Skip("Symlinks skipping is not tested on windows")
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -53,7 +54,7 @@ func createDirJunct(target string, name string) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func testWalkTraverseDirJunct(t *testing.T, fsType FilesystemType, uri string) {
|
func testWalkTraverseDirJunct(t *testing.T, fsType FilesystemType, uri string) {
|
||||||
if runtime.GOOS != "windows" {
|
if !build.IsWindows {
|
||||||
t.Skip("Directory junctions are available and tested on windows only")
|
t.Skip("Directory junctions are available and tested on windows only")
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -86,7 +87,7 @@ func testWalkTraverseDirJunct(t *testing.T, fsType FilesystemType, uri string) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func testWalkInfiniteRecursion(t *testing.T, fsType FilesystemType, uri string) {
|
func testWalkInfiniteRecursion(t *testing.T, fsType FilesystemType, uri string) {
|
||||||
if runtime.GOOS != "windows" {
|
if !build.IsWindows {
|
||||||
t.Skip("Infinite recursion detection is tested on windows only")
|
t.Skip("Infinite recursion detection is tested on windows only")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -13,12 +13,12 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"runtime"
|
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/gobwas/glob"
|
"github.com/gobwas/glob"
|
||||||
|
|
||||||
|
"github.com/syncthing/syncthing/lib/build"
|
||||||
"github.com/syncthing/syncthing/lib/fs"
|
"github.com/syncthing/syncthing/lib/fs"
|
||||||
"github.com/syncthing/syncthing/lib/osutil"
|
"github.com/syncthing/syncthing/lib/osutil"
|
||||||
"github.com/syncthing/syncthing/lib/sha256"
|
"github.com/syncthing/syncthing/lib/sha256"
|
||||||
@ -35,7 +35,7 @@ const (
|
|||||||
var defaultResult Result = resultInclude
|
var defaultResult Result = resultInclude
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
if runtime.GOOS == "darwin" || runtime.GOOS == "windows" {
|
if build.IsDarwin || build.IsWindows {
|
||||||
defaultResult |= resultFoldCase
|
defaultResult |= resultFoldCase
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -12,11 +12,11 @@ import (
|
|||||||
"io"
|
"io"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"runtime"
|
|
||||||
"strings"
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/syncthing/syncthing/lib/build"
|
||||||
"github.com/syncthing/syncthing/lib/fs"
|
"github.com/syncthing/syncthing/lib/fs"
|
||||||
"github.com/syncthing/syncthing/lib/osutil"
|
"github.com/syncthing/syncthing/lib/osutil"
|
||||||
)
|
)
|
||||||
@ -210,10 +210,9 @@ func TestCaseSensitivity(t *testing.T) {
|
|||||||
match := []string{"test"}
|
match := []string{"test"}
|
||||||
dontMatch := []string{"foo"}
|
dontMatch := []string{"foo"}
|
||||||
|
|
||||||
switch runtime.GOOS {
|
if build.IsDarwin || build.IsWindows {
|
||||||
case "darwin", "windows":
|
|
||||||
match = append(match, "TEST", "Test", "tESt")
|
match = append(match, "TEST", "Test", "tESt")
|
||||||
default:
|
} else {
|
||||||
dontMatch = append(dontMatch, "TEST", "Test", "tESt")
|
dontMatch = append(dontMatch, "TEST", "Test", "tESt")
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -618,7 +617,7 @@ func TestHashOfEmpty(t *testing.T) {
|
|||||||
func TestWindowsPatterns(t *testing.T) {
|
func TestWindowsPatterns(t *testing.T) {
|
||||||
// We should accept patterns as both a/b and a\b and match that against
|
// We should accept patterns as both a/b and a\b and match that against
|
||||||
// both kinds of slash as well.
|
// both kinds of slash as well.
|
||||||
if runtime.GOOS != "windows" {
|
if !build.IsWindows {
|
||||||
t.Skip("Windows specific test")
|
t.Skip("Windows specific test")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -643,7 +642,7 @@ func TestWindowsPatterns(t *testing.T) {
|
|||||||
|
|
||||||
func TestAutomaticCaseInsensitivity(t *testing.T) {
|
func TestAutomaticCaseInsensitivity(t *testing.T) {
|
||||||
// We should do case insensitive matching by default on some platforms.
|
// We should do case insensitive matching by default on some platforms.
|
||||||
if runtime.GOOS != "windows" && runtime.GOOS != "darwin" {
|
if !build.IsWindows && !build.IsDarwin {
|
||||||
t.Skip("Windows/Mac specific test")
|
t.Skip("Windows/Mac specific test")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -1205,7 +1204,7 @@ func TestEmptyPatterns(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestWindowsLineEndings(t *testing.T) {
|
func TestWindowsLineEndings(t *testing.T) {
|
||||||
if runtime.GOOS != "windows" {
|
if !build.IsWindows {
|
||||||
t.Skip("Windows specific")
|
t.Skip("Windows specific")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -14,6 +14,7 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/syncthing/syncthing/lib/build"
|
||||||
"github.com/syncthing/syncthing/lib/fs"
|
"github.com/syncthing/syncthing/lib/fs"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -133,13 +134,13 @@ func expandLocations() error {
|
|||||||
// trying.
|
// trying.
|
||||||
func defaultConfigDir(userHome string) string {
|
func defaultConfigDir(userHome string) string {
|
||||||
switch runtime.GOOS {
|
switch runtime.GOOS {
|
||||||
case "windows":
|
case build.Windows:
|
||||||
if p := os.Getenv("LocalAppData"); p != "" {
|
if p := os.Getenv("LocalAppData"); p != "" {
|
||||||
return filepath.Join(p, "Syncthing")
|
return filepath.Join(p, "Syncthing")
|
||||||
}
|
}
|
||||||
return filepath.Join(os.Getenv("AppData"), "Syncthing")
|
return filepath.Join(os.Getenv("AppData"), "Syncthing")
|
||||||
|
|
||||||
case "darwin":
|
case build.Darwin:
|
||||||
return filepath.Join(userHome, "Library/Application Support/Syncthing")
|
return filepath.Join(userHome, "Library/Application Support/Syncthing")
|
||||||
|
|
||||||
default:
|
default:
|
||||||
@ -153,30 +154,28 @@ func defaultConfigDir(userHome string) string {
|
|||||||
// defaultDataDir returns the default data directory, which usually is the
|
// defaultDataDir returns the default data directory, which usually is the
|
||||||
// config directory but might be something else.
|
// config directory but might be something else.
|
||||||
func defaultDataDir(userHome, config string) string {
|
func defaultDataDir(userHome, config string) string {
|
||||||
switch runtime.GOOS {
|
if build.IsWindows || build.IsDarwin {
|
||||||
case "windows", "darwin":
|
|
||||||
return config
|
|
||||||
|
|
||||||
default:
|
|
||||||
// If a database exists at the "normal" location, use that anyway.
|
|
||||||
if _, err := os.Lstat(filepath.Join(config, LevelDBDir)); err == nil {
|
|
||||||
return config
|
|
||||||
}
|
|
||||||
// Always use this env var, as it's explicitly set by the user
|
|
||||||
if xdgHome := os.Getenv("XDG_DATA_HOME"); xdgHome != "" {
|
|
||||||
return filepath.Join(xdgHome, "syncthing")
|
|
||||||
}
|
|
||||||
// Only use the XDG default, if a syncthing specific dir already
|
|
||||||
// exists. Existence of ~/.local/share is not deemed enough, as
|
|
||||||
// it may also exist erroneously on non-XDG systems.
|
|
||||||
xdgDefault := filepath.Join(userHome, ".local/share/syncthing")
|
|
||||||
if _, err := os.Lstat(xdgDefault); err == nil {
|
|
||||||
return xdgDefault
|
|
||||||
}
|
|
||||||
// FYI: XDG_DATA_DIRS is not relevant, as it is for system-wide
|
|
||||||
// data dirs, not user specific ones.
|
|
||||||
return config
|
return config
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// If a database exists at the "normal" location, use that anyway.
|
||||||
|
if _, err := os.Lstat(filepath.Join(config, LevelDBDir)); err == nil {
|
||||||
|
return config
|
||||||
|
}
|
||||||
|
// Always use this env var, as it's explicitly set by the user
|
||||||
|
if xdgHome := os.Getenv("XDG_DATA_HOME"); xdgHome != "" {
|
||||||
|
return filepath.Join(xdgHome, "syncthing")
|
||||||
|
}
|
||||||
|
// Only use the XDG default, if a syncthing specific dir already
|
||||||
|
// exists. Existence of ~/.local/share is not deemed enough, as
|
||||||
|
// it may also exist erroneously on non-XDG systems.
|
||||||
|
xdgDefault := filepath.Join(userHome, ".local/share/syncthing")
|
||||||
|
if _, err := os.Lstat(xdgDefault); err == nil {
|
||||||
|
return xdgDefault
|
||||||
|
}
|
||||||
|
// FYI: XDG_DATA_DIRS is not relevant, as it is for system-wide
|
||||||
|
// data dirs, not user specific ones.
|
||||||
|
return config
|
||||||
}
|
}
|
||||||
|
|
||||||
// userHomeDir returns the user's home directory, or dies trying.
|
// userHomeDir returns the user's home directory, or dies trying.
|
||||||
|
@ -11,7 +11,6 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"runtime"
|
|
||||||
"sort"
|
"sort"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
@ -19,6 +18,7 @@ import (
|
|||||||
|
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
|
|
||||||
|
"github.com/syncthing/syncthing/lib/build"
|
||||||
"github.com/syncthing/syncthing/lib/config"
|
"github.com/syncthing/syncthing/lib/config"
|
||||||
"github.com/syncthing/syncthing/lib/db"
|
"github.com/syncthing/syncthing/lib/db"
|
||||||
"github.com/syncthing/syncthing/lib/events"
|
"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)
|
l.Debugln(f, "Handling ignored file", file)
|
||||||
dbUpdateChan <- dbUpdateJob{file, dbUpdateInvalidate}
|
dbUpdateChan <- dbUpdateJob{file, dbUpdateInvalidate}
|
||||||
|
|
||||||
case runtime.GOOS == "windows" && fs.WindowsInvalidFilename(file.Name) != nil:
|
case build.IsWindows && fs.WindowsInvalidFilename(file.Name) != nil:
|
||||||
if file.IsDeleted() {
|
if file.IsDeleted() {
|
||||||
// Just pretend we deleted it, no reason to create an error
|
// Just pretend we deleted it, no reason to create an error
|
||||||
// about a deleted file that we can't have anyway.
|
// 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())
|
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 {
|
if err := f.handleSymlinkCheckExisting(file, snap, scanChan); err != nil {
|
||||||
f.newPullError(file.Name, fmt.Errorf("handling unsupported symlink: %w", err))
|
f.newPullError(file.Name, fmt.Errorf("handling unsupported symlink: %w", err))
|
||||||
break
|
break
|
||||||
@ -2115,7 +2115,7 @@ func (f *sendReceiveFolder) maybeAdjustOwnership(file *protocol.FileInfo, name s
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (f *sendReceiveFolder) copyOwnershipFromParent(path string) error {
|
func (f *sendReceiveFolder) copyOwnershipFromParent(path string) error {
|
||||||
if runtime.GOOS == "windows" {
|
if build.IsWindows {
|
||||||
// Can't do anything.
|
// Can't do anything.
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
@ -15,12 +15,12 @@ import (
|
|||||||
"io"
|
"io"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"runtime"
|
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/syncthing/syncthing/lib/build"
|
||||||
"github.com/syncthing/syncthing/lib/events"
|
"github.com/syncthing/syncthing/lib/events"
|
||||||
"github.com/syncthing/syncthing/lib/fs"
|
"github.com/syncthing/syncthing/lib/fs"
|
||||||
"github.com/syncthing/syncthing/lib/ignore"
|
"github.com/syncthing/syncthing/lib/ignore"
|
||||||
@ -205,7 +205,7 @@ func TestHandleFileWithTemp(t *testing.T) {
|
|||||||
|
|
||||||
func TestCopierFinder(t *testing.T) {
|
func TestCopierFinder(t *testing.T) {
|
||||||
methods := []fs.CopyRangeMethod{fs.CopyRangeMethodStandard, fs.CopyRangeMethodAllWithFallback}
|
methods := []fs.CopyRangeMethod{fs.CopyRangeMethodStandard, fs.CopyRangeMethodAllWithFallback}
|
||||||
if runtime.GOOS == "linux" {
|
if build.IsLinux {
|
||||||
methods = append(methods, fs.CopyRangeMethodSendFile)
|
methods = append(methods, fs.CopyRangeMethodSendFile)
|
||||||
}
|
}
|
||||||
for _, method := range methods {
|
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
|
// Verifies that owner and group are copied from the parent, for both
|
||||||
// files and directories.
|
// files and directories.
|
||||||
|
|
||||||
if runtime.GOOS == "windows" {
|
if build.IsWindows {
|
||||||
t.Skip("copying owner not supported on Windows")
|
t.Skip("copying owner not supported on Windows")
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -986,7 +986,7 @@ func TestDeleteBehindSymlink(t *testing.T) {
|
|||||||
must(t, ffs.RemoveAll(link))
|
must(t, ffs.RemoveAll(link))
|
||||||
|
|
||||||
if err := fs.DebugSymlinkForTestsOnly(destFs, ffs, "", link); err != nil {
|
if err := fs.DebugSymlinkForTestsOnly(destFs, ffs, "", link); err != nil {
|
||||||
if runtime.GOOS == "windows" {
|
if build.IsWindows {
|
||||||
// Probably we require permissions we don't have.
|
// Probably we require permissions we don't have.
|
||||||
t.Skip("Need admin permissions or developer mode to run symlink test on Windows: " + err.Error())
|
t.Skip("Need admin permissions or developer mode to run symlink test on Windows: " + err.Error())
|
||||||
} else {
|
} else {
|
||||||
@ -1145,7 +1145,7 @@ func TestPullCaseOnlyDir(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestPullCaseOnlySymlink(t *testing.T) {
|
func TestPullCaseOnlySymlink(t *testing.T) {
|
||||||
if runtime.GOOS == "windows" {
|
if build.IsWindows {
|
||||||
t.Skip("symlinks not supported on windows")
|
t.Skip("symlinks not supported on windows")
|
||||||
}
|
}
|
||||||
testPullCaseOnlyDirOrSymlink(t, false)
|
testPullCaseOnlyDirOrSymlink(t, false)
|
||||||
@ -1275,7 +1275,7 @@ func TestPullCaseOnlyRename(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestPullSymlinkOverExistingWindows(t *testing.T) {
|
func TestPullSymlinkOverExistingWindows(t *testing.T) {
|
||||||
if runtime.GOOS != "windows" {
|
if !build.IsWindows {
|
||||||
t.Skip()
|
t.Skip()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -8,11 +8,11 @@ package model
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"runtime"
|
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/d4l3k/messagediff"
|
"github.com/d4l3k/messagediff"
|
||||||
|
|
||||||
|
"github.com/syncthing/syncthing/lib/build"
|
||||||
"github.com/syncthing/syncthing/lib/config"
|
"github.com/syncthing/syncthing/lib/config"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -96,7 +96,7 @@ func unifySubsCases() []unifySubsCase {
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
if runtime.GOOS == "windows" {
|
if build.IsWindows {
|
||||||
// Fixup path separators
|
// Fixup path separators
|
||||||
for i := range cases {
|
for i := range cases {
|
||||||
for j, p := range cases[i].in {
|
for j, p := range cases[i].in {
|
||||||
|
@ -27,6 +27,7 @@ import (
|
|||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
"github.com/thejerf/suture/v4"
|
"github.com/thejerf/suture/v4"
|
||||||
|
|
||||||
|
"github.com/syncthing/syncthing/lib/build"
|
||||||
"github.com/syncthing/syncthing/lib/config"
|
"github.com/syncthing/syncthing/lib/config"
|
||||||
"github.com/syncthing/syncthing/lib/connections"
|
"github.com/syncthing/syncthing/lib/connections"
|
||||||
"github.com/syncthing/syncthing/lib/db"
|
"github.com/syncthing/syncthing/lib/db"
|
||||||
@ -2399,7 +2400,7 @@ func (m *model) numHashers(folder string) int {
|
|||||||
return folderCfg.Hashers
|
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
|
// Interactive operating systems; don't load the system too heavily by
|
||||||
// default.
|
// default.
|
||||||
return 1
|
return 1
|
||||||
|
@ -15,7 +15,6 @@ import (
|
|||||||
"math/rand"
|
"math/rand"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"runtime"
|
|
||||||
"runtime/pprof"
|
"runtime/pprof"
|
||||||
"sort"
|
"sort"
|
||||||
"strconv"
|
"strconv"
|
||||||
@ -26,6 +25,7 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
|
"github.com/syncthing/syncthing/lib/build"
|
||||||
"github.com/syncthing/syncthing/lib/config"
|
"github.com/syncthing/syncthing/lib/config"
|
||||||
"github.com/syncthing/syncthing/lib/db"
|
"github.com/syncthing/syncthing/lib/db"
|
||||||
"github.com/syncthing/syncthing/lib/db/backend"
|
"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)
|
t.Errorf("Incorrect ignores: %v != %v", ignores2, ignores)
|
||||||
}
|
}
|
||||||
|
|
||||||
if runtime.GOOS == "darwin" {
|
if build.IsDarwin {
|
||||||
// see above
|
// see above
|
||||||
time.Sleep(time.Second)
|
time.Sleep(time.Second)
|
||||||
} else {
|
} else {
|
||||||
@ -2130,7 +2130,7 @@ func TestIssue4357(t *testing.T) {
|
|||||||
func TestIssue2782(t *testing.T) {
|
func TestIssue2782(t *testing.T) {
|
||||||
// CheckHealth should accept a symlinked folder, when using tilde-expanded path.
|
// CheckHealth should accept a symlinked folder, when using tilde-expanded path.
|
||||||
|
|
||||||
if runtime.GOOS == "windows" {
|
if build.IsWindows {
|
||||||
t.Skip("not reliable on Windows")
|
t.Skip("not reliable on Windows")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -2471,7 +2471,7 @@ func TestNoRequestsFromPausedDevices(t *testing.T) {
|
|||||||
|
|
||||||
// TestIssue2571 tests replacing a directory with content with a symlink
|
// TestIssue2571 tests replacing a directory with content with a symlink
|
||||||
func TestIssue2571(t *testing.T) {
|
func TestIssue2571(t *testing.T) {
|
||||||
if runtime.GOOS == "windows" {
|
if build.IsWindows {
|
||||||
t.Skip("Scanning symlinks isn't supported on windows")
|
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
|
// TestIssue4573 tests that contents of an unavailable dir aren't marked deleted
|
||||||
func TestIssue4573(t *testing.T) {
|
func TestIssue4573(t *testing.T) {
|
||||||
if runtime.GOOS == "windows" {
|
if build.IsWindows {
|
||||||
t.Skip("Can't make the dir inaccessible on windows")
|
t.Skip("Can't make the dir inaccessible on windows")
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2802,7 +2802,7 @@ func TestVersionRestore(t *testing.T) {
|
|||||||
"dir/file.txt",
|
"dir/file.txt",
|
||||||
"dir/existing.txt",
|
"dir/existing.txt",
|
||||||
} {
|
} {
|
||||||
if runtime.GOOS == "windows" {
|
if build.IsWindows {
|
||||||
file = filepath.FromSlash(file)
|
file = filepath.FromSlash(file)
|
||||||
}
|
}
|
||||||
dir := filepath.Dir(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.
|
// Check that content of files matches to the version they've been restored.
|
||||||
for file, version := range restore {
|
for file, version := range restore {
|
||||||
if runtime.GOOS == "windows" {
|
if build.IsWindows {
|
||||||
file = filepath.FromSlash(file)
|
file = filepath.FromSlash(file)
|
||||||
}
|
}
|
||||||
tag := version.In(time.Local).Truncate(time.Second).Format(versioner.TimeFormat)
|
tag := version.In(time.Local).Truncate(time.Second).Format(versioner.TimeFormat)
|
||||||
@ -2918,7 +2918,7 @@ func TestVersionRestore(t *testing.T) {
|
|||||||
must(t, err)
|
must(t, err)
|
||||||
for file, versions := range allFileVersions {
|
for file, versions := range allFileVersions {
|
||||||
key := file
|
key := file
|
||||||
if runtime.GOOS == "windows" {
|
if build.IsWindows {
|
||||||
file = filepath.FromSlash(file)
|
file = filepath.FromSlash(file)
|
||||||
}
|
}
|
||||||
for _, version := range versions {
|
for _, version := range versions {
|
||||||
|
@ -12,13 +12,13 @@ import (
|
|||||||
"errors"
|
"errors"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"runtime"
|
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/syncthing/syncthing/lib/build"
|
||||||
"github.com/syncthing/syncthing/lib/config"
|
"github.com/syncthing/syncthing/lib/config"
|
||||||
"github.com/syncthing/syncthing/lib/events"
|
"github.com/syncthing/syncthing/lib/events"
|
||||||
"github.com/syncthing/syncthing/lib/fs"
|
"github.com/syncthing/syncthing/lib/fs"
|
||||||
@ -72,7 +72,7 @@ func TestRequestSimple(t *testing.T) {
|
|||||||
func TestSymlinkTraversalRead(t *testing.T) {
|
func TestSymlinkTraversalRead(t *testing.T) {
|
||||||
// Verify that a symlink can not be traversed for reading.
|
// Verify that a symlink can not be traversed for reading.
|
||||||
|
|
||||||
if runtime.GOOS == "windows" {
|
if build.IsWindows {
|
||||||
t.Skip("no symlink support on CI")
|
t.Skip("no symlink support on CI")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -115,7 +115,7 @@ func TestSymlinkTraversalRead(t *testing.T) {
|
|||||||
func TestSymlinkTraversalWrite(t *testing.T) {
|
func TestSymlinkTraversalWrite(t *testing.T) {
|
||||||
// Verify that a symlink can not be traversed for writing.
|
// Verify that a symlink can not be traversed for writing.
|
||||||
|
|
||||||
if runtime.GOOS == "windows" {
|
if build.IsWindows {
|
||||||
t.Skip("no symlink support on CI")
|
t.Skip("no symlink support on CI")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -214,7 +214,7 @@ func TestRequestCreateTmpSymlink(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestRequestVersioningSymlinkAttack(t *testing.T) {
|
func TestRequestVersioningSymlinkAttack(t *testing.T) {
|
||||||
if runtime.GOOS == "windows" {
|
if build.IsWindows {
|
||||||
t.Skip("no symlink support on Windows")
|
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
|
// TestRequestSymlinkWindows checks that symlinks aren't marked as deleted on windows
|
||||||
// Issue: https://github.com/syncthing/syncthing/issues/5125
|
// Issue: https://github.com/syncthing/syncthing/issues/5125
|
||||||
func TestRequestSymlinkWindows(t *testing.T) {
|
func TestRequestSymlinkWindows(t *testing.T) {
|
||||||
if runtime.GOOS != "windows" {
|
if !build.IsWindows {
|
||||||
t.Skip("windows specific test")
|
t.Skip("windows specific test")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -7,9 +7,9 @@
|
|||||||
package model
|
package model
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"runtime"
|
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
"github.com/syncthing/syncthing/lib/build"
|
||||||
"github.com/syncthing/syncthing/lib/fs"
|
"github.com/syncthing/syncthing/lib/fs"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -70,7 +70,7 @@ func TestInWriteableDir(t *testing.T) {
|
|||||||
func TestOSWindowsRemove(t *testing.T) {
|
func TestOSWindowsRemove(t *testing.T) {
|
||||||
// os.Remove should remove read only things on windows
|
// os.Remove should remove read only things on windows
|
||||||
|
|
||||||
if runtime.GOOS != "windows" {
|
if !build.IsWindows {
|
||||||
t.Skipf("Tests not required")
|
t.Skipf("Tests not required")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -107,7 +107,7 @@ func TestOSWindowsRemove(t *testing.T) {
|
|||||||
func TestOSWindowsRemoveAll(t *testing.T) {
|
func TestOSWindowsRemoveAll(t *testing.T) {
|
||||||
// os.RemoveAll should remove read only things on windows
|
// os.RemoveAll should remove read only things on windows
|
||||||
|
|
||||||
if runtime.GOOS != "windows" {
|
if !build.IsWindows {
|
||||||
t.Skipf("Tests not required")
|
t.Skipf("Tests not required")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -139,7 +139,7 @@ func TestOSWindowsRemoveAll(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestInWritableDirWindowsRename(t *testing.T) {
|
func TestInWritableDirWindowsRename(t *testing.T) {
|
||||||
if runtime.GOOS != "windows" {
|
if !build.IsWindows {
|
||||||
t.Skipf("Tests not required")
|
t.Skipf("Tests not required")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -9,8 +9,8 @@ package osutil
|
|||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"runtime"
|
|
||||||
|
|
||||||
|
"github.com/syncthing/syncthing/lib/build"
|
||||||
"github.com/syncthing/syncthing/lib/fs"
|
"github.com/syncthing/syncthing/lib/fs"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -97,7 +97,7 @@ func (w *AtomicWriter) Close() error {
|
|||||||
return infoErr
|
return infoErr
|
||||||
}
|
}
|
||||||
err := w.fs.Rename(w.next.Name(), w.path)
|
err := w.fs.Rename(w.next.Name(), w.path)
|
||||||
if runtime.GOOS == "windows" && fs.IsPermission(err) {
|
if build.IsWindows && fs.IsPermission(err) {
|
||||||
// On Windows, we might not be allowed to rename over the file
|
// On Windows, we might not be allowed to rename over the file
|
||||||
// because it's read-only. Get us some write permissions and try
|
// because it's read-only. Get us some write permissions and try
|
||||||
// again.
|
// again.
|
||||||
|
@ -9,9 +9,9 @@ package osutil
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"runtime"
|
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
"github.com/syncthing/syncthing/lib/build"
|
||||||
"github.com/syncthing/syncthing/lib/fs"
|
"github.com/syncthing/syncthing/lib/fs"
|
||||||
"github.com/syncthing/syncthing/lib/sync"
|
"github.com/syncthing/syncthing/lib/sync"
|
||||||
)
|
)
|
||||||
@ -90,7 +90,7 @@ func withPreparedTarget(filesystem fs.Filesystem, from, to string, f func() erro
|
|||||||
}
|
}
|
||||||
|
|
||||||
// On Windows, make sure the destination file is writeable (or we can't delete it)
|
// On Windows, make sure the destination file is writeable (or we can't delete it)
|
||||||
if runtime.GOOS == "windows" {
|
if build.IsWindows {
|
||||||
filesystem.Chmod(to, 0666)
|
filesystem.Chmod(to, 0666)
|
||||||
if !strings.EqualFold(from, to) {
|
if !strings.EqualFold(from, to) {
|
||||||
err := filesystem.Remove(to)
|
err := filesystem.Remove(to)
|
||||||
|
@ -10,10 +10,10 @@ import (
|
|||||||
"io"
|
"io"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"runtime"
|
|
||||||
"strings"
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
"github.com/syncthing/syncthing/lib/build"
|
||||||
"github.com/syncthing/syncthing/lib/fs"
|
"github.com/syncthing/syncthing/lib/fs"
|
||||||
"github.com/syncthing/syncthing/lib/osutil"
|
"github.com/syncthing/syncthing/lib/osutil"
|
||||||
)
|
)
|
||||||
@ -51,7 +51,7 @@ func TestIsDeleted(t *testing.T) {
|
|||||||
}
|
}
|
||||||
fd.Close()
|
fd.Close()
|
||||||
}
|
}
|
||||||
if runtime.GOOS != "windows" {
|
if !build.IsWindows {
|
||||||
// Can't create unreadable dir on windows
|
// Can't create unreadable dir on windows
|
||||||
testFs.MkdirAll("inacc", 0777)
|
testFs.MkdirAll("inacc", 0777)
|
||||||
if err := testFs.Chmod("inacc", 0000); err == nil {
|
if err := testFs.Chmod("inacc", 0000); err == nil {
|
||||||
@ -63,7 +63,7 @@ func TestIsDeleted(t *testing.T) {
|
|||||||
}
|
}
|
||||||
for _, n := range []string{"Dir", "File", "Del"} {
|
for _, n := range []string{"Dir", "File", "Del"} {
|
||||||
if err := fs.DebugSymlinkForTestsOnly(testFs, testFs, strings.ToLower(n), "linkTo"+n); err != nil {
|
if err := fs.DebugSymlinkForTestsOnly(testFs, testFs, strings.ToLower(n), "linkTo"+n); err != nil {
|
||||||
if runtime.GOOS == "windows" {
|
if build.IsWindows {
|
||||||
t.Skip("Symlinks aren't working")
|
t.Skip("Symlinks aren't working")
|
||||||
}
|
}
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
|
@ -9,7 +9,8 @@ package osutil
|
|||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"io"
|
"io"
|
||||||
"runtime"
|
|
||||||
|
"github.com/syncthing/syncthing/lib/build"
|
||||||
)
|
)
|
||||||
|
|
||||||
type ReplacingWriter struct {
|
type ReplacingWriter struct {
|
||||||
@ -51,7 +52,7 @@ func (w ReplacingWriter) Write(bs []byte) (int, error) {
|
|||||||
// LineEndingsWriter returns a writer that writes platform-appropriate line
|
// LineEndingsWriter returns a writer that writes platform-appropriate line
|
||||||
// endings. (This is a no-op on non-Windows platforms.)
|
// endings. (This is a no-op on non-Windows platforms.)
|
||||||
func LineEndingsWriter(w io.Writer) io.Writer {
|
func LineEndingsWriter(w io.Writer) io.Writer {
|
||||||
if runtime.GOOS != "windows" {
|
if !build.IsWindows {
|
||||||
return w
|
return w
|
||||||
}
|
}
|
||||||
return &ReplacingWriter{
|
return &ReplacingWriter{
|
||||||
|
@ -10,8 +10,9 @@
|
|||||||
package osutil
|
package osutil
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"runtime"
|
|
||||||
"syscall"
|
"syscall"
|
||||||
|
|
||||||
|
"github.com/syncthing/syncthing/lib/build"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
@ -36,7 +37,7 @@ func MaximizeOpenFileLimit() (int, error) {
|
|||||||
|
|
||||||
// macOS doesn't like a soft limit greater then OPEN_MAX
|
// macOS doesn't like a soft limit greater then OPEN_MAX
|
||||||
// See also: man setrlimit
|
// See also: man setrlimit
|
||||||
if runtime.GOOS == "darwin" && lim.Max > darwinOpenMax {
|
if build.IsDarwin && lim.Max > darwinOpenMax {
|
||||||
lim.Max = darwinOpenMax
|
lim.Max = darwinOpenMax
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -9,9 +9,9 @@ package osutil_test
|
|||||||
import (
|
import (
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"runtime"
|
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
"github.com/syncthing/syncthing/lib/build"
|
||||||
"github.com/syncthing/syncthing/lib/fs"
|
"github.com/syncthing/syncthing/lib/fs"
|
||||||
"github.com/syncthing/syncthing/lib/osutil"
|
"github.com/syncthing/syncthing/lib/osutil"
|
||||||
)
|
)
|
||||||
@ -22,7 +22,7 @@ func TestTraversesSymlink(t *testing.T) {
|
|||||||
testFs := fs.NewFilesystem(fs.FilesystemTypeBasic, tmpDir)
|
testFs := fs.NewFilesystem(fs.FilesystemTypeBasic, tmpDir)
|
||||||
testFs.MkdirAll("a/b/c", 0755)
|
testFs.MkdirAll("a/b/c", 0755)
|
||||||
if err := fs.DebugSymlinkForTestsOnly(testFs, testFs, filepath.Join("a", "b"), filepath.Join("a", "l")); err != nil {
|
if err := fs.DebugSymlinkForTestsOnly(testFs, testFs, filepath.Join("a", "b"), filepath.Join("a", "l")); err != nil {
|
||||||
if runtime.GOOS == "windows" {
|
if build.IsWindows {
|
||||||
t.Skip("Symlinks aren't working")
|
t.Skip("Symlinks aren't working")
|
||||||
}
|
}
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
@ -71,7 +71,7 @@ func TestIssue4875(t *testing.T) {
|
|||||||
testFs := fs.NewFilesystem(fs.FilesystemTypeBasic, tmpDir)
|
testFs := fs.NewFilesystem(fs.FilesystemTypeBasic, tmpDir)
|
||||||
testFs.MkdirAll(filepath.Join("a", "b", "c"), 0755)
|
testFs.MkdirAll(filepath.Join("a", "b", "c"), 0755)
|
||||||
if err := fs.DebugSymlinkForTestsOnly(testFs, testFs, filepath.Join("a", "b"), filepath.Join("a", "l")); err != nil {
|
if err := fs.DebugSymlinkForTestsOnly(testFs, testFs, filepath.Join("a", "b"), filepath.Join("a", "l")); err != nil {
|
||||||
if runtime.GOOS == "windows" {
|
if build.IsWindows {
|
||||||
t.Skip("Symlinks aren't working")
|
t.Skip("Symlinks aren't working")
|
||||||
}
|
}
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
|
@ -8,9 +8,9 @@ import (
|
|||||||
"encoding/json"
|
"encoding/json"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"runtime"
|
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/syncthing/syncthing/lib/build"
|
||||||
"github.com/syncthing/syncthing/lib/rand"
|
"github.com/syncthing/syncthing/lib/rand"
|
||||||
"github.com/syncthing/syncthing/lib/sha256"
|
"github.com/syncthing/syncthing/lib/sha256"
|
||||||
)
|
)
|
||||||
@ -286,15 +286,13 @@ func ModTimeEqual(a, b time.Time, modTimeWindow time.Duration) bool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func PermsEqual(a, b uint32) bool {
|
func PermsEqual(a, b uint32) bool {
|
||||||
switch runtime.GOOS {
|
if build.IsWindows {
|
||||||
case "windows":
|
|
||||||
// There is only writeable and read only, represented for user, group
|
// There is only writeable and read only, represented for user, group
|
||||||
// and other equally. We only compare against user.
|
// and other equally. We only compare against user.
|
||||||
return a&0600 == b&0600
|
return a&0600 == b&0600
|
||||||
default:
|
|
||||||
// All bits count
|
|
||||||
return a&0777 == b&0777
|
|
||||||
}
|
}
|
||||||
|
// All bits count
|
||||||
|
return a&0777 == b&0777
|
||||||
}
|
}
|
||||||
|
|
||||||
// BlocksEqual returns true when the two files have identical block lists.
|
// BlocksEqual returns true when the two files have identical block lists.
|
||||||
|
@ -11,13 +11,13 @@ import (
|
|||||||
"errors"
|
"errors"
|
||||||
"io"
|
"io"
|
||||||
"os"
|
"os"
|
||||||
"runtime"
|
|
||||||
"sync"
|
"sync"
|
||||||
"testing"
|
"testing"
|
||||||
"testing/quick"
|
"testing/quick"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
lz4 "github.com/pierrec/lz4/v4"
|
lz4 "github.com/pierrec/lz4/v4"
|
||||||
|
"github.com/syncthing/syncthing/lib/build"
|
||||||
"github.com/syncthing/syncthing/lib/rand"
|
"github.com/syncthing/syncthing/lib/rand"
|
||||||
"github.com/syncthing/syncthing/lib/testutils"
|
"github.com/syncthing/syncthing/lib/testutils"
|
||||||
)
|
)
|
||||||
@ -848,7 +848,7 @@ func TestIsEquivalent(t *testing.T) {
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
if runtime.GOOS == "windows" {
|
if build.IsWindows {
|
||||||
// On windows we only check the user writable bit of the permission
|
// On windows we only check the user writable bit of the permission
|
||||||
// set, so these are equivalent.
|
// set, so these are equivalent.
|
||||||
cases = append(cases, testCase{
|
cases = append(cases, testCase{
|
||||||
|
@ -11,13 +11,13 @@ import (
|
|||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"runtime"
|
|
||||||
"strings"
|
"strings"
|
||||||
"sync/atomic"
|
"sync/atomic"
|
||||||
"time"
|
"time"
|
||||||
"unicode/utf8"
|
"unicode/utf8"
|
||||||
|
|
||||||
metrics "github.com/rcrowley/go-metrics"
|
metrics "github.com/rcrowley/go-metrics"
|
||||||
|
"github.com/syncthing/syncthing/lib/build"
|
||||||
"github.com/syncthing/syncthing/lib/events"
|
"github.com/syncthing/syncthing/lib/events"
|
||||||
"github.com/syncthing/syncthing/lib/fs"
|
"github.com/syncthing/syncthing/lib/fs"
|
||||||
"github.com/syncthing/syncthing/lib/ignore"
|
"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 {
|
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
|
// Symlinks are not supported on Windows. We ignore instead of returning
|
||||||
// an error.
|
// an error.
|
||||||
if runtime.GOOS == "windows" {
|
if build.IsWindows {
|
||||||
return nil
|
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
|
// normalizePath returns the normalized relative path (possibly after fixing
|
||||||
// it on disk), or skip is true.
|
// it on disk), or skip is true.
|
||||||
func (w *walker) normalizePath(path string, info fs.FileInfo) (normPath string, err error) {
|
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.
|
// Mac OS X file names should always be NFD normalized.
|
||||||
normPath = norm.NFD.String(path)
|
normPath = norm.NFD.String(path)
|
||||||
} else {
|
} 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
|
// do not depend on type, and things that should be preserved from the
|
||||||
// previous version of the FileInfo.
|
// previous version of the FileInfo.
|
||||||
func (w *walker) updateFileInfo(dst, src protocol.FileInfo) protocol.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
|
// If we have an existing index entry, copy the executable bits
|
||||||
// from there.
|
// from there.
|
||||||
dst.Permissions |= (src.Permissions & 0111)
|
dst.Permissions |= (src.Permissions & 0111)
|
||||||
|
@ -15,13 +15,13 @@ import (
|
|||||||
"io"
|
"io"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"runtime"
|
|
||||||
rdebug "runtime/debug"
|
rdebug "runtime/debug"
|
||||||
"sort"
|
"sort"
|
||||||
"sync"
|
"sync"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/d4l3k/messagediff"
|
"github.com/d4l3k/messagediff"
|
||||||
|
"github.com/syncthing/syncthing/lib/build"
|
||||||
"github.com/syncthing/syncthing/lib/events"
|
"github.com/syncthing/syncthing/lib/events"
|
||||||
"github.com/syncthing/syncthing/lib/fs"
|
"github.com/syncthing/syncthing/lib/fs"
|
||||||
"github.com/syncthing/syncthing/lib/ignore"
|
"github.com/syncthing/syncthing/lib/ignore"
|
||||||
@ -178,7 +178,7 @@ func TestVerify(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestNormalization(t *testing.T) {
|
func TestNormalization(t *testing.T) {
|
||||||
if runtime.GOOS == "darwin" {
|
if build.IsDarwin {
|
||||||
t.Skip("Normalization test not possible on darwin")
|
t.Skip("Normalization test not possible on darwin")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -197,7 +197,7 @@ func TestNormalization(t *testing.T) {
|
|||||||
}
|
}
|
||||||
numInvalid := 2
|
numInvalid := 2
|
||||||
|
|
||||||
if runtime.GOOS == "windows" {
|
if build.IsWindows {
|
||||||
// On Windows, in case 5 the character gets replaced with a
|
// On Windows, in case 5 the character gets replaced with a
|
||||||
// replacement character \xEF\xBF\xBD at the point it's written to disk,
|
// replacement character \xEF\xBF\xBD at the point it's written to disk,
|
||||||
// which means it suddenly becomes valid (sort of).
|
// which means it suddenly becomes valid (sort of).
|
||||||
@ -257,7 +257,7 @@ func TestNormalization(t *testing.T) {
|
|||||||
func TestNormalizationDarwinCaseFS(t *testing.T) {
|
func TestNormalizationDarwinCaseFS(t *testing.T) {
|
||||||
// This tests that normalization works on Darwin, through a CaseFS.
|
// This tests that normalization works on Darwin, through a CaseFS.
|
||||||
|
|
||||||
if runtime.GOOS != "darwin" {
|
if !build.IsDarwin {
|
||||||
t.Skip("Normalization test not possible on non-Darwin")
|
t.Skip("Normalization test not possible on non-Darwin")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -321,7 +321,7 @@ func TestIssue1507(_ *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestWalkSymlinkUnix(t *testing.T) {
|
func TestWalkSymlinkUnix(t *testing.T) {
|
||||||
if runtime.GOOS == "windows" {
|
if build.IsWindows {
|
||||||
t.Skip("skipping unsupported symlink test")
|
t.Skip("skipping unsupported symlink test")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -351,7 +351,7 @@ func TestWalkSymlinkUnix(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestWalkSymlinkWindows(t *testing.T) {
|
func TestWalkSymlinkWindows(t *testing.T) {
|
||||||
if runtime.GOOS != "windows" {
|
if !build.IsWindows {
|
||||||
t.Skip("skipping unsupported symlink test")
|
t.Skip("skipping unsupported symlink test")
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -386,7 +386,7 @@ func TestWalkRootSymlink(t *testing.T) {
|
|||||||
dest, _ := filepath.Abs("testdata/dir1")
|
dest, _ := filepath.Abs("testdata/dir1")
|
||||||
destFs := fs.NewFilesystem(testFsType, dest)
|
destFs := fs.NewFilesystem(testFsType, dest)
|
||||||
if err := fs.DebugSymlinkForTestsOnly(destFs, testFs, ".", "link"); err != nil {
|
if err := fs.DebugSymlinkForTestsOnly(destFs, testFs, ".", "link"); err != nil {
|
||||||
if runtime.GOOS == "windows" {
|
if build.IsWindows {
|
||||||
// Probably we require permissions we don't have.
|
// Probably we require permissions we don't have.
|
||||||
t.Skip("Need admin permissions or developer mode to run symlink test on Windows: " + err.Error())
|
t.Skip("Need admin permissions or developer mode to run symlink test on Windows: " + err.Error())
|
||||||
} else {
|
} else {
|
||||||
@ -406,7 +406,7 @@ func TestWalkRootSymlink(t *testing.T) {
|
|||||||
files = walkDir(testFs, "link", nil, nil, 0)
|
files = walkDir(testFs, "link", nil, nil, 0)
|
||||||
|
|
||||||
// Verify that we got the one symlink, except on windows
|
// Verify that we got the one symlink, except on windows
|
||||||
if runtime.GOOS == "windows" {
|
if build.IsWindows {
|
||||||
if len(files) != 0 {
|
if len(files) != 0 {
|
||||||
t.Errorf("expected no files, not %d", len(files))
|
t.Errorf("expected no files, not %d", len(files))
|
||||||
}
|
}
|
||||||
@ -588,7 +588,7 @@ func TestScanOwnershipPOSIX(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestScanOwnershipWindows(t *testing.T) {
|
func TestScanOwnershipWindows(t *testing.T) {
|
||||||
if runtime.GOOS != "windows" {
|
if !build.IsWindows {
|
||||||
t.Skip("This test only works on Windows")
|
t.Skip("This test only works on Windows")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -15,6 +15,8 @@ import (
|
|||||||
"runtime"
|
"runtime"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
"github.com/syncthing/syncthing/lib/build"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Release struct {
|
type Release struct {
|
||||||
@ -236,15 +238,13 @@ func releaseNames(tag string) []string {
|
|||||||
// standard, containing both the architecture/OS and the tag name we
|
// standard, containing both the architecture/OS and the tag name we
|
||||||
// expect. This protects against malformed release data potentially
|
// expect. This protects against malformed release data potentially
|
||||||
// tricking us into doing a downgrade.
|
// tricking us into doing a downgrade.
|
||||||
switch runtime.GOOS {
|
if build.IsDarwin {
|
||||||
case "darwin":
|
|
||||||
return []string{
|
return []string{
|
||||||
fmt.Sprintf("syncthing-macos-%s-%s.", runtime.GOARCH, tag),
|
fmt.Sprintf("syncthing-macos-%s-%s.", runtime.GOARCH, tag),
|
||||||
fmt.Sprintf("syncthing-macosx-%s-%s.", runtime.GOARCH, tag),
|
fmt.Sprintf("syncthing-macosx-%s-%s.", runtime.GOARCH, tag),
|
||||||
}
|
}
|
||||||
default:
|
}
|
||||||
return []string{
|
return []string{
|
||||||
fmt.Sprintf("syncthing-%s-%s-%s.", runtime.GOOS, runtime.GOARCH, tag),
|
fmt.Sprintf("syncthing-%s-%s-%s.", runtime.GOOS, runtime.GOARCH, tag),
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -14,6 +14,8 @@ import (
|
|||||||
"runtime"
|
"runtime"
|
||||||
"strings"
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
"github.com/syncthing/syncthing/lib/build"
|
||||||
)
|
)
|
||||||
|
|
||||||
var versions = []struct {
|
var versions = []struct {
|
||||||
@ -120,7 +122,7 @@ func TestSelectedRelease(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestSelectedReleaseMacOS(t *testing.T) {
|
func TestSelectedReleaseMacOS(t *testing.T) {
|
||||||
if runtime.GOOS != "darwin" {
|
if !build.IsDarwin {
|
||||||
t.Skip("macOS only")
|
t.Skip("macOS only")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -42,13 +42,13 @@ import (
|
|||||||
"net"
|
"net"
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/url"
|
"net/url"
|
||||||
"runtime"
|
|
||||||
"strings"
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
|
|
||||||
|
"github.com/syncthing/syncthing/lib/build"
|
||||||
"github.com/syncthing/syncthing/lib/dialer"
|
"github.com/syncthing/syncthing/lib/dialer"
|
||||||
"github.com/syncthing/syncthing/lib/nat"
|
"github.com/syncthing/syncthing/lib/nat"
|
||||||
)
|
)
|
||||||
@ -100,7 +100,7 @@ func Discover(ctx context.Context, _, timeout time.Duration) []nat.Device {
|
|||||||
|
|
||||||
for _, intf := range interfaces {
|
for _, intf := range interfaces {
|
||||||
// Interface flags seem to always be 0 on Windows
|
// Interface flags seem to always be 0 on Windows
|
||||||
if runtime.GOOS != "windows" && (intf.Flags&net.FlagUp == 0 || intf.Flags&net.FlagMulticast == 0) {
|
if !build.IsWindows && (intf.Flags&net.FlagUp == 0 || intf.Flags&net.FlagMulticast == 0) {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -12,10 +12,10 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"runtime"
|
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/syncthing/syncthing/lib/build"
|
||||||
"github.com/syncthing/syncthing/lib/config"
|
"github.com/syncthing/syncthing/lib/config"
|
||||||
"github.com/syncthing/syncthing/lib/fs"
|
"github.com/syncthing/syncthing/lib/fs"
|
||||||
|
|
||||||
@ -35,7 +35,7 @@ type external struct {
|
|||||||
func newExternal(cfg config.FolderConfiguration) Versioner {
|
func newExternal(cfg config.FolderConfiguration) Versioner {
|
||||||
command := cfg.Versioning.Params["command"]
|
command := cfg.Versioning.Params["command"]
|
||||||
|
|
||||||
if runtime.GOOS == "windows" {
|
if build.IsWindows {
|
||||||
command = strings.ReplaceAll(command, `\`, `\\`)
|
command = strings.ReplaceAll(command, `\`, `\\`)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -9,9 +9,9 @@ package versioner
|
|||||||
import (
|
import (
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"runtime"
|
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
"github.com/syncthing/syncthing/lib/build"
|
||||||
"github.com/syncthing/syncthing/lib/fs"
|
"github.com/syncthing/syncthing/lib/fs"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -45,7 +45,7 @@ func TestExternalNoCommand(t *testing.T) {
|
|||||||
|
|
||||||
func TestExternal(t *testing.T) {
|
func TestExternal(t *testing.T) {
|
||||||
cmd := "./_external_test/external.sh %FOLDER_PATH% %FILE_PATH%"
|
cmd := "./_external_test/external.sh %FOLDER_PATH% %FILE_PATH%"
|
||||||
if runtime.GOOS == "windows" {
|
if build.IsWindows {
|
||||||
cmd = `.\\_external_test\\external.bat %FOLDER_PATH% %FILE_PATH%`
|
cmd = `.\\_external_test\\external.bat %FOLDER_PATH% %FILE_PATH%`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -10,11 +10,11 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"runtime"
|
|
||||||
"strconv"
|
"strconv"
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/syncthing/syncthing/lib/build"
|
||||||
"github.com/syncthing/syncthing/lib/config"
|
"github.com/syncthing/syncthing/lib/config"
|
||||||
"github.com/syncthing/syncthing/lib/events"
|
"github.com/syncthing/syncthing/lib/events"
|
||||||
"github.com/syncthing/syncthing/lib/fs"
|
"github.com/syncthing/syncthing/lib/fs"
|
||||||
@ -329,7 +329,7 @@ func testAggregatorOutput(t *testing.T, fsWatchChan <-chan []string, expectedBat
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
if runtime.GOOS != "darwin" {
|
if !build.IsDarwin {
|
||||||
now := time.Since(startTime)
|
now := time.Since(startTime)
|
||||||
if innerIndex == 0 {
|
if innerIndex == 0 {
|
||||||
switch {
|
switch {
|
||||||
|
@ -12,9 +12,10 @@ package integration
|
|||||||
import (
|
import (
|
||||||
"log"
|
"log"
|
||||||
"os"
|
"os"
|
||||||
"runtime"
|
|
||||||
"syscall"
|
"syscall"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/syncthing/syncthing/lib/build"
|
||||||
)
|
)
|
||||||
|
|
||||||
func printUsage(name string, proc *os.ProcessState, total int64) {
|
func printUsage(name string, proc *os.ProcessState, total int64) {
|
||||||
@ -22,7 +23,7 @@ func printUsage(name string, proc *os.ProcessState, total int64) {
|
|||||||
mib := total / 1024 / 1024
|
mib := total / 1024 / 1024
|
||||||
log.Printf("%s: Utime: %s / MiB", name, time.Duration(rusage.Utime.Nano()/mib))
|
log.Printf("%s: Utime: %s / MiB", name, time.Duration(rusage.Utime.Nano()/mib))
|
||||||
log.Printf("%s: Stime: %s / MiB", name, time.Duration(rusage.Stime.Nano()/mib))
|
log.Printf("%s: Stime: %s / MiB", name, time.Duration(rusage.Stime.Nano()/mib))
|
||||||
if runtime.GOOS == "darwin" {
|
if build.IsDarwin {
|
||||||
// Darwin reports in bytes, Linux seems to report in KiB even
|
// Darwin reports in bytes, Linux seems to report in KiB even
|
||||||
// though the manpage says otherwise.
|
// though the manpage says otherwise.
|
||||||
rusage.Maxrss /= 1024
|
rusage.Maxrss /= 1024
|
||||||
|
@ -25,6 +25,7 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
"unicode"
|
"unicode"
|
||||||
|
|
||||||
|
"github.com/syncthing/syncthing/lib/build"
|
||||||
"github.com/syncthing/syncthing/lib/rc"
|
"github.com/syncthing/syncthing/lib/rc"
|
||||||
"github.com/syncthing/syncthing/lib/sha256"
|
"github.com/syncthing/syncthing/lib/sha256"
|
||||||
)
|
)
|
||||||
@ -174,7 +175,7 @@ func alterFiles(dir string) error {
|
|||||||
|
|
||||||
// Change capitalization
|
// Change capitalization
|
||||||
case r == 2 && comps > 3 && rand.Float64() < 0.2:
|
case r == 2 && comps > 3 && rand.Float64() < 0.2:
|
||||||
if runtime.GOOS == "darwin" || runtime.GOOS == "windows" {
|
if build.IsDarwin || build.IsWindows {
|
||||||
// Syncthing is currently broken for case-only renames on case-
|
// Syncthing is currently broken for case-only renames on case-
|
||||||
// insensitive platforms.
|
// insensitive platforms.
|
||||||
// https://github.com/syncthing/syncthing/issues/1787
|
// https://github.com/syncthing/syncthing/issues/1787
|
||||||
|
Loading…
Reference in New Issue
Block a user