From 4ba58884b1eaa739a5b51c98bd080345a8ff0fae Mon Sep 17 00:00:00 2001 From: Nick Craig-Wood Date: Wed, 20 Dec 2017 11:49:42 +0000 Subject: [PATCH] webdav: decode multiple more carefully - fixes nextcloud 12.0.4 For some reason nextcloud sends multiple propstat responses now, one with a 404 status. rclone was interpreting the last status and assuming the file was missing. --- webdav/api/types.go | 40 ++++++++++++++++++++++++++++++++++++++-- 1 file changed, 38 insertions(+), 2 deletions(-) diff --git a/webdav/api/types.go b/webdav/api/types.go index c856a3007..d7a69b273 100644 --- a/webdav/api/types.go +++ b/webdav/api/types.go @@ -25,8 +25,40 @@ type Response struct { } // Prop is the properties of a response +// +// This is a lazy way of decoding the multiple in the +// response. +// +// The response might look like this +// +// +// /remote.php/webdav/Nextcloud%20Manual.pdf +// +// +// Tue, 19 Dec 2017 22:02:36 GMT +// 4143665 +// +// "048d7be4437ff7deeae94db50ff3e209" +// application/pdf +// +// HTTP/1.1 200 OK +// +// +// +// +// +// +// HTTP/1.1 404 Not Found +// +// +// +// So we elide the array of and within that the array of +// into one struct. +// +// Note that status collects all the status values for which we just +// check the first is OK. type Prop struct { - Status string `xml:"DAV: status"` + Status []string `xml:"DAV: status"` Name string `xml:"DAV: prop>displayname,omitempty"` Type *xml.Name `xml:"DAV: prop>resourcetype>collection,omitempty"` Size int64 `xml:"DAV: prop>getcontentlength,omitempty"` @@ -38,7 +70,11 @@ var parseStatus = regexp.MustCompile(`^HTTP/[0-9.]+\s+(\d+)\s+(.*)$`) // StatusOK examines the Status and returns an OK flag func (p *Prop) StatusOK() bool { - match := parseStatus.FindStringSubmatch(p.Status) + // Assume OK if no statuses received + if len(p.Status) == 0 { + return true + } + match := parseStatus.FindStringSubmatch(p.Status[0]) if len(match) < 3 { return false }