WebDAV: Ensure remote path exists to fix sync upload #3310

Signed-off-by: Michael Mayer <michael@photoprism.app>
This commit is contained in:
Michael Mayer 2023-03-30 14:50:16 +02:00
parent 9e8504c84f
commit db496c9392
4 changed files with 24 additions and 7 deletions

View file

@ -173,7 +173,7 @@ func (c *Client) MkdirAll(dir string) (err error) {
for _, folder := range folders {
dir = path.Join(dir, folder)
err = c.client.Mkdir(dir)
err = c.Mkdir(dir)
}
return err
@ -193,7 +193,15 @@ func (c *Client) Mkdir(dir string) error {
c.mkdir[dir] = true
return c.client.Mkdir(dir)
err := c.client.Mkdir(dir)
if err == nil {
return nil
} else if strings.Contains(err.Error(), "already exists") {
return nil
}
return err
}
// Upload uploads a single file to the remote server.

View file

@ -102,8 +102,10 @@ func (w *Share) Start() (err error) {
dir := path.Dir(file.RemoteName)
// Ensure destination folder exists.
_ = client.MkdirAll(dir)
// Ensure remote folder exists.
if err := client.MkdirAll(dir); err != nil {
log.Debugf("share: %s", err)
}
srcFileName := photoprism.FileName(file.File.FileRoot, file.File.FileName)

View file

@ -20,10 +20,15 @@ func (w *Sync) refresh(a entity.Service) (complete bool, err error) {
return false, err
}
// Ensure remote folder exists.
if err = client.MkdirAll(a.SyncPath); err != nil {
log.Debugf("sync: %s", err)
}
subDirs, err := client.Directories(a.SyncPath, true, webdav.MaxRequestDuration)
if err != nil {
log.Error(err)
log.Errorf("sync: %s", err)
return false, err
}

View file

@ -45,8 +45,10 @@ func (w *Sync) upload(a entity.Service) (complete bool, err error) {
remoteName := path.Join(a.SyncPath, file.FileName)
remoteDir := path.Dir(remoteName)
// Ensure destination folder exists.
_ = client.MkdirAll(remoteDir)
// Ensure remote folder exists.
if err := client.MkdirAll(remoteDir); err != nil {
log.Debugf("sync: %s", err)
}
if err := client.Upload(fileName, remoteName); err != nil {
w.logError(err)