From d0caa630af43c3f752ad1cb83a011607d5d086ce Mon Sep 17 00:00:00 2001 From: Anis Elleuch Date: Tue, 6 Sep 2016 04:38:40 +0100 Subject: [PATCH] isTargetURLDir() returns true for aliased URLs with empty object names (#1805) --- cmd/common-methods.go | 30 ++++++++++++++++-------------- 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/cmd/common-methods.go b/cmd/common-methods.go index 5ff1681e..503a8c4c 100644 --- a/cmd/common-methods.go +++ b/cmd/common-methods.go @@ -19,6 +19,7 @@ package cmd import ( "io" "os" + "path/filepath" "regexp" "runtime" "strings" @@ -29,25 +30,26 @@ import ( // Check if the target URL represents folder. It may or may not exist yet. func isTargetURLDir(targetURL string) bool { - targetURLParse := newClientURL(targetURL) _, targetContent, err := url2Stat(targetURL) - if err != nil { - _, aliasedTargetURL, _ := mustExpandAlias(targetURL) - if aliasedTargetURL == targetURL { - return false - } - if targetURLParse.Path == string(targetURLParse.Separator) && targetURLParse.Scheme != "" { - return false - } - if strings.HasSuffix(targetURLParse.Path, string(targetURLParse.Separator)) { - return true - } + if err == nil { + return targetContent.Type.IsDir() + } + _, aliasedTargetURL, _ := mustExpandAlias(targetURL) + if aliasedTargetURL == targetURL { return false } - if !targetContent.Type.IsDir() { // Target is a dir. + // targetURL is an aliased path, continue guessing if the path + // is meant to point to a bucket or directory + pathURL := filepath.FromSlash(targetURL) + fields := strings.Split(pathURL, string(filepath.Separator)) + switch len(fields) { + case 0, 1: return false + case 2: + return true + default: + return strings.HasSuffix(pathURL, string(filepath.Separator)) } - return true } // getSource gets a reader from URL.