Skip to content

Commit 0ccf650

Browse files
committed
touch: make touch obey --transfers
Before this change, when executed on a directory, rclone would only touch files sequentially. This change makes rclone touch --transfers files at once. Fixes rclone#8402
1 parent 85d467e commit 0ccf650

File tree

2 files changed

+17
-8
lines changed

2 files changed

+17
-8
lines changed

cmd/touch/touch.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ unless ` + "`--no-create`" + ` or ` + "`--recursive`" + ` is provided.
5151
If ` + "`--recursive`" + ` is used then recursively sets the modification
5252
time on all existing files that is found under the path. Filters are supported,
5353
and you can test with the ` + "`--dry-run`" + ` or the ` + "`--interactive`/`-i`" + ` flag.
54+
This will touch ` + "`--transfers`" + ` files concurrently.
5455
5556
If ` + "`--timestamp`" + ` is used then sets the modification time to that
5657
time instead of the current time. Times may be specified as one of:

fs/operations/operations.go

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2140,20 +2140,28 @@ func SetTierFile(ctx context.Context, o fs.Object, tier string) error {
21402140

21412141
// TouchDir touches every file in directory with time t
21422142
func TouchDir(ctx context.Context, f fs.Fs, remote string, t time.Time, recursive bool) error {
2143-
return walk.ListR(ctx, f, remote, false, ConfigMaxDepth(ctx, recursive), walk.ListObjects, func(entries fs.DirEntries) error {
2143+
ci := fs.GetConfig(ctx)
2144+
g, gCtx := errgroup.WithContext(ctx)
2145+
g.SetLimit(ci.Transfers)
2146+
err := walk.ListR(ctx, f, remote, false, ConfigMaxDepth(ctx, recursive), walk.ListObjects, func(entries fs.DirEntries) error {
21442147
entries.ForObject(func(o fs.Object) {
21452148
if !SkipDestructive(ctx, o, "touch") {
2146-
fs.Debugf(f, "Touching %q", o.Remote())
2147-
err := o.SetModTime(ctx, t)
2148-
if err != nil {
2149-
err = fmt.Errorf("failed to touch: %w", err)
2150-
err = fs.CountError(ctx, err)
2151-
fs.Errorf(o, "%v", err)
2152-
}
2149+
g.Go(func() error {
2150+
fs.Debugf(f, "Touching %q", o.Remote())
2151+
err := o.SetModTime(gCtx, t)
2152+
if err != nil {
2153+
err = fmt.Errorf("failed to touch: %w", err)
2154+
err = fs.CountError(gCtx, err)
2155+
fs.Errorf(o, "%v", err)
2156+
}
2157+
return nil
2158+
})
21532159
}
21542160
})
21552161
return nil
21562162
})
2163+
_ = g.Wait()
2164+
return err
21572165
}
21582166

21592167
// ListFormat defines files information print format

0 commit comments

Comments
 (0)