Refactor ensureParent method to simplify MKCOL URL construction
This commit is contained in:
@@ -59,16 +59,9 @@ func (c *WebDAVClient) ensureParent(ctx context.Context, remotePath string) erro
|
||||
for _, p := range parts {
|
||||
cur = path.Join(cur, p)
|
||||
var mkurl string
|
||||
if cur == "" || cur == "/" {
|
||||
mkurl = fmt.Sprintf("%s/%s", c.BaseURL, url.PathEscape(p))
|
||||
} else {
|
||||
// Ensure there's a "/" between baseURL and cur
|
||||
sep := ""
|
||||
if !strings.HasSuffix(c.BaseURL, "/") && !strings.HasPrefix(cur, "/") {
|
||||
sep = "/"
|
||||
}
|
||||
mkurl = fmt.Sprintf("%s%s%s", c.BaseURL, sep, strings.TrimPrefix(cur, "/"))
|
||||
}
|
||||
// Always ensure a single '/' between BaseURL and the current path
|
||||
// e.g. http://nextcloud/remote.php/dav/files/testuser/orgs/<id>
|
||||
mkurl = fmt.Sprintf("%s/%s", strings.TrimRight(c.BaseURL, "/"), strings.TrimLeft(cur, "/"))
|
||||
req, _ := http.NewRequestWithContext(ctx, "MKCOL", mkurl, nil)
|
||||
if c.user != "" {
|
||||
req.SetBasicAuth(c.user, c.pass)
|
||||
|
||||
Reference in New Issue
Block a user