1
0
mirror of https://github.com/rclone/rclone.git synced 2025-12-06 00:03:32 +00:00

touch: add support for touching files in directory, with options for recursive, filtering and dry-run/interactive

Fixes #5301
This commit is contained in:
albertony
2021-05-22 21:06:24 +02:00
parent 2e72ec96c1
commit 41876dd669
4 changed files with 132 additions and 48 deletions

View File

@@ -1906,6 +1906,23 @@ func SetTier(ctx context.Context, fsrc fs.Fs, tier string) error {
})
}
// TouchDir touches every file in f with time t
func TouchDir(ctx context.Context, f fs.Fs, t time.Time, recursive bool) error {
return walk.ListR(ctx, f, "", false, ConfigMaxDepth(ctx, recursive), walk.ListObjects, func(entries fs.DirEntries) error {
entries.ForObject(func(o fs.Object) {
if !SkipDestructive(ctx, o, "touch") {
fs.Debugf(f, "Touching %q", o.Remote())
err := o.SetModTime(ctx, t)
if err != nil {
err = fs.CountError(err)
fs.Errorf(o, "Failed to touch %v", err)
}
}
})
return nil
})
}
// ListFormat defines files information print format
type ListFormat struct {
separator string