Skip to content

Commit 8eb9f01

Browse files
committed
Merge branch 'master' of github.com:rclone/rclone into feature/storj
2 parents f97139e + e14d968 commit 8eb9f01

File tree

539 files changed

+23692
-8525
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

539 files changed

+23692
-8525
lines changed

VERSION

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
v1.50.1
1+
v1.50.2

backend/cache/storage_persistent.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import (
1616
"sync"
1717
"time"
1818

19-
bolt "github.com/coreos/bbolt"
19+
bolt "github.com/etcd-io/bbolt"
2020
"github.com/pkg/errors"
2121
"github.com/rclone/rclone/fs"
2222
"github.com/rclone/rclone/fs/walk"

backend/drive/drive.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -1021,11 +1021,11 @@ func NewFs(name, path string, m configmap.Mapper) (fs.Fs, error) {
10211021
}
10221022

10231023
// set root folder for a team drive or query the user root folder
1024-
if f.isTeamDrive {
1025-
f.rootFolderID = f.opt.TeamDriveID
1026-
} else if opt.RootFolderID != "" {
1024+
if opt.RootFolderID != "" {
10271025
// override root folder if set or cached in the config
10281026
f.rootFolderID = opt.RootFolderID
1027+
} else if f.isTeamDrive {
1028+
f.rootFolderID = f.opt.TeamDriveID
10291029
} else {
10301030
// Look up the root ID and cache it in the config
10311031
rootID, err := f.getRootID()

backend/koofr/koofr.go

+4-1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import (
1616
"github.com/rclone/rclone/fs/config/configstruct"
1717
"github.com/rclone/rclone/fs/config/obscure"
1818
"github.com/rclone/rclone/fs/encodings"
19+
"github.com/rclone/rclone/fs/fshttp"
1920
"github.com/rclone/rclone/fs/hash"
2021

2122
httpclient "github.com/koofr/go-httpclient"
@@ -259,7 +260,9 @@ func NewFs(name, root string, m configmap.Mapper) (ff fs.Fs, err error) {
259260
if err != nil {
260261
return nil, err
261262
}
262-
client := koofrclient.NewKoofrClient(opt.Endpoint, false)
263+
httpClient := httpclient.New()
264+
httpClient.Client = fshttp.NewClient(fs.Config)
265+
client := koofrclient.NewKoofrClientWithHTTPClient(opt.Endpoint, httpClient)
263266
basicAuth := fmt.Sprintf("Basic %s",
264267
base64.StdEncoding.EncodeToString([]byte(opt.User+":"+pass)))
265268
client.HTTPClient.Headers.Set("Authorization", basicAuth)

backend/local/local.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -350,7 +350,7 @@ func (f *Fs) List(ctx context.Context, dir string) (entries fs.DirEntries, err e
350350
err = errors.Wrapf(err, "failed to open directory %q", dir)
351351
fs.Errorf(dir, "%v", err)
352352
if isPerm {
353-
accounting.Stats(ctx).Error(fserrors.NoRetryError(err))
353+
_ = accounting.Stats(ctx).Error(fserrors.NoRetryError(err))
354354
err = nil // ignore error but fail sync
355355
}
356356
return nil, err
@@ -386,7 +386,7 @@ func (f *Fs) List(ctx context.Context, dir string) (entries fs.DirEntries, err e
386386
if fierr != nil {
387387
err = errors.Wrapf(err, "failed to read directory %q", namepath)
388388
fs.Errorf(dir, "%v", fierr)
389-
accounting.Stats(ctx).Error(fserrors.NoRetryError(fierr)) // fail the sync
389+
_ = accounting.Stats(ctx).Error(fserrors.NoRetryError(fierr)) // fail the sync
390390
continue
391391
}
392392
fis = append(fis, fi)
@@ -409,7 +409,7 @@ func (f *Fs) List(ctx context.Context, dir string) (entries fs.DirEntries, err e
409409
// Skip bad symlinks
410410
err = fserrors.NoRetryError(errors.Wrap(err, "symlink"))
411411
fs.Errorf(newRemote, "Listing error: %v", err)
412-
accounting.Stats(ctx).Error(err)
412+
err = accounting.Stats(ctx).Error(err)
413413
continue
414414
}
415415
if err != nil {

backend/qingstor/qingstor.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,7 @@ func qsServiceConnection(opt *Options) (*qs.Service, error) {
269269
cf.Protocol = protocol
270270
cf.Host = host
271271
cf.Port = port
272-
cf.ConnectionRetries = opt.ConnectionRetries
272+
// unsupported in v3.1: cf.ConnectionRetries = opt.ConnectionRetries
273273
cf.Connection = fshttp.NewClient(fs.Config)
274274

275275
return qs.Init(cf)

backend/sftp/sftp.go

+14-9
Original file line numberDiff line numberDiff line change
@@ -29,15 +29,17 @@ import (
2929
"github.com/rclone/rclone/fs/fshttp"
3030
"github.com/rclone/rclone/fs/hash"
3131
"github.com/rclone/rclone/lib/env"
32+
"github.com/rclone/rclone/lib/pacer"
3233
"github.com/rclone/rclone/lib/readers"
3334
sshagent "github.com/xanzy/ssh-agent"
3435
"golang.org/x/crypto/ssh"
35-
"golang.org/x/time/rate"
3636
)
3737

3838
const (
39-
connectionsPerSecond = 10 // don't make more than this many ssh connections/s
4039
hashCommandNotSupported = "none"
40+
minSleep = 100 * time.Millisecond
41+
maxSleep = 2 * time.Second
42+
decayConstant = 2 // bigger for slower decay, exponential
4143
)
4244

4345
var (
@@ -190,7 +192,7 @@ type Fs struct {
190192
cachedHashes *hash.Set
191193
poolMu sync.Mutex
192194
pool []*conn
193-
connLimit *rate.Limiter // for limiting number of connections per second
195+
pacer *fs.Pacer // pacer for operations
194196
}
195197

196198
// Object is a remote SFTP file that has been stat'd (so it exists, but is not necessarily open for reading)
@@ -270,10 +272,6 @@ func (c *conn) closed() error {
270272
// Open a new connection to the SFTP server.
271273
func (f *Fs) sftpConnection() (c *conn, err error) {
272274
// Rate limit rate of new connections
273-
err = f.connLimit.Wait(context.Background())
274-
if err != nil {
275-
return nil, errors.Wrap(err, "limiter failed in connect")
276-
}
277275
c = &conn{
278276
err: make(chan error, 1),
279277
}
@@ -307,7 +305,14 @@ func (f *Fs) getSftpConnection() (c *conn, err error) {
307305
if c != nil {
308306
return c, nil
309307
}
310-
return f.sftpConnection()
308+
err = f.pacer.Call(func() (bool, error) {
309+
c, err = f.sftpConnection()
310+
if err != nil {
311+
return true, err
312+
}
313+
return false, nil
314+
})
315+
return c, err
311316
}
312317

313318
// Return an SFTP connection to the pool
@@ -465,7 +470,7 @@ func NewFsWithConnection(ctx context.Context, name string, root string, m config
465470
config: sshConfig,
466471
url: "sftp://" + opt.User + "@" + opt.Host + ":" + opt.Port + "/" + root,
467472
mkdirLock: newStringLock(),
468-
connLimit: rate.NewLimiter(rate.Limit(connectionsPerSecond), 1),
473+
pacer: fs.NewPacer(pacer.NewDefault(pacer.MinSleep(minSleep), pacer.MaxSleep(maxSleep), pacer.DecayConstant(decayConstant))),
469474
}
470475
f.features = (&fs.Features{
471476
CanHaveEmptyDirectories: true,

backend/swift/swift.go

+42-11
Original file line numberDiff line numberDiff line change
@@ -530,10 +530,10 @@ type listFn func(remote string, object *swift.Object, isDirectory bool) error
530530
//
531531
// Set recurse to read sub directories
532532
func (f *Fs) listContainerRoot(container, directory, prefix string, addContainer bool, recurse bool, fn listFn) error {
533-
if prefix != "" {
533+
if prefix != "" && !strings.HasSuffix(prefix, "/") {
534534
prefix += "/"
535535
}
536-
if directory != "" {
536+
if directory != "" && !strings.HasSuffix(directory, "/") {
537537
directory += "/"
538538
}
539539
// Options for ObjectsWalk
@@ -952,6 +952,18 @@ func (o *Object) isStaticLargeObject() (bool, error) {
952952
return o.hasHeader("X-Static-Large-Object")
953953
}
954954

955+
func (o *Object) isInContainerVersioning() (bool, error) {
956+
_, headers, err := o.fs.c.Container(o.fs.root)
957+
if err != nil {
958+
return false, err
959+
}
960+
xHistoryLocation := headers["X-History-Location"]
961+
if len(xHistoryLocation) > 0 {
962+
return true, nil
963+
}
964+
return false, nil
965+
}
966+
955967
// Size returns the size of an object in bytes
956968
func (o *Object) Size() int64 {
957969
return o.size
@@ -1083,9 +1095,8 @@ func min(x, y int64) int64 {
10831095
//
10841096
// if except is passed in then segments with that prefix won't be deleted
10851097
func (o *Object) removeSegments(except string) error {
1086-
container, containerPath := o.split()
1087-
segmentsContainer := container + "_segments"
1088-
err := o.fs.listContainerRoot(segmentsContainer, containerPath, "", false, true, func(remote string, object *swift.Object, isDirectory bool) error {
1098+
segmentsContainer, prefix, err := o.getSegmentsDlo()
1099+
err = o.fs.listContainerRoot(segmentsContainer, prefix, "", false, true, func(remote string, object *swift.Object, isDirectory bool) error {
10891100
if isDirectory {
10901101
return nil
10911102
}
@@ -1114,6 +1125,19 @@ func (o *Object) removeSegments(except string) error {
11141125
return nil
11151126
}
11161127

1128+
func (o *Object) getSegmentsDlo() (segmentsContainer string, prefix string, err error) {
1129+
if err = o.readMetaData(); err != nil {
1130+
return
1131+
}
1132+
dirManifest := o.headers["X-Object-Manifest"]
1133+
delimiter := strings.Index(dirManifest, "/")
1134+
if len(dirManifest) == 0 || delimiter < 0 {
1135+
err = errors.New("Missing or wrong structure of manifest of Dynamic large object")
1136+
return
1137+
}
1138+
return dirManifest[:delimiter], dirManifest[delimiter+1:], nil
1139+
}
1140+
11171141
// urlEncode encodes a string so that it is a valid URL
11181142
//
11191143
// We don't use any of Go's standard methods as we need `/` not
@@ -1300,12 +1324,9 @@ func (o *Object) Update(ctx context.Context, in io.Reader, src fs.ObjectInfo, op
13001324
}
13011325

13021326
// Remove an object
1303-
func (o *Object) Remove(ctx context.Context) error {
1327+
func (o *Object) Remove(ctx context.Context) (err error) {
13041328
container, containerPath := o.split()
1305-
isDynamicLargeObject, err := o.isDynamicLargeObject()
1306-
if err != nil {
1307-
return err
1308-
}
1329+
13091330
// Remove file/manifest first
13101331
err = o.fs.pacer.Call(func() (bool, error) {
13111332
err = o.fs.c.ObjectDelete(container, containerPath)
@@ -1314,12 +1335,22 @@ func (o *Object) Remove(ctx context.Context) error {
13141335
if err != nil {
13151336
return err
13161337
}
1338+
isDynamicLargeObject, err := o.isDynamicLargeObject()
1339+
if err != nil {
1340+
return err
1341+
}
13171342
// ...then segments if required
13181343
if isDynamicLargeObject {
1319-
err = o.removeSegments("")
1344+
isInContainerVersioning, err := o.isInContainerVersioning()
13201345
if err != nil {
13211346
return err
13221347
}
1348+
if !isInContainerVersioning {
1349+
err = o.removeSegments("")
1350+
if err != nil {
1351+
return err
1352+
}
1353+
}
13231354
}
13241355
return nil
13251356
}

cmd/cmd.go

+13-13
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ func ShowVersion() {
8282
func NewFsFile(remote string) (fs.Fs, string) {
8383
_, _, fsPath, err := fs.ParseRemote(remote)
8484
if err != nil {
85-
fs.CountError(err)
85+
err = fs.CountError(err)
8686
log.Fatalf("Failed to create file system for %q: %v", remote, err)
8787
}
8888
f, err := cache.Get(remote)
@@ -92,7 +92,7 @@ func NewFsFile(remote string) (fs.Fs, string) {
9292
case nil:
9393
return f, ""
9494
default:
95-
fs.CountError(err)
95+
err = fs.CountError(err)
9696
log.Fatalf("Failed to create file system for %q: %v", remote, err)
9797
}
9898
return nil, ""
@@ -107,13 +107,13 @@ func newFsFileAddFilter(remote string) (fs.Fs, string) {
107107
if fileName != "" {
108108
if !filter.Active.InActive() {
109109
err := errors.Errorf("Can't limit to single files when using filters: %v", remote)
110-
fs.CountError(err)
110+
err = fs.CountError(err)
111111
log.Fatalf(err.Error())
112112
}
113113
// Limit transfers to this file
114114
err := filter.Active.AddFile(fileName)
115115
if err != nil {
116-
fs.CountError(err)
116+
err = fs.CountError(err)
117117
log.Fatalf("Failed to limit to single file %q: %v", remote, err)
118118
}
119119
}
@@ -135,7 +135,7 @@ func NewFsSrc(args []string) fs.Fs {
135135
func newFsDir(remote string) fs.Fs {
136136
f, err := cache.Get(remote)
137137
if err != nil {
138-
fs.CountError(err)
138+
err = fs.CountError(err)
139139
log.Fatalf("Failed to create file system for %q: %v", remote, err)
140140
}
141141
return f
@@ -189,11 +189,11 @@ func NewFsSrcDstFiles(args []string) (fsrc fs.Fs, srcFileName string, fdst fs.Fs
189189
fdst, err := cache.Get(dstRemote)
190190
switch err {
191191
case fs.ErrorIsFile:
192-
fs.CountError(err)
192+
_ = fs.CountError(err)
193193
log.Fatalf("Source doesn't exist or is a directory and destination is a file")
194194
case nil:
195195
default:
196-
fs.CountError(err)
196+
_ = fs.CountError(err)
197197
log.Fatalf("Failed to create file system for destination %q: %v", dstRemote, err)
198198
}
199199
return
@@ -239,7 +239,7 @@ func Run(Retry bool, showStats bool, cmd *cobra.Command, f func() error) {
239239
SigInfoHandler()
240240
for try := 1; try <= *retries; try++ {
241241
err = f()
242-
fs.CountError(err)
242+
err = fs.CountError(err)
243243
lastErr := accounting.GlobalStats().GetLastError()
244244
if err == nil {
245245
err = lastErr
@@ -386,12 +386,12 @@ func initConfig() {
386386
fs.Infof(nil, "Creating CPU profile %q\n", *cpuProfile)
387387
f, err := os.Create(*cpuProfile)
388388
if err != nil {
389-
fs.CountError(err)
389+
err = fs.CountError(err)
390390
log.Fatal(err)
391391
}
392392
err = pprof.StartCPUProfile(f)
393393
if err != nil {
394-
fs.CountError(err)
394+
err = fs.CountError(err)
395395
log.Fatal(err)
396396
}
397397
atexit.Register(func() {
@@ -405,17 +405,17 @@ func initConfig() {
405405
fs.Infof(nil, "Saving Memory profile %q\n", *memProfile)
406406
f, err := os.Create(*memProfile)
407407
if err != nil {
408-
fs.CountError(err)
408+
err = fs.CountError(err)
409409
log.Fatal(err)
410410
}
411411
err = pprof.WriteHeapProfile(f)
412412
if err != nil {
413-
fs.CountError(err)
413+
err = fs.CountError(err)
414414
log.Fatal(err)
415415
}
416416
err = f.Close()
417417
if err != nil {
418-
fs.CountError(err)
418+
err = fs.CountError(err)
419419
log.Fatal(err)
420420
}
421421
})

cmd/cryptcheck/cryptcheck.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ func cryptCheck(ctx context.Context, fdst, fsrc fs.Fs) error {
8888
underlyingDst := cryptDst.UnWrap()
8989
underlyingHash, err := underlyingDst.Hash(ctx, hashType)
9090
if err != nil {
91-
fs.CountError(err)
91+
err = fs.CountError(err)
9292
fs.Errorf(dst, "Error reading hash from underlying %v: %v", underlyingDst, err)
9393
return true, false
9494
}
@@ -97,7 +97,7 @@ func cryptCheck(ctx context.Context, fdst, fsrc fs.Fs) error {
9797
}
9898
cryptHash, err := fcrypt.ComputeHash(ctx, cryptDst, src, hashType)
9999
if err != nil {
100-
fs.CountError(err)
100+
err = fs.CountError(err)
101101
fs.Errorf(dst, "Error computing hash: %v", err)
102102
return true, false
103103
}
@@ -106,7 +106,7 @@ func cryptCheck(ctx context.Context, fdst, fsrc fs.Fs) error {
106106
}
107107
if cryptHash != underlyingHash {
108108
err = errors.Errorf("hashes differ (%s:%s) %q vs (%s:%s) %q", fdst.Name(), fdst.Root(), cryptHash, fsrc.Name(), fsrc.Root(), underlyingHash)
109-
fs.CountError(err)
109+
err = fs.CountError(err)
110110
fs.Errorf(src, err.Error())
111111
return true, false
112112
}

cmd/serve/dlna/dlna_util.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ func withHeader(name string, value string, next http.Handler) http.Handler {
214214

215215
// serveError returns an http.StatusInternalServerError and logs the error
216216
func serveError(what interface{}, w http.ResponseWriter, text string, err error) {
217-
fs.CountError(err)
217+
err = fs.CountError(err)
218218
fs.Errorf(what, "%s: %v", text, err)
219219
http.Error(w, text+".", http.StatusInternalServerError)
220220
}

cmd/serve/httplib/serve/dir.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ func (d *Directory) AddEntry(remote string, isDir bool) {
6868

6969
// Error logs the error and if a ResponseWriter is given it writes a http.StatusInternalServerError
7070
func Error(what interface{}, w http.ResponseWriter, text string, err error) {
71-
fs.CountError(err)
71+
err = fs.CountError(err)
7272
fs.Errorf(what, "%s: %v", text, err)
7373
if w != nil {
7474
http.Error(w, text+".", http.StatusInternalServerError)

0 commit comments

Comments
 (0)