Merge pull request #1484 from abperiasamy/type-d-enhanced

enhance type D to support files and dirs with recursive flag
This commit is contained in:
Anand Babu (AB) Periasamy
2015-11-24 13:29:08 -08:00
2 changed files with 14 additions and 21 deletions
+4 -12
View File
@@ -40,7 +40,8 @@ func checkCopySyntax(ctx *cli.Context) {
tgtURL := URLs[len(URLs)-1]
isRecursive := ctx.Bool("recursive")
/****** Generic rules *******/
/****** Generic Invalid Rules *******/
// Check if bucket name is passed for URL type arguments.
url := client.NewURL(tgtURL)
if url.Host != "" {
// This check is for type URL.
@@ -129,17 +130,8 @@ func checkCopySyntaxTypeC(srcURLs []string, tgtURL string, isRecursive bool) {
// checkCopySyntaxTypeD verifies if the source is a valid list of files and target is a valid folder.
func checkCopySyntaxTypeD(srcURLs []string, tgtURL string) {
// Check source.
for _, srcURL := range srcURLs {
_, srcContent, err := url2Stat(srcURL)
fatalIf(err.Trace(srcURL), "Unable to stat source ‘"+srcURL+"’.")
if !srcContent.Type.IsRegular() {
fatalIf(errInvalidArgument().Trace(), "Source ‘"+srcURL+"’ is not a file.")
}
}
// Check target.
// Source can be anything: file, dir, dir...
// Check target if it is a dir
if _, tgtContent, err := url2Stat(tgtURL); err == nil {
if !tgtContent.Type.IsDir() {
fatalIf(errInvalidArgument().Trace(tgtURL), "Target ‘"+tgtURL+"’ is not a folder.")
+10 -9
View File
@@ -39,15 +39,13 @@ type copyURLsType uint8
// A: copy(f, f) -> copy(f, f)
// B: copy(f, d) -> copy(f, d/f) -> []A
// C: copy(d1..., d2) -> []copy(f, d2/d1/f) -> []A
// D: copy([]f, d) -> []B -> []A
// D: copy([]f, d) -> []B
//
// * INVALID RULES
// =========================
// copy(d, f)
// copy(d..., f)
// copy([]f, f)
//'
// copy([](f|d)..., f)
const (
copyURLsTypeInvalid copyURLsType = iota
@@ -85,6 +83,7 @@ func guessCopyURLType(sourceURLs []string, targetURL string, isRecursive bool) c
if isTargetURLDir(targetURL) {
return copyURLsTypeD
}
return copyURLsTypeInvalid
}
@@ -186,14 +185,16 @@ func makeCopyContentTypeC(sourceURL client.URL, sourceContent *client.Content, t
return makeCopyContentTypeA(sourceContent, newTargetURL)
}
// MULTI-SOURCE - Type D: copy([]f, d) -> []B
// prepareCopyURLsTypeD - prepares target and source URLs for copying.
func prepareCopyURLsTypeD(sourceURLs []string, targetURL string) <-chan copyURLs {
// MULTI-SOURCE - Type D: copy([](f|d...), d) -> []B
// prepareCopyURLsTypeE - prepares target and source URLs for copying.
func prepareCopyURLsTypeD(sourceURLs []string, targetURL string, isRecursive bool) <-chan copyURLs {
copyURLsCh := make(chan copyURLs)
go func(sourceURLs []string, targetURL string, copyURLsCh chan copyURLs) {
defer close(copyURLsCh)
for _, sourceURL := range sourceURLs {
copyURLsCh <- prepareCopyURLsTypeB(sourceURL, targetURL)
for cpURLs := range prepareCopyURLsTypeC(sourceURL, targetURL, isRecursive) {
copyURLsCh <- cpURLs
}
}
}(sourceURLs, targetURL, copyURLsCh)
return copyURLsCh
@@ -214,7 +215,7 @@ func prepareCopyURLs(sourceURLs []string, targetURL string, isRecursive bool) <-
copyURLsCh <- cURLs
}
case copyURLsTypeD:
for cURLs := range prepareCopyURLsTypeD(sourceURLs, targetURL) {
for cURLs := range prepareCopyURLsTypeD(sourceURLs, targetURL, isRecursive) {
copyURLsCh <- cURLs
}
default: