Compare commits
13 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
f60c73fbb4 | ||
|
|
a11466bd13 | ||
|
|
e3cd1f98e7 | ||
|
|
e3a31466a7 | ||
|
|
2b5dab74d3 | ||
|
|
79a29f3ad5 | ||
|
|
a03a0a3645 | ||
|
|
12fe295146 | ||
|
|
8f99657223 | ||
|
|
b12f1c1b33 | ||
|
|
33816041d6 | ||
|
|
31c3cc07c7 | ||
|
|
87bbafc0c0 |
28
client.go
28
client.go
@@ -6,7 +6,9 @@ import (
|
|||||||
"encoding/xml"
|
"encoding/xml"
|
||||||
"io"
|
"io"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"net/url"
|
||||||
"os"
|
"os"
|
||||||
|
pathpkg "path"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
@@ -31,6 +33,14 @@ func NewClient(uri string, user string, pw string) *Client {
|
|||||||
return c
|
return c
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (c *Client) SetHeader(key, value string) {
|
||||||
|
c.headers.Add(key, value)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *Client) SetTransport(transport http.RoundTripper) {
|
||||||
|
c.c.Transport = transport
|
||||||
|
}
|
||||||
|
|
||||||
func (c *Client) Connect() error {
|
func (c *Client) Connect() error {
|
||||||
rs, err := c.options("/")
|
rs, err := c.options("/")
|
||||||
if err == nil {
|
if err == nil {
|
||||||
@@ -84,17 +94,20 @@ func (c *Client) ReadDir(path string) ([]os.FileInfo, error) {
|
|||||||
|
|
||||||
if p := getProps(r, "200"); p != nil {
|
if p := getProps(r, "200"); p != nil {
|
||||||
f := new(File)
|
f := new(File)
|
||||||
f.name = p.Name
|
if ps, err := url.QueryUnescape(r.Href); err == nil {
|
||||||
|
f.name = pathpkg.Base(ps)
|
||||||
|
} else {
|
||||||
|
f.name = p.Name
|
||||||
|
}
|
||||||
f.path = path + f.name
|
f.path = path + f.name
|
||||||
|
f.modified = parseModified(&p.Modified)
|
||||||
|
|
||||||
if p.Type.Local == "collection" {
|
if p.Type.Local == "collection" {
|
||||||
f.path += "/"
|
f.path += "/"
|
||||||
f.size = 0
|
f.size = 0
|
||||||
f.modified = time.Unix(0, 0)
|
|
||||||
f.isdir = true
|
f.isdir = true
|
||||||
} else {
|
} else {
|
||||||
f.size = parseInt64(&p.Size)
|
f.size = parseInt64(&p.Size)
|
||||||
f.modified = parseModified(&p.Modified)
|
|
||||||
f.isdir = false
|
f.isdir = false
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -183,7 +196,7 @@ func (c *Client) RemoveAll(path string) error {
|
|||||||
}
|
}
|
||||||
rs.Body.Close()
|
rs.Body.Close()
|
||||||
|
|
||||||
if rs.StatusCode == 200 || rs.StatusCode == 404 {
|
if rs.StatusCode == 200 || rs.StatusCode == 204 || rs.StatusCode == 404 {
|
||||||
return nil
|
return nil
|
||||||
} else {
|
} else {
|
||||||
return newPathError("Remove", path, rs.StatusCode)
|
return newPathError("Remove", path, rs.StatusCode)
|
||||||
@@ -248,7 +261,12 @@ func (c *Client) ReadStream(path string) (io.ReadCloser, error) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, newPathErrorErr("ReadStream", path, err)
|
return nil, newPathErrorErr("ReadStream", path, err)
|
||||||
}
|
}
|
||||||
return rs.Body, nil
|
if rs.StatusCode == 200 {
|
||||||
|
return rs.Body, nil
|
||||||
|
} else {
|
||||||
|
rs.Body.Close()
|
||||||
|
return nil, newPathError("ReadStream", path, rs.StatusCode)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Client) Write(path string, data []byte, _ os.FileMode) error {
|
func (c *Client) Write(path string, data []byte, _ os.FileMode) error {
|
||||||
|
|||||||
Reference in New Issue
Block a user