From 3f572e6bf2946fbe505886c72937844f288795b9 Mon Sep 17 00:00:00 2001 From: Nick Craig-Wood Date: Thu, 29 Nov 2018 17:54:02 +0000 Subject: [PATCH] webdav: fix infinite loop on failed directory creation - fixes #2714 --- backend/webdav/webdav.go | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/backend/webdav/webdav.go b/backend/webdav/webdav.go index 8370d7904..2738d6200 100644 --- a/backend/webdav/webdav.go +++ b/backend/webdav/webdav.go @@ -601,10 +601,9 @@ func (f *Fs) mkParentDir(dirPath string) error { return f.mkdir(parent) } -// mkdir makes the directory and parents using native paths -func (f *Fs) mkdir(dirPath string) error { - // defer log.Trace(dirPath, "")("") - // We assume the root is already ceated +// low level mkdir, only makes the directory, doesn't attempt to create parents +func (f *Fs) _mkdir(dirPath string) error { + // We assume the root is already created if dirPath == "" { return nil } @@ -617,20 +616,26 @@ func (f *Fs) mkdir(dirPath string) error { Path: dirPath, NoResponse: true, } - err := f.pacer.Call(func() (bool, error) { + return f.pacer.Call(func() (bool, error) { resp, err := f.srv.Call(&opts) return shouldRetry(resp, err) }) +} + +// mkdir makes the directory and parents using native paths +func (f *Fs) mkdir(dirPath string) error { + // defer log.Trace(dirPath, "")("") + err := f._mkdir(dirPath) if apiErr, ok := err.(*api.Error); ok { // already exists if apiErr.StatusCode == http.StatusMethodNotAllowed || apiErr.StatusCode == http.StatusNotAcceptable { return nil } - // parent does not exists + // parent does not exist if apiErr.StatusCode == http.StatusConflict { err = f.mkParentDir(dirPath) if err == nil { - err = f.mkdir(dirPath) + err = f._mkdir(dirPath) } } }