From 0b7f959433e2212f04e762de355a9daf0a2dcadc Mon Sep 17 00:00:00 2001 From: Nick Craig-Wood Date: Wed, 9 Oct 2019 22:28:07 +0100 Subject: [PATCH] cmount: when setting dates discard out of range dates It appears that sometimes Windows/WinFSP/cgofuse sends dates which are the epoch to rclone. These dates appear as 1601-01-01 00:00:00 plus or minus the timezone. These dates aren't being sent from rclone. This patch filters dates out before 1601-01-02 so rclone does not attempt to set them. See: https://forum.rclone.org/t/bug-corruption-of-modtime-via-vfs-layer/12204 See: https://forum.rclone.org/t/io-error-googleapi-error-403-insufficient-permission-insufficientpermissions/11372 See: https://github.com/billziss-gh/cgofuse/issues/35 --- cmd/cmount/fs.go | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/cmd/cmount/fs.go b/cmd/cmount/fs.go index 90c640b46..352e45d19 100644 --- a/cmd/cmount/fs.go +++ b/cmd/cmount/fs.go @@ -441,6 +441,11 @@ func (fsys *FS) Rename(oldPath string, newPath string) (errc int) { return translateError(fsys.VFS.Rename(oldPath, newPath)) } +// Windows sometimes seems to send times that are the epoch which is +// 1601-01-01 +/- timezone so filter out times that are earlier than +// this. +var invalidDateCutoff = time.Date(1601, 1, 2, 0, 0, 0, 0, time.UTC) + // Utimens changes the access and modification times of a file. func (fsys *FS) Utimens(path string, tmsp []fuse.Timespec) (errc int) { defer log.Trace(path, "tmsp=%+v", tmsp)("errc=%d", &errc) @@ -448,12 +453,16 @@ func (fsys *FS) Utimens(path string, tmsp []fuse.Timespec) (errc int) { if errc != 0 { return errc } - var t time.Time if tmsp == nil || len(tmsp) < 2 { - t = time.Now() - } else { - t = tmsp[1].Time() + fs.Debugf(path, "Utimens: Not setting time as timespec isn't complete: %v", tmsp) + return 0 } + t := tmsp[1].Time() + if t.Before(invalidDateCutoff) { + fs.Debugf(path, "Utimens: Not setting out of range time: %v", t) + return 0 + } + fs.Debugf(path, "Utimens: SetModTime: %v", t) return translateError(node.SetModTime(t)) }