From b8d7beb48cda151ca3a1def3d5d0882895a1d748 Mon Sep 17 00:00:00 2001 From: Christoph Polcin Date: Fri, 24 Oct 2014 12:40:49 +0200 Subject: [PATCH] Connect() will fail on non collection roots --- client.go | 13 +++++-------- main/client.go | 2 +- 2 files changed, 6 insertions(+), 9 deletions(-) diff --git a/client.go b/client.go index 8d6acc2..5944b69 100644 --- a/client.go +++ b/client.go @@ -3,7 +3,6 @@ package gowebdav import ( "encoding/base64" "encoding/xml" - "errors" "fmt" "net/http" "os" @@ -32,19 +31,17 @@ func NewClient(uri string, user string, pw string) *Client { } func (c *Client) Connect() error { - if rs, err := c.options("/"); err == nil { + rs, err := c.options("/") + if err == nil { defer rs.Body.Close() if rs.StatusCode != 200 || (rs.Header.Get("Dav") == "" && rs.Header.Get("DAV") == "") { - return errors.New(fmt.Sprintf("Bad Request: %d - %s", rs.StatusCode, c.root)) + return newPathError("Connect", c.root, rs.StatusCode) } - // TODO check PROPFIND if path is collection - - return nil - } else { - return err + _, err = c.ReadDir("/") } + return err } type props struct { diff --git a/main/client.go b/main/client.go index d65839c..a37da24 100644 --- a/main/client.go +++ b/main/client.go @@ -36,7 +36,7 @@ func main() { c := d.NewClient(*root, *usr, *pw) if err := c.Connect(); err != nil { - Fail(err) + Fail(fmt.Sprintf("Failed to connect due to: %s", err.Error())) } if len(flag.Args()) > 0 {