Skip to content

Commit

Permalink
share: Presign objects under a dir prefix (#2215)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
vadmeste authored and deekoder committed Jul 31, 2017
1 parent d066ff7 commit b62fa40
Showing 1 changed file with 16 additions and 8 deletions.
24 changes: 16 additions & 8 deletions cmd/share-download-main.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package cmd

import (
"strings"
"time"

"github.com/minio/cli"
Expand Down Expand Up @@ -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/
`,
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit b62fa40

Please sign in to comment.