mirror of
https://github.com/rclone/rclone.git
synced 2025-12-11 22:14:05 +01: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:
@@ -2,11 +2,11 @@ package union
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"io"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
"github.com/rclone/rclone/backend/union/upstream"
|
||||
"github.com/rclone/rclone/fs"
|
||||
)
|
||||
@@ -82,7 +82,7 @@ func (o *Object) Update(ctx context.Context, in io.Reader, src fs.ObjectInfo, op
|
||||
multithread(len(entries), func(i int) {
|
||||
if o, ok := entries[i].(*upstream.Object); ok {
|
||||
err := o.Update(ctx, readers[i], src, options...)
|
||||
errs[i] = errors.Wrap(err, o.UpstreamFs().Name())
|
||||
errs[i] = fmt.Errorf("%s: %w", o.UpstreamFs().Name(), err)
|
||||
} else {
|
||||
errs[i] = fs.ErrorNotAFile
|
||||
}
|
||||
@@ -101,7 +101,7 @@ func (o *Object) Remove(ctx context.Context) error {
|
||||
multithread(len(entries), func(i int) {
|
||||
if o, ok := entries[i].(*upstream.Object); ok {
|
||||
err := o.Remove(ctx)
|
||||
errs[i] = errors.Wrap(err, o.UpstreamFs().Name())
|
||||
errs[i] = fmt.Errorf("%s: %w", o.UpstreamFs().Name(), err)
|
||||
} else {
|
||||
errs[i] = fs.ErrorNotAFile
|
||||
}
|
||||
@@ -120,7 +120,7 @@ func (o *Object) SetModTime(ctx context.Context, t time.Time) error {
|
||||
multithread(len(entries), func(i int) {
|
||||
if o, ok := entries[i].(*upstream.Object); ok {
|
||||
err := o.SetModTime(ctx, t)
|
||||
errs[i] = errors.Wrap(err, o.UpstreamFs().Name())
|
||||
errs[i] = fmt.Errorf("%s: %w", o.UpstreamFs().Name(), err)
|
||||
} else {
|
||||
errs[i] = fs.ErrorNotAFile
|
||||
}
|
||||
|
||||
@@ -2,12 +2,12 @@ package policy
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"math/rand"
|
||||
"path"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
"github.com/rclone/rclone/backend/union/upstream"
|
||||
"github.com/rclone/rclone/fs"
|
||||
)
|
||||
@@ -44,7 +44,7 @@ func registerPolicy(name string, p Policy) {
|
||||
func Get(name string) (Policy, error) {
|
||||
p, ok := policies[strings.ToLower(name)]
|
||||
if !ok {
|
||||
return nil, errors.Errorf("didn't find policy called %q", name)
|
||||
return nil, fmt.Errorf("didn't find policy called %q", name)
|
||||
}
|
||||
return p, nil
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@ package union
|
||||
import (
|
||||
"bufio"
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
"path"
|
||||
@@ -11,7 +12,6 @@ import (
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
"github.com/rclone/rclone/backend/union/policy"
|
||||
"github.com/rclone/rclone/backend/union/upstream"
|
||||
"github.com/rclone/rclone/fs"
|
||||
@@ -99,7 +99,7 @@ func (f *Fs) wrapEntries(entries ...upstream.Entry) (entry, error) {
|
||||
cd: entries,
|
||||
}, nil
|
||||
default:
|
||||
return nil, errors.Errorf("unknown object type %T", e)
|
||||
return nil, fmt.Errorf("unknown object type %T", e)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -132,7 +132,7 @@ func (f *Fs) Rmdir(ctx context.Context, dir string) error {
|
||||
errs := Errors(make([]error, len(upstreams)))
|
||||
multithread(len(upstreams), func(i int) {
|
||||
err := upstreams[i].Rmdir(ctx, dir)
|
||||
errs[i] = errors.Wrap(err, upstreams[i].Name())
|
||||
errs[i] = fmt.Errorf("%s: %w", upstreams[i].Name(), err)
|
||||
})
|
||||
return errs.Err()
|
||||
}
|
||||
@@ -162,7 +162,7 @@ func (f *Fs) Mkdir(ctx context.Context, dir string) error {
|
||||
errs := Errors(make([]error, len(upstreams)))
|
||||
multithread(len(upstreams), func(i int) {
|
||||
err := upstreams[i].Mkdir(ctx, dir)
|
||||
errs[i] = errors.Wrap(err, upstreams[i].Name())
|
||||
errs[i] = fmt.Errorf("%s: %w", upstreams[i].Name(), err)
|
||||
})
|
||||
return errs.Err()
|
||||
}
|
||||
@@ -186,10 +186,10 @@ func (f *Fs) Purge(ctx context.Context, dir string) error {
|
||||
errs := Errors(make([]error, len(upstreams)))
|
||||
multithread(len(upstreams), func(i int) {
|
||||
err := upstreams[i].Features().Purge(ctx, dir)
|
||||
if errors.Cause(err) == fs.ErrorDirNotFound {
|
||||
if errors.Is(err, fs.ErrorDirNotFound) {
|
||||
err = nil
|
||||
}
|
||||
errs[i] = errors.Wrap(err, upstreams[i].Name())
|
||||
errs[i] = fmt.Errorf("%s: %w", upstreams[i].Name(), err)
|
||||
})
|
||||
return errs.Err()
|
||||
}
|
||||
@@ -264,7 +264,7 @@ func (f *Fs) Move(ctx context.Context, src fs.Object, remote string) (fs.Object,
|
||||
su := entries[i].UpstreamFs()
|
||||
o, ok := entries[i].(*upstream.Object)
|
||||
if !ok {
|
||||
errs[i] = errors.Wrap(fs.ErrorNotAFile, su.Name())
|
||||
errs[i] = fmt.Errorf("%s: %w", su.Name(), fs.ErrorNotAFile)
|
||||
return
|
||||
}
|
||||
var du *upstream.Fs
|
||||
@@ -274,7 +274,7 @@ func (f *Fs) Move(ctx context.Context, src fs.Object, remote string) (fs.Object,
|
||||
}
|
||||
}
|
||||
if du == nil {
|
||||
errs[i] = errors.Wrap(fs.ErrorCantMove, su.Name()+":"+remote)
|
||||
errs[i] = fmt.Errorf("%s: %s: %w", su.Name(), remote, fs.ErrorCantMove)
|
||||
return
|
||||
}
|
||||
srcObj := o.UnWrap()
|
||||
@@ -286,7 +286,7 @@ func (f *Fs) Move(ctx context.Context, src fs.Object, remote string) (fs.Object,
|
||||
// Do the Move or Copy
|
||||
dstObj, err := do(ctx, srcObj, remote)
|
||||
if err != nil || dstObj == nil {
|
||||
errs[i] = errors.Wrap(err, su.Name())
|
||||
errs[i] = fmt.Errorf("%s: %w", su.Name(), err)
|
||||
return
|
||||
}
|
||||
objs[i] = du.WrapObject(dstObj)
|
||||
@@ -294,7 +294,7 @@ func (f *Fs) Move(ctx context.Context, src fs.Object, remote string) (fs.Object,
|
||||
if duFeatures.Move == nil {
|
||||
err = srcObj.Remove(ctx)
|
||||
if err != nil {
|
||||
errs[i] = errors.Wrap(err, su.Name())
|
||||
errs[i] = fmt.Errorf("%s: %w", su.Name(), err)
|
||||
return
|
||||
}
|
||||
}
|
||||
@@ -345,18 +345,18 @@ func (f *Fs) DirMove(ctx context.Context, src fs.Fs, srcRemote, dstRemote string
|
||||
}
|
||||
}
|
||||
if du == nil {
|
||||
errs[i] = errors.Wrap(fs.ErrorCantDirMove, su.Name()+":"+su.Root())
|
||||
errs[i] = fmt.Errorf("%s: %s: %w", su.Name(), su.Root(), fs.ErrorCantDirMove)
|
||||
return
|
||||
}
|
||||
err := du.Features().DirMove(ctx, su.Fs, srcRemote, dstRemote)
|
||||
errs[i] = errors.Wrap(err, du.Name()+":"+du.Root())
|
||||
errs[i] = fmt.Errorf("%s: %w", du.Name()+":"+du.Root(), err)
|
||||
})
|
||||
errs = errs.FilterNil()
|
||||
if len(errs) == 0 {
|
||||
return nil
|
||||
}
|
||||
for _, e := range errs {
|
||||
if errors.Cause(e) != fs.ErrorDirExists {
|
||||
if !errors.Is(e, fs.ErrorDirExists) {
|
||||
return errs
|
||||
}
|
||||
}
|
||||
@@ -477,7 +477,7 @@ func (f *Fs) put(ctx context.Context, in io.Reader, src fs.ObjectInfo, stream bo
|
||||
o, err = u.Put(ctx, readers[i], src, options...)
|
||||
}
|
||||
if err != nil {
|
||||
errs[i] = errors.Wrap(err, u.Name())
|
||||
errs[i] = fmt.Errorf("%s: %w", u.Name(), err)
|
||||
return
|
||||
}
|
||||
objs[i] = u.WrapObject(o)
|
||||
@@ -537,7 +537,7 @@ func (f *Fs) About(ctx context.Context) (*fs.Usage, error) {
|
||||
}
|
||||
for _, u := range f.upstreams {
|
||||
usg, err := u.About(ctx)
|
||||
if errors.Cause(err) == fs.ErrorDirNotFound {
|
||||
if errors.Is(err, fs.ErrorDirNotFound) {
|
||||
continue
|
||||
}
|
||||
if err != nil {
|
||||
@@ -593,7 +593,7 @@ func (f *Fs) List(ctx context.Context, dir string) (entries fs.DirEntries, err e
|
||||
u := f.upstreams[i]
|
||||
entries, err := u.List(ctx, dir)
|
||||
if err != nil {
|
||||
errs[i] = errors.Wrap(err, u.Name())
|
||||
errs[i] = fmt.Errorf("%s: %w", u.Name(), err)
|
||||
return
|
||||
}
|
||||
uEntries := make([]upstream.Entry, len(entries))
|
||||
@@ -604,7 +604,7 @@ func (f *Fs) List(ctx context.Context, dir string) (entries fs.DirEntries, err e
|
||||
})
|
||||
if len(errs) == len(errs.FilterNil()) {
|
||||
errs = errs.Map(func(e error) error {
|
||||
if errors.Cause(e) == fs.ErrorDirNotFound {
|
||||
if errors.Is(e, fs.ErrorDirNotFound) {
|
||||
return nil
|
||||
}
|
||||
return e
|
||||
@@ -657,13 +657,13 @@ func (f *Fs) ListR(ctx context.Context, dir string, callback fs.ListRCallback) (
|
||||
err = walk.ListR(ctx, u, dir, true, -1, walk.ListAll, callback)
|
||||
}
|
||||
if err != nil {
|
||||
errs[i] = errors.Wrap(err, u.Name())
|
||||
errs[i] = fmt.Errorf("%s: %w", u.Name(), err)
|
||||
return
|
||||
}
|
||||
})
|
||||
if len(errs) == len(errs.FilterNil()) {
|
||||
errs = errs.Map(func(e error) error {
|
||||
if errors.Cause(e) == fs.ErrorDirNotFound {
|
||||
if errors.Is(e, fs.ErrorDirNotFound) {
|
||||
return nil
|
||||
}
|
||||
return e
|
||||
@@ -688,7 +688,7 @@ func (f *Fs) NewObject(ctx context.Context, remote string) (fs.Object, error) {
|
||||
u := f.upstreams[i]
|
||||
o, err := u.NewObject(ctx, remote)
|
||||
if err != nil && err != fs.ErrorObjectNotFound {
|
||||
errs[i] = errors.Wrap(err, u.Name())
|
||||
errs[i] = fmt.Errorf("%s: %w", u.Name(), err)
|
||||
return
|
||||
}
|
||||
objs[i] = u.WrapObject(o)
|
||||
@@ -777,7 +777,7 @@ func (f *Fs) Shutdown(ctx context.Context) error {
|
||||
u := f.upstreams[i]
|
||||
if do := u.Features().Shutdown; do != nil {
|
||||
err := do(ctx)
|
||||
errs[i] = errors.Wrap(err, u.Name())
|
||||
errs[i] = fmt.Errorf("%s: %w", u.Name(), err)
|
||||
}
|
||||
})
|
||||
return errs.Err()
|
||||
|
||||
@@ -2,6 +2,8 @@ package upstream
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
"math"
|
||||
"path"
|
||||
@@ -11,7 +13,6 @@ import (
|
||||
"sync/atomic"
|
||||
"time"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
"github.com/rclone/rclone/fs"
|
||||
"github.com/rclone/rclone/fs/cache"
|
||||
"github.com/rclone/rclone/fs/fspath"
|
||||
@@ -133,7 +134,7 @@ func (f *Fs) WrapEntry(e fs.DirEntry) (Entry, error) {
|
||||
case fs.Directory:
|
||||
return f.WrapDirectory(e.(fs.Directory)), nil
|
||||
default:
|
||||
return nil, errors.Errorf("unknown object type %T", e)
|
||||
return nil, fmt.Errorf("unknown object type %T", e)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -335,7 +336,7 @@ func (f *Fs) updateUsageCore(lock bool) error {
|
||||
usage, err := f.RootFs.Features().About(ctx)
|
||||
if err != nil {
|
||||
f.cacheUpdate = false
|
||||
if errors.Cause(err) == fs.ErrorDirNotFound {
|
||||
if errors.Is(err, fs.ErrorDirNotFound) {
|
||||
err = nil
|
||||
}
|
||||
return err
|
||||
|
||||
Reference in New Issue
Block a user