mirror of
https://github.com/rclone/rclone.git
synced 2025-12-06 00:03:32 +00:00
Remove github.com/pkg/errors and replace with std library version
This is possible now that we no longer support go1.12 and brings rclone into line with standard practices in the Go world. This also removes errors.New and errors.Errorf from lib/errors and prefers the stdlib errors package over lib/errors.
This commit is contained in:
@@ -5,6 +5,7 @@ package sftp
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
"net"
|
||||
@@ -12,7 +13,6 @@ import (
|
||||
"regexp"
|
||||
"strings"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
"github.com/pkg/sftp"
|
||||
"github.com/rclone/rclone/fs"
|
||||
"github.com/rclone/rclone/fs/hash"
|
||||
@@ -74,7 +74,7 @@ func (c *conn) execCommand(ctx context.Context, out io.Writer, command string) (
|
||||
}
|
||||
usage, err := about(ctx)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "About failed")
|
||||
return fmt.Errorf("About failed: %w", err)
|
||||
}
|
||||
total, used, free := int64(-1), int64(-1), int64(-1)
|
||||
if usage.Total != nil {
|
||||
@@ -94,7 +94,7 @@ func (c *conn) execCommand(ctx context.Context, out io.Writer, command string) (
|
||||
/dev/root %d %d %d %d%% /
|
||||
`, total, used, free, perc)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "send output failed")
|
||||
return fmt.Errorf("send output failed: %w", err)
|
||||
}
|
||||
case "md5sum", "sha1sum":
|
||||
ht := hash.MD5
|
||||
@@ -113,7 +113,7 @@ func (c *conn) execCommand(ctx context.Context, out io.Writer, command string) (
|
||||
} else {
|
||||
node, err := c.vfs.Stat(args)
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "hash failed finding file %q", args)
|
||||
return fmt.Errorf("hash failed finding file %q: %w", args, err)
|
||||
}
|
||||
if node.IsDir() {
|
||||
return errors.New("can't hash directory")
|
||||
@@ -124,12 +124,12 @@ func (c *conn) execCommand(ctx context.Context, out io.Writer, command string) (
|
||||
}
|
||||
hashSum, err = o.Hash(ctx, ht)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "hash failed")
|
||||
return fmt.Errorf("hash failed: %w", err)
|
||||
}
|
||||
}
|
||||
_, err = fmt.Fprintf(out, "%s %s\n", hashSum, args)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "send output failed")
|
||||
return fmt.Errorf("send output failed: %w", err)
|
||||
}
|
||||
case "echo":
|
||||
// special cases for rclone command detection
|
||||
@@ -138,7 +138,7 @@ func (c *conn) execCommand(ctx context.Context, out io.Writer, command string) (
|
||||
if c.vfs.Fs().Hashes().Contains(hash.MD5) {
|
||||
_, err = fmt.Fprintf(out, "0bee89b07a248e27c83fc3d5951213c1 -\n")
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "send output failed")
|
||||
return fmt.Errorf("send output failed: %w", err)
|
||||
}
|
||||
} else {
|
||||
return errors.New("md5 hash not supported")
|
||||
@@ -147,7 +147,7 @@ func (c *conn) execCommand(ctx context.Context, out io.Writer, command string) (
|
||||
if c.vfs.Fs().Hashes().Contains(hash.SHA1) {
|
||||
_, err = fmt.Fprintf(out, "03cfd743661f07975fa2f1220c5194cbaff48451 -\n")
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "send output failed")
|
||||
return fmt.Errorf("send output failed: %w", err)
|
||||
}
|
||||
} else {
|
||||
return errors.New("sha1 hash not supported")
|
||||
@@ -155,11 +155,11 @@ func (c *conn) execCommand(ctx context.Context, out io.Writer, command string) (
|
||||
default:
|
||||
_, err = fmt.Fprintf(out, "%s\n", args)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "send output failed")
|
||||
return fmt.Errorf("send output failed: %w", err)
|
||||
}
|
||||
}
|
||||
default:
|
||||
return errors.Errorf("%q not implemented\n", command)
|
||||
return fmt.Errorf("%q not implemented", command)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
@@ -268,7 +268,7 @@ func serveChannel(rwc io.ReadWriteCloser, h sftp.Handlers, what string) error {
|
||||
}()
|
||||
err := server.Serve()
|
||||
if err != nil && err != io.EOF {
|
||||
return errors.Wrap(err, "completed with error")
|
||||
return fmt.Errorf("completed with error: %w", err)
|
||||
}
|
||||
fs.Debugf(what, "exited session")
|
||||
return nil
|
||||
|
||||
Reference in New Issue
Block a user