mirror of
https://github.com/1f349/go-webdav.git
synced 2024-12-22 08:14:15 +00:00
webdav: add Client.MoveAll
This commit is contained in:
parent
d30d4d2932
commit
489be203a1
18
client.go
18
client.go
@ -186,3 +186,21 @@ func (c *Client) Mkdir(name string) error {
|
||||
_, err = c.ic.Do(req)
|
||||
return err
|
||||
}
|
||||
|
||||
func (c *Client) MoveAll(name, dest string, overwrite bool) error {
|
||||
req, err := c.ic.NewRequest("MOVE", name, nil)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
dest, err = c.ic.ResolveHref(dest)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
req.Header.Set("Destination", dest)
|
||||
|
||||
req.Header.Set("Overwrite", internal.FormatOverwrite(overwrite))
|
||||
|
||||
_, err = c.ic.Do(req)
|
||||
return err
|
||||
}
|
||||
|
@ -33,10 +33,10 @@ func (c *Client) SetBasicAuth(username, password string) {
|
||||
c.password = password
|
||||
}
|
||||
|
||||
func (c *Client) NewRequest(method string, href string, body io.Reader) (*http.Request, error) {
|
||||
func (c *Client) ResolveHref(href string) (string, error) {
|
||||
hrefURL, err := url.Parse(href)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to parse request href %q: %v", href, err)
|
||||
return "", fmt.Errorf("webdav: failed to parse href %q: %v", href, err)
|
||||
}
|
||||
|
||||
u := url.URL{
|
||||
@ -46,7 +46,15 @@ func (c *Client) NewRequest(method string, href string, body io.Reader) (*http.R
|
||||
Path: path.Join(c.endpoint.Path, hrefURL.Path),
|
||||
RawQuery: hrefURL.RawQuery,
|
||||
}
|
||||
return http.NewRequest(method, u.String(), body)
|
||||
return u.String(), nil
|
||||
}
|
||||
|
||||
func (c *Client) NewRequest(method string, href string, body io.Reader) (*http.Request, error) {
|
||||
href, err := c.ResolveHref(href)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return http.NewRequest(method, href, body)
|
||||
}
|
||||
|
||||
func (c *Client) NewXMLRequest(method string, href string, v interface{}) (*http.Request, error) {
|
||||
|
Loading…
Reference in New Issue
Block a user