From 923c0e24b1dc2cc78916efa54f3515ff80045ebf Mon Sep 17 00:00:00 2001 From: Anis Elleuch Date: Wed, 29 Mar 2017 22:43:24 +0100 Subject: [PATCH] share: Download shares the url of exact prefix (#2096) When recursive flag is not specified, share download will only generate download urls for the object which has the exact same prefix. --- cmd/share-download-main.go | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/cmd/share-download-main.go b/cmd/share-download-main.go index 6bc69d29..58268adc 100644 --- a/cmd/share-download-main.go +++ b/cmd/share-download-main.go @@ -116,7 +116,32 @@ func doShareDownloadURL(targetURL string, isRecursive bool, expiry time.Duration // Generate share URL for each target. isIncomplete := false - for content := range clnt.List(isRecursive, isIncomplete, DirNone) { + + // Channel which will receive objects whose URLs need to be shared + objectsCh := make(chan *clientContent) + + if !isRecursive { + // Share thr url of only one exact prefix if it exists + content, err := clnt.Stat(isIncomplete) + if err != nil { + return err.Trace(clnt.GetURL().String()) + } + go func() { + defer close(objectsCh) + objectsCh <- content + }() + } else { + // Recursive mode: Share list of objects + go func() { + defer close(objectsCh) + for content := range clnt.List(isRecursive, isIncomplete, DirNone) { + objectsCh <- content + } + }() + } + + // Iterate over all objects to generate share URL + for content := range objectsCh { if content.Err != nil { return content.Err.Trace(clnt.GetURL().String()) }