share: Presign objects under a dir prefix (#2215)

From now on, when the user specifies to share a prefix which represents
a directory, all objects under that directory will be shared without
having to check for --recursive flag. If the latter is specified, all
objects in all subdirs will be shared.
This commit is contained in:
A. Elleuch
2017-07-31 11:39:19 -07:00
committed by Dee Koder
parent d066ff71f5
commit b62fa406d8
+16 -8
View File
@@ -17,6 +17,7 @@
package cmd
import (
"strings"
"time"
"github.com/minio/cli"
@@ -57,9 +58,9 @@ EXAMPLES:
$ {{.HelpName}} --expire=10m s3/backup/2006-Mar-1/backup.tar.gz
3. Share all objects under this folder with 5 days expiry.
$ {{.HelpName}} --expire=120h s3/backup/
$ {{.HelpName}} --expire=120h s3/backup/2006-Mar-1/
4. Share all objects under this folder and all its sub-folders with 5 days expiry.
4. Share all objects under this bucket and all its folders and sub-folders with 5 days expiry.
$ {{.HelpName}} --recursive --expire=120h s3/backup/
`,
@@ -126,17 +127,24 @@ func doShareDownloadURL(targetURL string, isRecursive bool, expiry time.Duration
// 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())
}
content, err := clnt.Stat(isIncomplete)
if err != nil {
return err.Trace(clnt.GetURL().String())
}
if !content.Type.IsDir() {
go func() {
defer close(objectsCh)
objectsCh <- content
}()
} else {
if !strings.HasSuffix(targetURLFull, string(clnt.GetURL().Separator)) {
targetURLFull = targetURLFull + string(clnt.GetURL().Separator)
}
clnt, err = newClientFromAlias(targetAlias, targetURLFull)
if err != nil {
return err.Trace(targetURLFull)
}
// Recursive mode: Share list of objects
go func() {
defer close(objectsCh)