Skip to content

Commit

Permalink
Merge branch 'master' into logsuppression
Browse files Browse the repository at this point in the history
* master:
  golang-ci: Skip "cognitive complexity" check for now
  lib/model: Prevent cleanup-race in testing (ref syncthing#6152) (syncthing#6155)
  gui: Decrease padding on the panel and modal bodies (syncthing#6153)
  lib/model: In tests prevent goroutine leaks and increase timeouts (syncthing#6152)
  lib/model: Simplify pull error/retry logic (fixes syncthing#6139) (syncthing#6141)
  docker: Add stdiscosrv and strelaysrv Dockerfiles (syncthing#6143)
  lib/protocol: Buffer allocation when compressing (fixes syncthing#6146) (syncthing#6147)
  golang-ci: Upgrade, skipping the white space complainer
  all: Cleanups enabled by Go 1.12
  lib/tlsutil: Remove Go 1.12 TLS 1.3 beta opt-in
  lib/api: Make theme paths relative (syncthing#6142)
  gui, lib/api: Adds support for prefers-color-scheme (fixes syncthing#6115)
  lib/api: Reset mtime after theme change (fixes syncthing#5810) (syncthing#6140)
  lib/model: Remove some testing deadlocks (syncthing#6138)
  lib/model: Add test for previous commit
  lib/model: Add initial deviceStatRefs on model creation (fixes syncthing#6136) (syncthing#6137)
  lib/model: Add folders on start in model (syncthing#6135)
  • Loading branch information
calmh committed Nov 17, 2019
2 parents 2f9b0cb + e7100bc commit f206d40
Show file tree
Hide file tree
Showing 26 changed files with 440 additions and 246 deletions.
4 changes: 3 additions & 1 deletion .golangci.yml
Expand Up @@ -14,9 +14,11 @@ linters:
- scopelint
- gocyclo
- funlen
- wsl
- gocognit

service:
golangci-lint-version: 1.19.x
golangci-lint-version: 1.21.x
prepare:
- rm -f go.sum # 1.12 -> 1.13 issues with QUIC-go
- GO111MODULE=on go mod vendor
Expand Down
4 changes: 2 additions & 2 deletions Dockerfile
Expand Up @@ -19,10 +19,10 @@ RUN apk add --no-cache ca-certificates su-exec
COPY --from=builder /src/syncthing /bin/syncthing
COPY --from=builder /src/script/docker-entrypoint.sh /bin/entrypoint.sh

ENV PUID=1000 PGID=1000
ENV PUID=1000 PGID=1000 HOME=/var/syncthing

HEALTHCHECK --interval=1m --timeout=10s \
CMD nc -z localhost 8384 || exit 1

ENV STGUIADDRESS=0.0.0.0:8384
ENTRYPOINT ["/bin/entrypoint.sh", "-home", "/var/syncthing/config"]
ENTRYPOINT ["/bin/entrypoint.sh", "/bin/syncthing", "-home", "/var/syncthing/config"]
28 changes: 28 additions & 0 deletions Dockerfile.stdiscosrv
@@ -0,0 +1,28 @@
FROM golang:1.13 AS builder

WORKDIR /src
COPY . .

ENV CGO_ENABLED=0
ENV BUILD_HOST=syncthing.net
ENV BUILD_USER=docker
RUN rm -f stdiscosrv && go run build.go -no-upgrade build stdiscosrv

FROM alpine

EXPOSE 19200 8443

VOLUME ["/var/stdiscosrv"]

RUN apk add --no-cache ca-certificates su-exec

COPY --from=builder /src/stdiscosrv /bin/stdiscosrv
COPY --from=builder /src/script/docker-entrypoint.sh /bin/entrypoint.sh

ENV PUID=1000 PGID=1000 HOME=/var/stdiscosrv

HEALTHCHECK --interval=1m --timeout=10s \
CMD nc -z localhost 8443 || exit 1

WORKDIR /var/stdiscosrv
ENTRYPOINT ["/bin/entrypoint.sh", "/bin/stdiscosrv"]
28 changes: 28 additions & 0 deletions Dockerfile.strelaysrv
@@ -0,0 +1,28 @@
FROM golang:1.13 AS builder

WORKDIR /src
COPY . .

ENV CGO_ENABLED=0
ENV BUILD_HOST=syncthing.net
ENV BUILD_USER=docker
RUN rm -f strelaysrv && go run build.go -no-upgrade build strelaysrv

FROM alpine

EXPOSE 22067 22070

VOLUME ["/var/strelaysrv"]

RUN apk add --no-cache ca-certificates su-exec

COPY --from=builder /src/strelaysrv /bin/strelaysrv
COPY --from=builder /src/script/docker-entrypoint.sh /bin/entrypoint.sh

ENV PUID=1000 PGID=1000 HOME=/var/strelaysrv

HEALTHCHECK --interval=1m --timeout=10s \
CMD nc -z localhost 22067 || exit 1

WORKDIR /var/strelaysrv
ENTRYPOINT ["/bin/entrypoint.sh", "/bin/strelaysrv"]
17 changes: 7 additions & 10 deletions cmd/syncthing/monitor.go
Expand Up @@ -151,17 +151,14 @@ func monitorMain(runtimeOptions RuntimeOptions) {
// Successful exit indicates an intentional shutdown
return
} else if exiterr, ok := err.(*exec.ExitError); ok {
if status, ok := exiterr.Sys().(syscall.WaitStatus); ok {
switch status.ExitStatus() {
case syncthing.ExitUpgrade.AsInt():
// Restart the monitor process to release the .old
// binary as part of the upgrade process.
l.Infoln("Restarting monitor...")
if err = restartMonitor(args); err != nil {
l.Warnln("Restart:", err)
}
return
if exiterr.ExitCode() == syncthing.ExitUpgrade.AsInt() {
// Restart the monitor process to release the .old
// binary as part of the upgrade process.
l.Infoln("Restarting monitor...")
if err = restartMonitor(args); err != nil {
l.Warnln("Restart:", err)
}
return
}
}
}
Expand Down
14 changes: 13 additions & 1 deletion gui/default/assets/css/overrides.css
Expand Up @@ -246,6 +246,18 @@ a.toggler:hover {
text-decoration: none;
}

/**
* Panel and Modal body padding decrease
*/

.panel-collapse .panel-body {
padding: 0;
}

.modal-body {
padding: 5px;
}

/**
* Progress bars with centered text
*/
Expand Down Expand Up @@ -400,4 +412,4 @@ ul.three-columns li, ul.two-columns li {
.btn:not(.panel-heading) + .btn:not(.panel-heading) {
margin-bottom: 1rem;
}
}
}
28 changes: 2 additions & 26 deletions gui/default/assets/css/theme.css
Expand Up @@ -7,29 +7,5 @@
*/

.panel-progress {
background: #3498db;
}

.identicon rect {
fill: #333;
}

.panel-warning .identicon rect {
fill: #fff;
}

.li-column {
background-color: rgb(236, 240, 241);
border-radius: 3px;
}

.panel-heading:hover, .panel-heading:focus {
text-decoration: none;
}

.fancytree-ext-filter-hide tr.fancytree-submatch span.fancytree-title,
.fancytree-ext-filter-hide span.fancytree-node.fancytree-submatch span.fancytree-title {
color: black !important;
font-weight: lighter !important;
}
@import "../../theme-assets/dark/assets/css/theme.css" screen and (prefers-color-scheme: dark);
@import "../../theme-assets/light/assets/css/theme.css" (prefers-color-scheme: light), (prefers-color-scheme: no-preference);
18 changes: 18 additions & 0 deletions gui/default/syncthing/core/syncthingController.js
Expand Up @@ -389,6 +389,7 @@ angular.module('syncthing.core')
});

refreshNoAuthWarning();
setDefaultTheme();

if (!hasConfig) {
$scope.$emit('ConfigLoaded');
Expand Down Expand Up @@ -651,6 +652,23 @@ angular.module('syncthing.core')
$scope.remoteNeedDevice = undefined;
}


function setDefaultTheme() {
if (!document.getElementById("fallback-theme-css")){

// check if no support for prefers-color-scheme
var colorSchemeNotSupported = typeof window.matchMedia === "undefined" || window.matchMedia('(prefers-color-scheme: dark)').media === 'not all';

if ($scope.config.gui.theme === "default" && colorSchemeNotSupported) {
document.documentElement.style.display = 'none';
document.head.insertAdjacentHTML(
'beforeend',
'<link id="fallback-theme-css" rel="stylesheet" href="theme-assets/light/assets/css/theme.css" onload="document.documentElement.style.display = \'\'">'
);
}
}
}

function saveIgnores(ignores, cb) {
$http.post(urlbase + '/db/ignores?folder=' + encodeURIComponent($scope.currentFolder.id), {
ignore: ignores
Expand Down
35 changes: 35 additions & 0 deletions gui/light/assets/css/theme.css
@@ -0,0 +1,35 @@
/*
// Copyright (C) 2016 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/.
*/

.panel-progress {
background: #3498db;
}

.identicon rect {
fill: #333;
}

.panel-warning .identicon rect {
fill: #fff;
}

.li-column {
background-color: rgb(236, 240, 241);
border-radius: 3px;
}

.panel-heading:hover, .panel-heading:focus {
text-decoration: none;
}

.fancytree-ext-filter-hide tr.fancytree-submatch span.fancytree-title,
.fancytree-ext-filter-hide span.fancytree-node.fancytree-submatch span.fancytree-title {
color: black !important;
font-weight: lighter !important;
}
40 changes: 29 additions & 11 deletions lib/api/api_statics.go
Expand Up @@ -23,21 +23,25 @@ import (
"github.com/syncthing/syncthing/lib/sync"
)

const themePrefix = "theme-assets/"

type staticsServer struct {
assetDir string
assets map[string][]byte
availableThemes []string

mut sync.RWMutex
theme string
mut sync.RWMutex
theme string
lastThemeChange time.Time
}

func newStaticsServer(theme, assetDir string) *staticsServer {
s := &staticsServer{
assetDir: assetDir,
assets: auto.Assets(),
mut: sync.NewRWMutex(),
theme: theme,
assetDir: assetDir,
assets: auto.Assets(),
mut: sync.NewRWMutex(),
theme: theme,
lastThemeChange: time.Now().UTC(),
}

seen := make(map[string]struct{})
Expand Down Expand Up @@ -86,8 +90,23 @@ func (s *staticsServer) serveAsset(w http.ResponseWriter, r *http.Request) {

s.mut.RLock()
theme := s.theme
modificationTime := s.lastThemeChange
s.mut.RUnlock()

// If path starts with special prefix, get theme and file from path
if strings.HasPrefix(file, themePrefix) {
path := file[len(themePrefix):]
i := strings.IndexRune(path, '/')

if i == -1 {
http.NotFound(w, r)
return
}

theme = path[:i]
file = path[i+1:]
}

// Check for an override for the current theme.
if s.assetDir != "" {
p := filepath.Join(s.assetDir, theme, filepath.FromSlash(file))
Expand Down Expand Up @@ -125,14 +144,12 @@ func (s *staticsServer) serveAsset(w http.ResponseWriter, r *http.Request) {
}
}

etag := fmt.Sprintf("%d", auto.Generated)
modified := time.Unix(auto.Generated, 0).UTC()

w.Header().Set("Last-Modified", modified.Format(http.TimeFormat))
etag := fmt.Sprintf("%d", modificationTime.Unix())
w.Header().Set("Last-Modified", modificationTime.Format(http.TimeFormat))
w.Header().Set("Etag", etag)

if t, err := time.Parse(http.TimeFormat, r.Header.Get("If-Modified-Since")); err == nil {
if modified.Equal(t) || modified.Before(t) {
if modificationTime.Equal(t) || modificationTime.Before(t) {
w.WriteHeader(http.StatusNotModified)
return
}
Expand Down Expand Up @@ -199,6 +216,7 @@ func (s *staticsServer) mimeTypeForFile(file string) string {
func (s *staticsServer) setTheme(theme string) {
s.mut.Lock()
s.theme = theme
s.lastThemeChange = time.Now().UTC()
s.mut.Unlock()
}

Expand Down
7 changes: 0 additions & 7 deletions lib/api/mocked_model_test.go
Expand Up @@ -10,7 +10,6 @@ import (
"net"
"time"

"github.com/syncthing/syncthing/lib/config"
"github.com/syncthing/syncthing/lib/connections"
"github.com/syncthing/syncthing/lib/db"
"github.com/syncthing/syncthing/lib/model"
Expand Down Expand Up @@ -180,10 +179,4 @@ func (m *mockedModel) GetHello(protocol.DeviceID) protocol.HelloIntf {
return nil
}

func (m *mockedModel) AddFolder(cfg config.FolderConfiguration) {}

func (m *mockedModel) RestartFolder(from, to config.FolderConfiguration) {}

func (m *mockedModel) StartFolder(folder string) {}

func (m *mockedModel) StartDeadlockDetector(timeout time.Duration) {}
2 changes: 1 addition & 1 deletion lib/connections/service.go
Expand Up @@ -83,7 +83,7 @@ var tlsCipherSuiteNames = map[uint16]string{

var tlsVersionNames = map[uint16]string{
tls.VersionTLS12: "TLS1.2",
772: "TLS1.3", // tls.VersionTLS13 constant available in Go 1.12+
tls.VersionTLS13: "TLS1.3",
}

// Service listens and dials all configured unconnected devices, via supported
Expand Down
21 changes: 7 additions & 14 deletions lib/fs/util.go
Expand Up @@ -35,23 +35,16 @@ func ExpandTilde(path string) (string, error) {
}

func getHomeDir() (string, error) {
var home string

switch runtime.GOOS {
case "windows":
home = filepath.Join(os.Getenv("HomeDrive"), os.Getenv("HomePath"))
if home == "" {
home = os.Getenv("UserProfile")
if runtime.GOOS == "windows" {
// Legacy -- we prioritize this for historical reasons, whereas
// os.UserHomeDir uses %USERPROFILE% always.
home := filepath.Join(os.Getenv("HomeDrive"), os.Getenv("HomePath"))
if home != "" {
return home, nil
}
default:
home = os.Getenv("HOME")
}

if home == "" {
return "", errNoHome
}

return home, nil
return os.UserHomeDir()
}

var windowsDisallowedCharacters = string([]rune{
Expand Down

0 comments on commit f206d40

Please sign in to comment.