mirror of
https://github.com/rclone/rclone.git
synced 2024-12-22 15:11:56 +01:00
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
This commit is contained in:
parent
61d6f538b3
commit
8e2dc069d2
@ -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
|
||||
|
@ -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 {
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user