Skip to content

Commit

Permalink
Merge branch 'main' into integrationtests
Browse files Browse the repository at this point in the history
* main:
  lib/model: Use a single lock (phase two: cleanup) (syncthing#9276)
  build(deps): bump actions/setup-go from 4 to 5 (syncthing#9279)
  lib/model: Use a single lock (syncthing#9275)
  cmd/syncthing: Better cli stdin handling (ref syncthing#9166) (syncthing#9281)
  cmd/syncthing: Mostly replace urfave/cli command line parser with alecthomas/kong (syncthing#9166)
  lib/nat: Fix test build failure (ref syncthing#9010)
  lib/model: Add pmut locking for DeviceStatistics (fixes syncthing#9274)
  lib/model: Add pmut locking for DeviceStatistics (fixes syncthing#9274)
  lib/model: Remove spurious "replacing service" failure event (ref syncthing#9271)
  lib/model: Remove spurious "replacing service" failure event (ref syncthing#9271)
  lib/nat, lib/upnp: IPv6 UPnP support (syncthing#9010)
  gui, man, authors: Update docs, translations, and contributors
  gui: Show folder/device status on small screens (syncthing#8643)
  lib/model: Remove runner during folder cleanup (fixes syncthing#9269) (syncthing#9271)
  • Loading branch information
calmh committed Dec 11, 2023
2 parents b9a302a + 935a28c commit f701994
Show file tree
Hide file tree
Showing 67 changed files with 1,273 additions and 1,066 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build-infra-dockers.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ jobs:
with:
fetch-depth: 0

- uses: actions/setup-go@v4
- uses: actions/setup-go@v5
with:
go-version: ${{ env.GO_VERSION }}
check-latest: true
Expand Down
20 changes: 10 additions & 10 deletions .github/workflows/build-syncthing.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ jobs:
with:
fetch-depth: 0

- uses: actions/setup-go@v4
- uses: actions/setup-go@v5
with:
go-version: ${{ matrix.go }}
cache: true
Expand Down Expand Up @@ -111,7 +111,7 @@ jobs:
steps:
- uses: actions/checkout@v4

- uses: actions/setup-go@v4
- uses: actions/setup-go@v5
with:
go-version: ${{ env.GO_VERSION }}
cache: false
Expand Down Expand Up @@ -167,7 +167,7 @@ jobs:
with:
fetch-depth: 0

- uses: actions/setup-go@v4
- uses: actions/setup-go@v5
with:
go-version: ${{ env.GO_VERSION }}
cache: false
Expand Down Expand Up @@ -220,7 +220,7 @@ jobs:
with:
fetch-depth: 0

- uses: actions/setup-go@v4
- uses: actions/setup-go@v5
with:
go-version: ${{ env.GO_VERSION }}
cache: false
Expand Down Expand Up @@ -267,7 +267,7 @@ jobs:
with:
fetch-depth: 0

- uses: actions/setup-go@v4
- uses: actions/setup-go@v5
with:
go-version: ${{ env.GO_VERSION }}
cache: false
Expand Down Expand Up @@ -394,7 +394,7 @@ jobs:
with:
fetch-depth: 0

- uses: actions/setup-go@v4
- uses: actions/setup-go@v5
with:
go-version: ${{ env.GO_VERSION }}
cache: false
Expand Down Expand Up @@ -461,7 +461,7 @@ jobs:
with:
fetch-depth: 0

- uses: actions/setup-go@v4
- uses: actions/setup-go@v5
with:
go-version: ${{ env.GO_VERSION }}
cache: false
Expand Down Expand Up @@ -573,7 +573,7 @@ jobs:
with:
fetch-depth: 0

- uses: actions/setup-go@v4
- uses: actions/setup-go@v5
with:
go-version: ${{ env.GO_VERSION }}
cache: false
Expand Down Expand Up @@ -745,7 +745,7 @@ jobs:
with:
fetch-depth: 0

- uses: actions/setup-go@v4
- uses: actions/setup-go@v5
with:
go-version: ${{ env.GO_VERSION }}
cache: false
Expand Down Expand Up @@ -830,7 +830,7 @@ jobs:
steps:
- uses: actions/checkout@v4

- uses: actions/setup-go@v4
- uses: actions/setup-go@v5
with:
go-version: ${{ env.GO_VERSION }}
cache: false
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/update-docs-translations.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
with:
fetch-depth: 0
token: ${{ secrets.ACTIONS_GITHUB_TOKEN }}
- uses: actions/setup-go@v4
- uses: actions/setup-go@v5
with:
go-version: ^1.19.6
- run: |
Expand Down
10 changes: 9 additions & 1 deletion cmd/strelaysrv/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,15 @@ func main() {
cfg.Options.NATTimeoutS = natTimeout
})
natSvc := nat.NewService(id, wrapper)
mapping := mapping{natSvc.NewMapping(nat.TCP, addr.IP, addr.Port)}
var ipVersion nat.IPVersion
if strings.HasSuffix(proto, "4") {
ipVersion = nat.IPv4Only
} else if strings.HasSuffix(proto, "6") {
ipVersion = nat.IPv6Only
} else {
ipVersion = nat.IPvAny
}
mapping := mapping{natSvc.NewMapping(nat.TCP, ipVersion, addr.IP, addr.Port)}

if natEnabled {
ctx, cancel := context.WithCancel(context.Background())
Expand Down
32 changes: 21 additions & 11 deletions cmd/syncthing/cli/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"reflect"

"github.com/AudriusButkevicius/recli"
"github.com/alecthomas/kong"
"github.com/syncthing/syncthing/lib/config"
"github.com/urfave/cli"
)
Expand All @@ -23,9 +24,20 @@ type configHandler struct {
err error
}

func getConfigCommand(f *apiClientFactory) (cli.Command, error) {
type configCommand struct {
Args []string `arg:"" default:"-h"`
}

func (c *configCommand) Run(ctx Context, _ *kong.Context) error {
app := cli.NewApp()
app.Name = "syncthing"
app.Author = "The Syncthing Authors"
app.Metadata = map[string]interface{}{
"clientFactory": ctx.clientFactory,
}

h := new(configHandler)
h.client, h.err = f.getClient()
h.client, h.err = ctx.clientFactory.getClient()
if h.err == nil {
h.cfg, h.err = getConfig(h.client)
}
Expand All @@ -38,17 +50,15 @@ func getConfigCommand(f *apiClientFactory) (cli.Command, error) {

commands, err := recli.New(recliCfg).Construct(&h.cfg)
if err != nil {
return cli.Command{}, fmt.Errorf("config reflect: %w", err)
return fmt.Errorf("config reflect: %w", err)
}

return cli.Command{
Name: "config",
HideHelp: true,
Usage: "Configuration modification command group",
Subcommands: commands,
Before: h.configBefore,
After: h.configAfter,
}, nil
app.Commands = commands
app.HideHelp = true
app.Before = h.configBefore
app.After = h.configAfter

return app.Run(append([]string{app.Name}, c.Args...))
}

func (h *configHandler) configBefore(c *cli.Context) error {
Expand Down
62 changes: 26 additions & 36 deletions cmd/syncthing/cli/debug.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,47 +9,37 @@ package cli
import (
"fmt"
"net/url"

"github.com/urfave/cli"
)

var debugCommand = cli.Command{
Name: "debug",
HideHelp: true,
Usage: "Debug command group",
Subcommands: []cli.Command{
{
Name: "file",
Usage: "Show information about a file (or directory/symlink)",
ArgsUsage: "FOLDER-ID PATH",
Action: expects(2, debugFile()),
},
indexCommand,
{
Name: "profile",
Usage: "Save a profile to help figuring out what Syncthing does.",
ArgsUsage: "cpu | heap",
Action: expects(1, profile()),
},
},
type fileCommand struct {
FolderID string `arg:""`
Path string `arg:""`
}

func debugFile() cli.ActionFunc {
return func(c *cli.Context) error {
query := make(url.Values)
query.Set("folder", c.Args()[0])
query.Set("file", normalizePath(c.Args()[1]))
return indexDumpOutput("debug/file?" + query.Encode())(c)
}
func (f *fileCommand) Run(ctx Context) error {
indexDumpOutput := indexDumpOutputWrapper(ctx.clientFactory)

query := make(url.Values)
query.Set("folder", f.FolderID)
query.Set("file", normalizePath(f.Path))
return indexDumpOutput("debug/file?" + query.Encode())
}

func profile() cli.ActionFunc {
return func(c *cli.Context) error {
switch t := c.Args()[0]; t {
case "cpu", "heap":
return saveToFile(fmt.Sprintf("debug/%vprof", c.Args()[0]))(c)
default:
return fmt.Errorf("expected cpu or heap as argument, got %v", t)
}
type profileCommand struct {
Type string `arg:"" help:"cpu | heap"`
}

func (p *profileCommand) Run(ctx Context) error {
switch t := p.Type; t {
case "cpu", "heap":
return saveToFile(fmt.Sprintf("debug/%vprof", p.Type), ctx.clientFactory)
default:
return fmt.Errorf("expected cpu or heap as argument, got %v", t)
}
}

type debugCommand struct {
File fileCommand `cmd:"" help:"Show information about a file (or directory/symlink)"`
Profile profileCommand `cmd:"" help:"Save a profile to help figuring out what Syncthing does"`
Index indexCommand `cmd:"" help:"Show information about the index (database)"`
}
51 changes: 25 additions & 26 deletions cmd/syncthing/cli/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,36 +11,25 @@ import (
"fmt"
"strings"

"github.com/urfave/cli"
"github.com/alecthomas/kong"
)

var errorsCommand = cli.Command{
Name: "errors",
HideHelp: true,
Usage: "Error command group",
Subcommands: []cli.Command{
{
Name: "show",
Usage: "Show pending errors",
Action: expects(0, indexDumpOutput("system/error")),
},
{
Name: "push",
Usage: "Push an error to active clients",
ArgsUsage: "ERROR-MESSAGE",
Action: expects(1, errorsPush),
},
{
Name: "clear",
Usage: "Clear pending errors",
Action: expects(0, emptyPost("system/error/clear")),
},
},
type errorsCommand struct {
Show struct{} `cmd:"" help:"Show pending errors"`
Push errorsPushCommand `cmd:"" help:"Push an error to active clients"`
Clear struct{} `cmd:"" help:"Clear pending errors"`
}

func errorsPush(c *cli.Context) error {
client := c.App.Metadata["client"].(APIClient)
errStr := strings.Join(c.Args(), " ")
type errorsPushCommand struct {
ErrorMessage string `arg:""`
}

func (e *errorsPushCommand) Run(ctx Context) error {
client, err := ctx.clientFactory.getClient()
if err != nil {
return err
}
errStr := e.ErrorMessage
response, err := client.Post("system/error", strings.TrimSpace(errStr))
if err != nil {
return err
Expand All @@ -59,3 +48,13 @@ func errorsPush(c *cli.Context) error {
}
return nil
}

func (*errorsCommand) Run(ctx Context, kongCtx *kong.Context) error {
switch kongCtx.Selected().Name {
case "show":
return indexDumpOutput("system/error", ctx.clientFactory)
case "clear":
return emptyPost("system/error/clear", ctx.clientFactory)
}
return nil
}
46 changes: 20 additions & 26 deletions cmd/syncthing/cli/index.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,32 +7,26 @@
package cli

import (
"github.com/urfave/cli"
"github.com/alecthomas/kong"
)

var indexCommand = cli.Command{
Name: "index",
Usage: "Show information about the index (database)",
Subcommands: []cli.Command{
{
Name: "dump",
Usage: "Print the entire db",
Action: expects(0, indexDump),
},
{
Name: "dump-size",
Usage: "Print the db size of different categories of information",
Action: expects(0, indexDumpSize),
},
{
Name: "check",
Usage: "Check the database for inconsistencies",
Action: expects(0, indexCheck),
},
{
Name: "account",
Usage: "Print key and value size statistics per key type",
Action: expects(0, indexAccount),
},
},
type indexCommand struct {
Dump struct{} `cmd:"" help:"Print the entire db"`
DumpSize struct{} `cmd:"" help:"Print the db size of different categories of information"`
Check struct{} `cmd:"" help:"Check the database for inconsistencies"`
Account struct{} `cmd:"" help:"Print key and value size statistics per key type"`
}

func (*indexCommand) Run(kongCtx *kong.Context) error {
switch kongCtx.Selected().Name {
case "dump":
return indexDump()
case "dump-size":
return indexDumpSize()
case "check":
return indexCheck()
case "account":
return indexAccount()
}
return nil
}
4 changes: 1 addition & 3 deletions cmd/syncthing/cli/index_accounting.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,10 @@ import (
"fmt"
"os"
"text/tabwriter"

"github.com/urfave/cli"
)

// indexAccount prints key and data size statistics per class
func indexAccount(*cli.Context) error {
func indexAccount() error {
ldb, err := getDB()
if err != nil {
return err
Expand Down

0 comments on commit f701994

Please sign in to comment.