diff --git a/backend/webdav/api/types.go b/backend/webdav/api/types.go index b0d2a57d5..991bcc827 100644 --- a/backend/webdav/api/types.go +++ b/backend/webdav/api/types.go @@ -209,3 +209,22 @@ func (t *Time) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error { } return err } + +// Quota is used to read the bytes used and available +// +// +// +// /remote.php/webdav/ +// +// +// -3 +// 376461895 +// +// HTTP/1.1 200 OK +// +// +// +type Quota struct { + Available int64 `xml:"DAV: response>propstat>prop>quota-available-bytes"` + Used int64 `xml:"DAV: response>propstat>prop>quota-used-bytes"` +} diff --git a/backend/webdav/webdav.go b/backend/webdav/webdav.go index d2cd9facc..5cb257501 100644 --- a/backend/webdav/webdav.go +++ b/backend/webdav/webdav.go @@ -869,6 +869,46 @@ func (f *Fs) Hashes() hash.Set { return hash.Set(hash.None) } +// About gets quota information +func (f *Fs) About() (*fs.Usage, error) { + opts := rest.Opts{ + Method: "PROPFIND", + Path: "", + ExtraHeaders: map[string]string{ + "Depth": "0", + }, + } + opts.Body = bytes.NewBuffer([]byte(` + + + + + + +`)) + var q = api.Quota{ + Available: -1, + Used: -1, + } + var resp *http.Response + var err error + err = f.pacer.Call(func() (bool, error) { + resp, err = f.srv.CallXML(&opts, nil, &q) + return shouldRetry(resp, err) + }) + if err != nil { + return nil, errors.Wrap(err, "about call failed") + } + usage := &fs.Usage{} + if q.Available >= 0 && q.Used >= 0 { + usage.Total = fs.NewUsageValue(q.Available + q.Used) + } + if q.Used >= 0 { + usage.Used = fs.NewUsageValue(q.Used) + } + return usage, nil +} + // ------------------------------------------------------------ // Fs returns the parent Fs @@ -1059,5 +1099,6 @@ var ( _ fs.Copier = (*Fs)(nil) _ fs.Mover = (*Fs)(nil) _ fs.DirMover = (*Fs)(nil) + _ fs.Abouter = (*Fs)(nil) _ fs.Object = (*Object)(nil) ) diff --git a/docs/content/overview.md b/docs/content/overview.md index 20ee72c88..f6255634e 100644 --- a/docs/content/overview.md +++ b/docs/content/overview.md @@ -149,7 +149,7 @@ operations more efficient. | pCloud | Yes | Yes | Yes | Yes | Yes | No | No | No [#2178](https://github.com/ncw/rclone/issues/2178) | Yes | | QingStor | No | Yes | No | No | No | Yes | No | No [#2178](https://github.com/ncw/rclone/issues/2178) | No | | SFTP | No | No | Yes | Yes | No | No | Yes | No [#2178](https://github.com/ncw/rclone/issues/2178) | No | -| WebDAV | Yes | Yes | Yes | Yes | No | No | Yes ‡ | No [#2178](https://github.com/ncw/rclone/issues/2178) | No | +| WebDAV | Yes | Yes | Yes | Yes | No | No | Yes ‡ | No [#2178](https://github.com/ncw/rclone/issues/2178) | Yes | | Yandex Disk | Yes | Yes | Yes | Yes | Yes | No | Yes | Yes | Yes | | The local filesystem | Yes | No | Yes | Yes | No | No | Yes | No | Yes | @@ -220,5 +220,7 @@ on the particular cloud provider. This is used to fetch quota information from the remote, like bytes used/free/quota and bytes used in the trash. +This is also used to return the space used, available for `rclone mount`. + If the server can't do `About` then `rclone about` will return an error.