Skip to content

Commit

Permalink
Merge pull request #448 from mutagen-io/v017-backports
Browse files Browse the repository at this point in the history
all: backport changes for v0.17.1
  • Loading branch information
xenoscopic authored May 4, 2023
2 parents 2855c81 + 38b1cb2 commit 1228b15
Show file tree
Hide file tree
Showing 18 changed files with 164 additions and 47 deletions.
8 changes: 4 additions & 4 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ jobs:
- uses: actions/checkout@v2
- uses: actions/setup-go@v2
with:
go-version: '1.20.1'
go-version: '1.20.4'
- name: "Install sha256sum"
run: brew install coreutils
- run: scripts/ci/setup_go.sh
Expand Down Expand Up @@ -72,7 +72,7 @@ jobs:
timeout-minutes: 30
strategy:
matrix:
goversion: ['1.19.6', '1.20.1']
goversion: ['1.19.9', '1.20.4']
steps:
- uses: actions/checkout@v2
- uses: actions/setup-go@v2
Expand All @@ -93,7 +93,7 @@ jobs:
- uses: actions/checkout@v2
- uses: actions/setup-go@v2
with:
go-version: '1.20.1'
go-version: '1.20.4'
- run: scripts/ci/setup_go.sh
shell: bash
- run: scripts/ci/setup_docker.sh
Expand All @@ -116,7 +116,7 @@ jobs:
- uses: actions/checkout@v2
- uses: actions/setup-go@v2
with:
go-version: '1.20.1'
go-version: '1.20.4'
- uses: docker/setup-qemu-action@v1
- uses: docker/setup-buildx-action@v1
- uses: docker/login-action@v1
Expand Down
5 changes: 4 additions & 1 deletion cmd/mutagen/common/templating/templating.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import (
"encoding/json"
"strings"
"text/template"

"github.com/mutagen-io/mutagen/pkg/platform/terminal"
)

// jsonify is the built-in JSON encoder that's made available to templates.
Expand Down Expand Up @@ -33,6 +35,7 @@ func jsonify(value any) (string, error) {

// builtins are the builtin functions supported in output templates.
var builtins = template.FuncMap{
"json": jsonify,
"json": jsonify,
"shellSanitize": terminal.NeutralizeControlCharacters,
// TODO: Figure out what other functions we want to include here, if any.
}
6 changes: 5 additions & 1 deletion cmd/mutagen/daemon/run.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package daemon

import (
"errors"
"fmt"
"io/fs"
"os"
"os/signal"

Expand Down Expand Up @@ -115,7 +117,9 @@ func runMain(_ *cobra.Command, _ []string) error {
// Create the daemon listener and defer its closure. Since we hold the
// daemon lock, we preemptively remove any existing socket since it should
// be stale.
os.Remove(endpoint)
if err := os.Remove(endpoint); err != nil && !errors.Is(err, fs.ErrNotExist) {
return fmt.Errorf("unable to remove existing daemon endpoint: %w", err)
}
listener, err := ipc.NewListener(endpoint)
if err != nil {
return fmt.Errorf("unable to create daemon listener: %w", err)
Expand Down
5 changes: 3 additions & 2 deletions cmd/mutagen/forward/list_monitor_common.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"github.com/mutagen-io/mutagen/cmd/mutagen/common"

"github.com/mutagen-io/mutagen/pkg/forwarding"
"github.com/mutagen-io/mutagen/pkg/platform/terminal"
"github.com/mutagen-io/mutagen/pkg/selection"
"github.com/mutagen-io/mutagen/pkg/url"
)
Expand All @@ -27,7 +28,7 @@ func printEndpoint(name string, url *url.URL, configuration *forwarding.Configur
fmt.Printf("%s:\n", name)

// Print the URL.
fmt.Println("\tURL:", url.Format("\n\t\t"))
fmt.Println("\tURL:", terminal.NeutralizeControlCharacters(url.Format("\n\t\t")))

// Print configuration information if desired.
if mode == common.SessionDisplayModeListLong || mode == common.SessionDisplayModeMonitorLong {
Expand Down Expand Up @@ -142,7 +143,7 @@ func printSession(state *forwarding.State, mode common.SessionDisplayMode) {

// Print the last error, if any.
if state.LastError != "" {
color.Red("Last error: %s\n", state.LastError)
color.Red("Last error: %s\n", terminal.NeutralizeControlCharacters(state.LastError))
}

// Print the session status .
Expand Down
4 changes: 2 additions & 2 deletions cmd/mutagen/forward/monitor.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ func monitorMain(_ *cobra.Command, arguments []string) error {
defer daemonConnection.Close()

// Create a session service client.
sessionService := forwardingsvc.NewForwardingClient(daemonConnection)
forwardingService := forwardingsvc.NewForwardingClient(daemonConnection)

// Create the list request that we'll use.
request := &forwardingsvc.ListRequest{
Expand Down Expand Up @@ -126,7 +126,7 @@ func monitorMain(_ *cobra.Command, arguments []string) error {
lastUpdateTime = now

// Perform a list operation.
response, err := sessionService.List(context.Background(), request)
response, err := forwardingService.List(context.Background(), request)
if err != nil {
return fmt.Errorf("list failed: %w", grpcutil.PeelAwayRPCErrorLayer(err))
} else if err = response.EnsureValid(); err != nil {
Expand Down
15 changes: 11 additions & 4 deletions cmd/mutagen/project/common_windows.go
Original file line number Diff line number Diff line change
@@ -1,17 +1,24 @@
package project

import (
"errors"
"os"
"os/exec"
"path/filepath"
)

// runInShell runs the specified command using the system shell. On Windows
// systems, this is %COMSPEC% (with a fallback to cmd.exe if unspecified).
// systems, this is %ComSpec% (with a fallback to a fully qualified cmd.exe if
// %ComSpec% is not an absolute path (which includes cases where it's empty)).
func runInShell(command string) error {
// Determine the shell to use.
shell := os.Getenv("COMSPEC")
if shell == "" {
shell = "cmd.exe"
shell := os.Getenv("ComSpec")
if !filepath.IsAbs(shell) {
systemRoot := os.Getenv("SystemRoot")
if !filepath.IsAbs(systemRoot) {
return errors.New("invalid ComSpec and SystemRoot environment variables")
}
shell = filepath.Join(systemRoot, "System32", "cmd.exe")
}

// Set up the process.
Expand Down
37 changes: 22 additions & 15 deletions cmd/mutagen/sync/list_monitor_common.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (

"github.com/mutagen-io/mutagen/cmd/mutagen/common"

"github.com/mutagen-io/mutagen/pkg/platform/terminal"
"github.com/mutagen-io/mutagen/pkg/selection"
"github.com/mutagen-io/mutagen/pkg/synchronization"
"github.com/mutagen-io/mutagen/pkg/synchronization/core"
Expand Down Expand Up @@ -87,7 +88,7 @@ func printEndpoint(name string, url *urlpkg.URL, configuration *synchronization.
fmt.Printf("%s:\n", name)

// Print the URL.
fmt.Println("\tURL:", url.Format("\n\t\t"))
fmt.Println("\tURL:", terminal.NeutralizeControlCharacters(url.Format("\n\t\t")))

// Print configuration information if desired.
if mode == common.SessionDisplayModeListLong || mode == common.SessionDisplayModeMonitorLong {
Expand Down Expand Up @@ -157,14 +158,14 @@ func printEndpoint(name string, url *urlpkg.URL, configuration *synchronization.
if configuration.DefaultOwner != "" {
defaultOwnerDescription = configuration.DefaultOwner
}
fmt.Println("\t\tDefault file/directory owner:", defaultOwnerDescription)
fmt.Println("\t\tDefault file/directory owner:", terminal.NeutralizeControlCharacters(defaultOwnerDescription))

// Compute and print the default file/directory group.
defaultGroupDescription := "Default"
if configuration.DefaultGroup != "" {
defaultGroupDescription = configuration.DefaultGroup
}
fmt.Println("\t\tDefault file/directory group:", defaultGroupDescription)
fmt.Println("\t\tDefault file/directory group:", terminal.NeutralizeControlCharacters(defaultGroupDescription))

// If the endpoint is remote, then compute and print the compression
// algorithm.
Expand Down Expand Up @@ -205,7 +206,10 @@ func printEndpoint(name string, url *urlpkg.URL, configuration *synchronization.
} else if mode == common.SessionDisplayModeListLong {
color.Red("\tScan problems:\n")
for _, p := range state.ScanProblems {
color.Red("\t\t%s: %v\n", formatPath(p.Path), p.Error)
color.Red("\t\t%s: %v\n",
terminal.NeutralizeControlCharacters(formatPath(p.Path)),
terminal.NeutralizeControlCharacters(p.Error),
)
}
if state.ExcludedScanProblems > 0 {
color.Red("\t\t...+%d more...\n", state.ExcludedScanProblems)
Expand All @@ -222,7 +226,10 @@ func printEndpoint(name string, url *urlpkg.URL, configuration *synchronization.
} else if mode == common.SessionDisplayModeListLong {
color.Red("\tTransition problems:\n")
for _, p := range state.TransitionProblems {
color.Red("\t\t%s: %v\n", formatPath(p.Path), p.Error)
color.Red("\t\t%s: %v\n",
terminal.NeutralizeControlCharacters(formatPath(p.Path)),
terminal.NeutralizeControlCharacters(p.Error),
)
}
if state.ExcludedTransitionProblems > 0 {
color.Red("\t\t...+%d more...\n", state.ExcludedTransitionProblems)
Expand All @@ -247,19 +254,19 @@ func printConflicts(conflicts []*core.Conflict, excludedConflicts uint64) {
for _, a := range c.AlphaChanges {
color.Red(
"\t(alpha) %s (%s -> %s)\n",
formatPath(a.Path),
formatEntry(a.Old),
formatEntry(a.New),
terminal.NeutralizeControlCharacters(formatPath(a.Path)),
terminal.NeutralizeControlCharacters(formatEntry(a.Old)),
terminal.NeutralizeControlCharacters(formatEntry(a.New)),
)
}

// Print the beta changes.
for _, b := range c.BetaChanges {
color.Red(
"\t(beta) %s (%s -> %s)\n",
formatPath(b.Path),
formatEntry(b.Old),
formatEntry(b.New),
terminal.NeutralizeControlCharacters(formatPath(b.Path)),
terminal.NeutralizeControlCharacters(formatEntry(b.Old)),
terminal.NeutralizeControlCharacters(formatEntry(b.New)),
)
}

Expand Down Expand Up @@ -374,15 +381,15 @@ func printSession(state *synchronization.State, mode common.SessionDisplayMode)
if len(configuration.DefaultIgnores) > 0 {
fmt.Println("\tDefault ignores:")
for _, p := range configuration.DefaultIgnores {
fmt.Printf("\t\t%s\n", p)
fmt.Printf("\t\t%s\n", terminal.NeutralizeControlCharacters(p))
}
}

// Print per-session ignores.
if len(configuration.Ignores) > 0 {
fmt.Println("\tIgnores:")
for _, p := range configuration.Ignores {
fmt.Printf("\t\t%s\n", p)
fmt.Printf("\t\t%s\n", terminal.NeutralizeControlCharacters(p))
}
} else {
fmt.Println("\tIgnores: None")
Expand Down Expand Up @@ -439,7 +446,7 @@ func printSession(state *synchronization.State, mode common.SessionDisplayMode)

// Print the last error, if any.
if state.LastError != "" {
color.Red("Last error: %s\n", state.LastError)
color.Red("Last error: %s\n", terminal.NeutralizeControlCharacters(state.LastError))
}

// Print the session status .
Expand Down Expand Up @@ -477,7 +484,7 @@ func printSession(state *synchronization.State, mode common.SessionDisplayMode)
stagingProgress.ReceivedFiles, stagingProgress.ExpectedFiles,
humanize.Bytes(stagingProgress.TotalReceivedSize), totalSizeDenominator,
100.0*fractionComplete,
stagingProgress.Path,
terminal.NeutralizeControlCharacters(stagingProgress.Path),
humanize.Bytes(stagingProgress.ReceivedSize), humanize.Bytes(stagingProgress.ExpectedSize),
)
}
Expand Down
7 changes: 4 additions & 3 deletions cmd/mutagen/sync/monitor.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (

synchronizationmodels "github.com/mutagen-io/mutagen/pkg/api/models/synchronization"
"github.com/mutagen-io/mutagen/pkg/grpcutil"
"github.com/mutagen-io/mutagen/pkg/platform/terminal"
selectionpkg "github.com/mutagen-io/mutagen/pkg/selection"
synchronizationsvc "github.com/mutagen-io/mutagen/pkg/service/synchronization"
"github.com/mutagen-io/mutagen/pkg/synchronization"
Expand Down Expand Up @@ -97,7 +98,7 @@ func computeMonitorStatusLine(state *synchronization.State) string {
stagingProgress.ReceivedFiles, stagingProgress.ExpectedFiles,
humanize.Bytes(stagingProgress.TotalReceivedSize), totalSizeDenominator,
100.0*fractionComplete,
path.Base(stagingProgress.Path),
terminal.NeutralizeControlCharacters(path.Base(stagingProgress.Path)),
humanize.Bytes(stagingProgress.ReceivedSize), humanize.Bytes(stagingProgress.ExpectedSize),
)
}
Expand Down Expand Up @@ -140,7 +141,7 @@ func monitorMain(_ *cobra.Command, arguments []string) error {
defer daemonConnection.Close()

// Create a session service client.
sessionService := synchronizationsvc.NewSynchronizationClient(daemonConnection)
synchronizationService := synchronizationsvc.NewSynchronizationClient(daemonConnection)

// Create the list request that we'll use.
request := &synchronizationsvc.ListRequest{
Expand Down Expand Up @@ -176,7 +177,7 @@ func monitorMain(_ *cobra.Command, arguments []string) error {
lastUpdateTime = now

// Perform a list operation.
response, err := sessionService.List(context.Background(), request)
response, err := synchronizationService.List(context.Background(), request)
if err != nil {
return fmt.Errorf("list failed: %w", grpcutil.PeelAwayRPCErrorLayer(err))
} else if err = response.EnsureValid(); err != nil {
Expand Down
2 changes: 1 addition & 1 deletion images/sidecar/linux/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Use an Alpine-based Go builder.
FROM golang:1.20.1-alpine3.17 AS builder
FROM golang:1.20.4-alpine3.17 AS builder

# Disable cgo in order to match the behavior of our release binaries (and to
# avoid the need for gcc on certain architectures).
Expand Down
8 changes: 5 additions & 3 deletions pkg/agent/dial.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"github.com/mutagen-io/mutagen/pkg/filesystem"
"github.com/mutagen-io/mutagen/pkg/logging"
"github.com/mutagen-io/mutagen/pkg/mutagen"
"github.com/mutagen-io/mutagen/pkg/platform/terminal"
"github.com/mutagen-io/mutagen/pkg/prompting"
streampkg "github.com/mutagen-io/mutagen/pkg/stream"
)
Expand Down Expand Up @@ -129,13 +130,14 @@ func connect(logger *logging.Logger, transport Transport, mode, prompter string,
// which is all we care about.
stream.Close()

// Extract any error output, ensure that it's UTF-8, and strip out any
// whitespace (primarily trailing newlines).
// Extract any error output, ensure that it's UTF-8, strip out any
// whitespace (primarily trailing newlines), and neutralize any control
// characters.
errorOutput := errorBuffer.String()
if !utf8.ValidString(errorOutput) {
return nil, false, false, errors.New("remote did not return UTF-8 output")
}
errorOutput = strings.TrimSpace(errorOutput)
errorOutput = terminal.NeutralizeControlCharacters(strings.TrimSpace(errorOutput))

// Wrap up the handshake error with additional context.
if errorOutput != "" {
Expand Down
Loading

0 comments on commit 1228b15

Please sign in to comment.