From 8e2dc069d2e493871256cdabf55c0319ff02ac99 Mon Sep 17 00:00:00 2001 From: Nick Craig-Wood Date: Wed, 3 May 2023 10:39:42 +0100 Subject: [PATCH] fs: Add --default-time flag to control unknown modtime of files/dirs Before this patch, files or directories with unknown modtime would appear as the current date. When mounted some systems look at modification dates of directories to see if they change and having them change whenever they drop out of the directory cache is not optimal. See #6986 --- docs/content/docs.md | 12 ++++++++++++ fs/config.go | 2 ++ fs/config/configflags/configflags.go | 1 + fs/dir.go | 8 ++++++-- 4 files changed, 21 insertions(+), 2 deletions(-) diff --git a/docs/content/docs.md b/docs/content/docs.md index 941c9c842..22e8c8c93 100644 --- a/docs/content/docs.md +++ b/docs/content/docs.md @@ -992,6 +992,18 @@ Mode to run dedupe command in. One of `interactive`, `skip`, `first`, `newest`, `oldest`, `rename`. The default is `interactive`. See the dedupe command for more information as to what these options mean. +### --default-time TIME ### + +If a file or directory does have a modification time rclone can read +then rclone will display this fixed time instead. + +The default is `2000-01-01 00:00:00 UTC`. This can be configured in +any of the ways shown in [the time or duration options](#time-option). + +For example `--default-time 2020-06-01` to set the default time to the +1st of June 2020 or `--default-time 0s` to set the default time to the +time rclone started up. + ### --disable FEATURE,FEATURE,... ### This disables a comma separated list of optional features. For example diff --git a/fs/config.go b/fs/config.go index 4049b6ea4..d243d794a 100644 --- a/fs/config.go +++ b/fs/config.go @@ -144,6 +144,7 @@ type ConfigInfo struct { Metadata bool ServerSideAcrossConfigs bool TerminalColorMode TerminalColorMode + DefaultTime Time // time that directories with no time should display } // NewConfig creates a new config with everything set to the default @@ -185,6 +186,7 @@ func NewConfig() *ConfigInfo { c.FsCacheExpireDuration = 300 * time.Second c.FsCacheExpireInterval = 60 * time.Second c.KvLockTime = 1 * time.Second + c.DefaultTime = Time(time.Date(2000, 1, 1, 0, 0, 0, 0, time.UTC)) // Perform a simple check for debug flags to enable debug logging during the flag initialization for argIndex, arg := range os.Args { diff --git a/fs/config/configflags/configflags.go b/fs/config/configflags/configflags.go index 96d728fcc..63f107fd0 100644 --- a/fs/config/configflags/configflags.go +++ b/fs/config/configflags/configflags.go @@ -144,6 +144,7 @@ func AddFlags(ci *fs.ConfigInfo, flagSet *pflag.FlagSet) { flags.BoolVarP(flagSet, &ci.Metadata, "metadata", "M", ci.Metadata, "If set, preserve metadata when copying objects") flags.BoolVarP(flagSet, &ci.ServerSideAcrossConfigs, "server-side-across-configs", "", ci.ServerSideAcrossConfigs, "Allow server-side operations (e.g. copy) to work across different configs") flags.FVarP(flagSet, &ci.TerminalColorMode, "color", "", "When to show colors (and other ANSI codes) AUTO|NEVER|ALWAYS") + flags.FVarP(flagSet, &ci.DefaultTime, "default-time", "", "Time to show if modtime is unknown for files and directories") } // ParseHeaders converts the strings passed in via the header flags into HTTPOptions diff --git a/fs/dir.go b/fs/dir.go index 63c51a310..c55bcea23 100644 --- a/fs/dir.go +++ b/fs/dir.go @@ -16,6 +16,8 @@ type Dir struct { } // NewDir creates an unspecialized Directory object +// +// If the modTime is unknown pass in time.Time{} func NewDir(remote string, modTime time.Time) *Dir { return &Dir{ remote: remote, @@ -75,12 +77,14 @@ func (d *Dir) SetParentID(parent string) *Dir { } // ModTime returns the modification date of the file -// It should return a best guess if one isn't available +// +// If one isn't available it returns the configured --default-dir-time func (d *Dir) ModTime(ctx context.Context) time.Time { if !d.modTime.IsZero() { return d.modTime } - return time.Now() + ci := GetConfig(ctx) + return time.Time(ci.DefaultTime) } // Size returns the size of the file