From df1faa9a8ff2e49c96f8d129fc63371f16a0dcdd Mon Sep 17 00:00:00 2001 From: Nick Craig-Wood Date: Fri, 30 Nov 2018 10:44:24 +0000 Subject: [PATCH] webdav: fail soft on time parsing errors The time format provided by webdav servers seems to vary wildly from that specified in the RFC - rclone already parses times in 5 different formats! If an unparseable time is found, then fail softly logging an ERROR (just once) but returning the epoch. This will mean that webdav servers with bad time formats will still be usable by rclone. --- backend/webdav/api/types.go | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/backend/webdav/api/types.go b/backend/webdav/api/types.go index 8de22fb41..4d248ac36 100644 --- a/backend/webdav/api/types.go +++ b/backend/webdav/api/types.go @@ -6,7 +6,10 @@ import ( "regexp" "strconv" "strings" + "sync" "time" + + "github.com/ncw/rclone/fs" ) const ( @@ -148,6 +151,8 @@ var timeFormats = []string{ time.RFC3339, // Wed, 31 Oct 2018 13:57:11 CET (as used by komfortcloud.de) } +var oneTimeError sync.Once + // UnmarshalXML turns XML into a Time func (t *Time) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error { var v string @@ -171,5 +176,14 @@ func (t *Time) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error { break } } + if err != nil { + oneTimeError.Do(func() { + fs.Errorf(nil, "Failed to parse time %q - using the epoch", v) + }) + // Return the epoch instead + *t = Time(time.Unix(0, 0)) + // ignore error + err = nil + } return err }