Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion cmd/mutagen/daemon/connect.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ func Connect(autostart, enforceVersionMatch bool) (*grpc.ClientConn, error) {
// Check for errors.
if err != nil {
// Handle failure due to timeouts.
if err == context.DeadlineExceeded {
if errors.Is(err, context.DeadlineExceeded) {
// If autostart is enabled, and we have attempts remaining, then
// try autostarting, waiting, and retrying.
if autostart && remainingPostAutostatAttempts > 0 {
Expand Down
2 changes: 1 addition & 1 deletion pkg/agent/bundle.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ func ExecutableForPlatform(goos, goarch, outputPath string) (string, error) {
var header *tar.Header
for {
if h, err := bundleArchive.Next(); err != nil {
if err == io.EOF {
if errors.Is(err, io.EOF) {
break
}
return "", fmt.Errorf("unable to read archive header: %w", err)
Expand Down
5 changes: 3 additions & 2 deletions pkg/filesystem/behavior/internal/format/format_statfs.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
package format

import (
"errors"
"fmt"

"golang.org/x/sys/unix"
Expand All @@ -15,7 +16,7 @@ import (
func statfsRetryingOnEINTR(path string, metadata *unix.Statfs_t) error {
for {
err := unix.Statfs(path, metadata)
if err == unix.EINTR {
if errors.Is(err, unix.EINTR) {
continue
}
return err
Expand All @@ -28,7 +29,7 @@ func statfsRetryingOnEINTR(path string, metadata *unix.Statfs_t) error {
func fstatfsRetryingOnEINTR(fd int, metadata *unix.Statfs_t) error {
for {
err := unix.Fstatfs(fd, metadata)
if err == unix.EINTR {
if errors.Is(err, unix.EINTR) {
continue
}
return err
Expand Down
6 changes: 3 additions & 3 deletions pkg/filesystem/directory_posix.go
Original file line number Diff line number Diff line change
Expand Up @@ -448,7 +448,7 @@ func (d *Directory) ReadSymbolicLink(name string) (string, error) {

// Handle errors. If we see ERANGE on AIX systems, it's an indication
// that the buffer size is too small.
if runtime.GOOS == "aix" && err == unix.ERANGE {
if runtime.GOOS == "aix" && errors.Is(err, unix.ERANGE) {
continue
} else if err != nil {
return "", err
Expand Down Expand Up @@ -554,7 +554,7 @@ func Rename(
)
if err == nil || (err != unix.ENOTSUP && err != unix.ENOSYS) {
return err
} else if err == unix.ENOTSUP && targetDirectory != nil {
} else if errors.Is(err, unix.ENOTSUP) && targetDirectory != nil {
targetDirectory.renameatNoReplaceUnsupported.Mark()
}
}
Expand Down Expand Up @@ -588,5 +588,5 @@ func Rename(
// IsCrossDeviceError checks whether or not an error returned from rename
// represents a cross-device error.
func IsCrossDeviceError(err error) bool {
return err == unix.EXDEV
return errors.Is(err, unix.EXDEV)
}
4 changes: 3 additions & 1 deletion pkg/filesystem/directory_rename_darwin.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package filesystem

import (
"errors"

"golang.org/x/sys/unix"

"github.com/mutagen-io/mutagen/pkg/filesystem/internal/syscall"
Expand All @@ -15,7 +17,7 @@ import (
func renameatNoReplaceRetryingOnEINTR(oldDirectory int, oldPath string, newDirectory int, newPath string) error {
for {
err := syscall.Renameatx_np(oldDirectory, oldPath, newDirectory, newPath, syscall.RENAME_EXCL)
if err == unix.EINTR {
if errors.Is(err, unix.EINTR) {
continue
}
return err
Expand Down
8 changes: 5 additions & 3 deletions pkg/filesystem/directory_rename_linux.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package filesystem

import (
"errors"

"golang.org/x/sys/unix"

"github.com/mutagen-io/mutagen/pkg/state"
Expand All @@ -24,9 +26,9 @@ func renameatNoReplaceRetryingOnEINTR(oldDirectory int, oldPath string, newDirec
// Loop until renameat2 completes with a return value other that EINTR.
for {
err := unix.Renameat2(oldDirectory, oldPath, newDirectory, newPath, unix.RENAME_NOREPLACE)
if err == unix.EINTR {
if errors.Is(err, unix.EINTR) {
continue
} else if err == unix.EINVAL {
} else if errors.Is(err, unix.EINVAL) {
// HACK: On Linux, using RENAME_NOREPLACE with a target filesystem
// that doesn't support it will yield EINVAL. To keep consistency
// with other renameatNoReplaceRetryingOnEINTR implementations, we
Expand All @@ -38,7 +40,7 @@ func renameatNoReplaceRetryingOnEINTR(oldDirectory int, oldPath string, newDirec
// invocation of renameat2. The only other error we'd need to
// consider would be ENOSYS, but that we don't need to alias.
return unix.ENOTSUP
} else if err == unix.ENOSYS {
} else if errors.Is(err, unix.ENOSYS) {
renameat2FailedWithENOSYS.Mark()
}
return err
Expand Down
25 changes: 13 additions & 12 deletions pkg/filesystem/interrupt_posix.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
package filesystem

import (
"errors"
"io"

"golang.org/x/sys/unix"
Expand All @@ -15,7 +16,7 @@ import (
func openatRetryingOnEINTR(directory int, path string, flags int, mode uint32) (int, error) {
for {
result, err := unix.Openat(directory, path, flags, mode)
if err == unix.EINTR {
if errors.Is(err, unix.EINTR) {
continue
}
return result, err
Expand All @@ -27,7 +28,7 @@ func openatRetryingOnEINTR(directory int, path string, flags int, mode uint32) (
func readRetryingOnEINTR(file int, buffer []byte) (int, error) {
for {
result, err := unix.Read(file, buffer)
if err == unix.EINTR {
if errors.Is(err, unix.EINTR) {
continue
} else if err == nil && result == 0 {
return 0, io.EOF
Expand Down Expand Up @@ -64,7 +65,7 @@ func closeConsideringEINTR(file int) error {
func mkdiratRetryingOnEINTR(directory int, path string, mode uint32) error {
for {
err := unix.Mkdirat(directory, path, mode)
if err == unix.EINTR {
if errors.Is(err, unix.EINTR) {
continue
}
return err
Expand All @@ -77,7 +78,7 @@ func mkdiratRetryingOnEINTR(directory int, path string, mode uint32) error {
func renameatRetryingOnEINTR(oldDirectory int, oldPath string, newDirectory int, newPath string) error {
for {
err := unix.Renameat(oldDirectory, oldPath, newDirectory, newPath)
if err == unix.EINTR {
if errors.Is(err, unix.EINTR) {
continue
}
return err
Expand All @@ -90,7 +91,7 @@ func renameatRetryingOnEINTR(oldDirectory int, oldPath string, newDirectory int,
func unlinkatRetryingOnEINTR(directory int, path string, flags int) error {
for {
err := unix.Unlinkat(directory, path, flags)
if err == unix.EINTR {
if errors.Is(err, unix.EINTR) {
continue
}
return err
Expand All @@ -102,7 +103,7 @@ func unlinkatRetryingOnEINTR(directory int, path string, flags int) error {
func fstatRetryingOnEINTR(file int, metadata *unix.Stat_t) error {
for {
err := unix.Fstat(file, metadata)
if err == unix.EINTR {
if errors.Is(err, unix.EINTR) {
continue
}
return err
Expand All @@ -114,7 +115,7 @@ func fstatRetryingOnEINTR(file int, metadata *unix.Stat_t) error {
func fchmodRetryingOnEINTR(file int, mode uint32) error {
for {
err := unix.Fchmod(file, mode)
if err == unix.EINTR {
if errors.Is(err, unix.EINTR) {
continue
}
return err
Expand All @@ -127,7 +128,7 @@ func fchmodRetryingOnEINTR(file int, mode uint32) error {
func fstatatRetryingOnEINTR(directory int, path string, metadata *unix.Stat_t, flags int) error {
for {
err := unix.Fstatat(directory, path, metadata, flags)
if err == unix.EINTR {
if errors.Is(err, unix.EINTR) {
continue
}
return err
Expand All @@ -140,7 +141,7 @@ func fstatatRetryingOnEINTR(directory int, path string, metadata *unix.Stat_t, f
func fchmodatRetryingOnEINTR(directory int, path string, mode uint32, flags int) error {
for {
err := unix.Fchmodat(directory, path, mode, flags)
if err == unix.EINTR {
if errors.Is(err, unix.EINTR) {
continue
}
return err
Expand All @@ -153,7 +154,7 @@ func fchmodatRetryingOnEINTR(directory int, path string, mode uint32, flags int)
func fchownatRetryingOnEINTR(directory int, path string, uid int, gid int, flags int) error {
for {
err := unix.Fchownat(directory, path, uid, gid, flags)
if err == unix.EINTR {
if errors.Is(err, unix.EINTR) {
continue
}
return err
Expand All @@ -166,7 +167,7 @@ func fchownatRetryingOnEINTR(directory int, path string, uid int, gid int, flags
func symlinkatRetryingOnEINTR(target string, directory int, path string) error {
for {
err := syscall.Symlinkat(target, directory, path)
if err == unix.EINTR {
if errors.Is(err, unix.EINTR) {
continue
}
return err
Expand All @@ -179,7 +180,7 @@ func symlinkatRetryingOnEINTR(target string, directory int, path string) error {
func readlinkatRetryingOnEINTR(directory int, path string, buffer []byte) (int, error) {
for {
result, err := syscall.Readlinkat(directory, path, buffer)
if err == unix.EINTR {
if errors.Is(err, unix.EINTR) {
continue
}
return result, err
Expand Down
2 changes: 1 addition & 1 deletion pkg/filesystem/locking/locker_posix.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import (
func fcntlFlockRetryingOnEINTR(file uintptr, command int, specification *unix.Flock_t) error {
for {
err := unix.FcntlFlock(file, command, specification)
if err == unix.EINTR {
if errors.Is(err, unix.EINTR) {
continue
}
return err
Expand Down
6 changes: 3 additions & 3 deletions pkg/multiplexing/multiplexer.go
Original file line number Diff line number Diff line change
Expand Up @@ -381,7 +381,7 @@ func (m *Multiplexer) read(reader Carrier, heartbeats chan<- struct{}) error {
stream.receiveBufferLock.Lock()
if _, err := stream.receiveBuffer.ReadNFrom(reader, length); err != nil {
stream.receiveBufferLock.Unlock()
if err == ring.ErrBufferFull {
if errors.Is(err, ring.ErrBufferFull) {
return errors.New("remote violated stream receive window")
}
return fmt.Errorf("unable to read stream data into buffer: %w", err)
Expand Down Expand Up @@ -694,13 +694,13 @@ func (m *Multiplexer) acceptOneStream(ctx context.Context) (*Stream, error) {
return stream, nil
}

// AcceptContext accepts an incoming stream.
// AcceptStream accepts an incoming stream.
func (m *Multiplexer) AcceptStream(ctx context.Context) (*Stream, error) {
// Loop until we find a pending stream that's not stale or encounter some
// other error.
for {
stream, err := m.acceptOneStream(ctx)
if err == errStaleInboundStream {
if errors.Is(err, errStaleInboundStream) {
continue
}
return stream, err
Expand Down
5 changes: 3 additions & 2 deletions pkg/multiplexing/multiplexer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package multiplexing

import (
"context"
"errors"
"fmt"
"net"
"sync"
Expand All @@ -20,7 +21,7 @@ func makeNetTestMakePipe(opener, acceptor *Multiplexer) nettest.MakePipe {
var openErr, acceptErr error
go func() {
opened, openErr = opener.OpenStream(context.Background())
if openErr == ErrMultiplexerClosed {
if errors.Is(openErr, ErrMultiplexerClosed) {
if internalErr := opener.InternalError(); internalErr != nil {
openErr = fmt.Errorf("multiplexer closed due to internal error: %w", internalErr)
}
Expand All @@ -29,7 +30,7 @@ func makeNetTestMakePipe(opener, acceptor *Multiplexer) nettest.MakePipe {
}()
go func() {
accepted, acceptErr = acceptor.AcceptStream(context.Background())
if acceptErr == ErrMultiplexerClosed {
if errors.Is(acceptErr, ErrMultiplexerClosed) {
if internalErr := acceptor.InternalError(); internalErr != nil {
acceptErr = fmt.Errorf("multiplexer closed due to internal error: %w", internalErr)
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/multiplexing/ring/buffer.go
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ func (b *Buffer) ReadNFrom(reader io.Reader, n int) (int, error) {

// If we encountered io.EOF simultaneously with completing the read, then we
// can clear the error.
if err == io.EOF && n == 0 {
if errors.Is(err, io.EOF) && n == 0 {
err = nil
}

Expand Down
3 changes: 2 additions & 1 deletion pkg/state/lock_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package state

import (
"context"
"errors"
"testing"
"time"
)
Expand All @@ -28,7 +29,7 @@ func TestTrackingLock(t *testing.T) {

// Wait for termination and ensure that the state doesn't change.
finalState, err := tracker.WaitForChange(context.Background(), firstState)
handoff <- (finalState == firstState && err == ErrTrackingTerminated)
handoff <- (finalState == firstState && errors.Is(err, ErrTrackingTerminated))
}()

// Acquire and release the lock in a way that will change the state, and
Expand Down
3 changes: 2 additions & 1 deletion pkg/state/tracker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package state

import (
"context"
"errors"
"testing"
"time"
)
Expand Down Expand Up @@ -45,7 +46,7 @@ func TestTracker(t *testing.T) {

// Wait for termination and ensure that the state doesn't change.
finalState, err := tracker.WaitForChange(context.Background(), secondState)
handoff <- (finalState == firstState && err == ErrTrackingTerminated)
handoff <- (finalState == firstState && errors.Is(err, ErrTrackingTerminated))
}()

// Notify of a change and wait for a response.
Expand Down
2 changes: 1 addition & 1 deletion pkg/synchronization/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -808,7 +808,7 @@ func (c *controller) run(ctx context.Context, alpha, beta Endpoint) {

// If synchronization failed due a halting error, then wait for the
// synchronization loop to be manually resumed.
if err == errHaltedForSafety {
if errors.Is(err, errHaltedForSafety) {
<-ctx.Done()
return
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/synchronization/core/scan.go
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ func (s *scanner) file(
// timely cancellation.
preemptableHasher := stream.NewPreemptableWriter(s.hasher, s.cancelled, scannerCopyPreemptionInterval)
if copied, err := io.CopyBuffer(preemptableHasher, file, s.copyBuffer); err != nil {
if err == stream.ErrWritePreempted {
if errors.Is(err, stream.ErrWritePreempted) {
return nil, ErrScanCancelled
}
return &Entry{
Expand Down
2 changes: 1 addition & 1 deletion pkg/synchronization/core/transition.go
Original file line number Diff line number Diff line change
Expand Up @@ -662,7 +662,7 @@ func (t *transitioner) findAndMoveStagedFileIntoPlace(
// If there was a copy error, then remove the temporary and abort.
if copyErr != nil {
parent.RemoveFile(temporaryName)
if copyErr == stream.ErrWritePreempted {
if errors.Is(copyErr, stream.ErrWritePreempted) {
return errTransitionCancelled
}
return fmt.Errorf("unable to copy file contents: %w", copyErr)
Expand Down
2 changes: 1 addition & 1 deletion pkg/synchronization/endpoint/local/endpoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -937,7 +937,7 @@ WatchEstablishment:
// events are likely happening on disk faster than we can
// process them. In that case, wait one polling interval before
// attempting to re-establish the watch.
if err == watching.ErrWatchInternalOverflow {
if errors.Is(err, watching.ErrWatchInternalOverflow) {
logger.Debug("Waiting before watch re-establishment")
timer.Reset(pollingDuration)
select {
Expand Down
Loading