Skip to content

Commit

Permalink
Fixed a webdav compatibility issue with rclone and other bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
gilbertchen committed Feb 26, 2019
1 parent bebd7c4 commit 2b56d57
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions src/duplicacy_webdavstorage.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ var (
)

func CreateWebDAVStorage(host string, port int, username string, password string, storageDir string, useHTTP bool, threads int) (storage *WebDAVStorage, err error) {
if storageDir[len(storageDir)-1] != '/' {
if len(storageDir) > 0 && storageDir[len(storageDir)-1] != '/' {
storageDir += "/"
}

Expand All @@ -59,7 +59,7 @@ func CreateWebDAVStorage(host string, port int, username string, password string
username: username,
password: password,
storageDir: "",
useHTTP: false,
useHTTP: useHTTP,

client: http.DefaultClient,
threads: threads,
Expand Down Expand Up @@ -313,6 +313,7 @@ func (storage *WebDAVStorage) ListFiles(threadIndex int, dir string) (files []st

// GetFileInfo returns the information about the file or directory at 'filePath'.
func (storage *WebDAVStorage) GetFileInfo(threadIndex int, filePath string) (exist bool, isDir bool, size int64, err error) {

properties, err := storage.getProperties(filePath, 0, "getcontentlength", "resourcetype")
if err != nil {
if err == errWebDAVNotExist {
Expand All @@ -325,7 +326,14 @@ func (storage *WebDAVStorage) GetFileInfo(threadIndex int, filePath string) (exi
return false, false, 0, err
}

if m, exist := properties["/"+storage.storageDir+filePath]; !exist {
m, exist := properties["/"+storage.storageDir+filePath]

// If no properties exist for the given filePath, remove the trailing / from filePath and search again
if !exist && filePath != "" && filePath[len(filePath) - 1] == '/' {
m, exist = properties["/"+storage.storageDir+filePath[:len(filePath) - 1]]
}

if !exist {
return false, false, 0, nil
} else if resourceType, exist := m["resourcetype"]; exist && strings.Contains(resourceType, "collection") {
return true, true, 0, nil
Expand Down

1 comment on commit 2b56d57

@gilbertchen
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This commit has been mentioned on Duplicacy Forum. There might be relevant details there:

https://forum.duplicacy.com/t/rclone-webdav-storage-path-test-does-not-exist/1821/5

Please sign in to comment.