Implement mc ls incomplete s3/bucketname
This commit is contained in:
@@ -295,7 +295,7 @@ func prepareCopyURLsTypeC(sourceURL, targetURL string) <-chan copyURLs {
|
||||
return
|
||||
}
|
||||
|
||||
for sourceContent := range sourceClient.List(true) {
|
||||
for sourceContent := range sourceClient.List(true, false) {
|
||||
if sourceContent.Err != nil {
|
||||
// Listing failed.
|
||||
copyURLsCh <- copyURLs{Error: sourceContent.Err.Trace()}
|
||||
|
||||
@@ -166,7 +166,7 @@ func doDiffObjects(firstURL, secondURL string, ch chan DiffMessage) {
|
||||
}
|
||||
|
||||
func dodiff(firstClnt, secondClnt client.Client, ch chan DiffMessage) {
|
||||
for contentCh := range firstClnt.List(false) {
|
||||
for contentCh := range firstClnt.List(false, false) {
|
||||
if contentCh.Err != nil {
|
||||
ch <- DiffMessage{
|
||||
Error: contentCh.Err.Trace(firstClnt.URL().String()),
|
||||
@@ -231,8 +231,8 @@ func dodiffRecursive(firstClnt, secondClnt client.Client, ch chan DiffMessage) {
|
||||
return
|
||||
}
|
||||
|
||||
fch := firstClnt.List(true)
|
||||
sch := secondClnt.List(true)
|
||||
fch := firstClnt.List(true, false)
|
||||
sch := secondClnt.List(true, false)
|
||||
f, fok := <-fch
|
||||
s, sok := <-sch
|
||||
for {
|
||||
|
||||
+31
-14
@@ -23,6 +23,7 @@ import (
|
||||
"github.com/minio/cli"
|
||||
"github.com/minio/mc/pkg/client"
|
||||
"github.com/minio/mc/pkg/console"
|
||||
"github.com/minio/minio-xl/pkg/probe"
|
||||
)
|
||||
|
||||
// list files and folders.
|
||||
@@ -49,23 +50,24 @@ EXAMPLES:
|
||||
|
||||
3. List files recursively on local filesystem on Windows.
|
||||
$ mc {{.Name}} C:\Users\Worf\...
|
||||
[2015-03-28 12:47:50 PDT] 11.00MiB Martok\Klingon Council Ministers.pdf
|
||||
[2015-03-31 14:46:33 PDT] 15.00MiB Gowron\Khitomer Conference Details.pdf
|
||||
|
||||
4. List files with non english characters on Amazon S3 cloud storage.
|
||||
$ mc ls s3/andoria/本...
|
||||
[2015-05-19 17:24:19 PDT] 41B 本語.txt
|
||||
[2015-05-19 17:28:22 PDT] 41B 本語.md
|
||||
|
||||
5. List files with space characters on Amazon S3 cloud storage.
|
||||
$ mc ls 's3/miniocloud/Community Files/'
|
||||
[2015-05-19 17:24:19 PDT] 41B 本語.txt
|
||||
[2015-05-19 17:28:22 PDT] 41B 本語.md
|
||||
|
||||
6. Behave like operating system tool ‘ls’, used for shell aliases.
|
||||
$ mc --mimic ls
|
||||
[2015-05-19 17:28:22 PDT] 41B 本語.md
|
||||
|
||||
7. List incompletely uploaded files for a given bucket
|
||||
$ mc ls incomplete s3/miniocloud
|
||||
[2015-10-19 22:28:02 PDT] 0B bin/
|
||||
|
||||
`,
|
||||
}
|
||||
|
||||
@@ -113,6 +115,7 @@ func setListPalette(style string) {
|
||||
|
||||
// mainList - is a handler for mc ls command
|
||||
func mainList(ctx *cli.Context) {
|
||||
setListPalette(ctx.GlobalString("colors"))
|
||||
checkListSyntax(ctx)
|
||||
|
||||
args := ctx.Args()
|
||||
@@ -121,18 +124,32 @@ func mainList(ctx *cli.Context) {
|
||||
args = []string{"."}
|
||||
}
|
||||
|
||||
setListPalette(ctx.GlobalString("colors"))
|
||||
var targetURLs []string
|
||||
var err *probe.Error
|
||||
if args.First() == "incomplete" {
|
||||
targetURLs, err = args2URLs(args.Tail())
|
||||
fatalIf(err.Trace(args...), "One or more unknown URL types passed.")
|
||||
for _, targetURL := range targetURLs {
|
||||
// if recursive strip off the "..."
|
||||
var clnt client.Client
|
||||
clnt, err = url2Client(stripRecursiveURL(targetURL))
|
||||
fatalIf(err.Trace(targetURL), "Unable to initialize target ‘"+targetURL+"’.")
|
||||
|
||||
targetURLs, err := args2URLs(args)
|
||||
fatalIf(err.Trace(args...), "One or more unknown URL types passed.")
|
||||
err = doListIncomplete(clnt, isURLRecursive(targetURL), len(targetURLs) > 1)
|
||||
fatalIf(err.Trace(clnt.URL().String()), "Unable to list target ‘"+clnt.URL().String()+"’.")
|
||||
}
|
||||
} else {
|
||||
targetURLs, err = args2URLs(args)
|
||||
fatalIf(err.Trace(args...), "One or more unknown URL types passed.")
|
||||
for _, targetURL := range targetURLs {
|
||||
// if recursive strip off the "..."
|
||||
var clnt client.Client
|
||||
clnt, err = url2Client(stripRecursiveURL(targetURL))
|
||||
fatalIf(err.Trace(targetURL), "Unable to initialize target ‘"+targetURL+"’.")
|
||||
|
||||
for _, targetURL := range targetURLs {
|
||||
// if recursive strip off the "..."
|
||||
var clnt client.Client
|
||||
clnt, err = url2Client(stripRecursiveURL(targetURL))
|
||||
fatalIf(err.Trace(targetURL), "Unable to initialize target ‘"+targetURL+"’.")
|
||||
|
||||
err = doList(clnt, isURLRecursive(targetURL), len(targetURLs) > 1)
|
||||
fatalIf(err.Trace(clnt.URL().String()), "Unable to list target ‘"+clnt.URL().String()+"’.")
|
||||
err = doList(clnt, isURLRecursive(targetURL), len(targetURLs) > 1)
|
||||
fatalIf(err.Trace(clnt.URL().String()), "Unable to list target ‘"+clnt.URL().String()+"’.")
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -110,7 +110,50 @@ func doList(clnt client.Client, recursive, multipleArgs bool) *probe.Error {
|
||||
if err != nil {
|
||||
return err.Trace(clnt.URL().String())
|
||||
}
|
||||
for contentCh := range clnt.List(recursive) {
|
||||
for contentCh := range clnt.List(recursive, false) {
|
||||
if contentCh.Err != nil {
|
||||
switch contentCh.Err.ToGoError().(type) {
|
||||
// handle this specifically for filesystem
|
||||
case client.BrokenSymlink:
|
||||
errorIf(contentCh.Err.Trace(), "Unable to list broken link.")
|
||||
continue
|
||||
case client.TooManyLevelsSymlink:
|
||||
errorIf(contentCh.Err.Trace(), "Unable to list too many levels link.")
|
||||
continue
|
||||
}
|
||||
if os.IsNotExist(contentCh.Err.ToGoError()) || os.IsPermission(contentCh.Err.ToGoError()) {
|
||||
if contentCh.Content != nil {
|
||||
if contentCh.Content.Type.IsDir() && (contentCh.Content.Type&os.ModeSymlink == os.ModeSymlink) {
|
||||
errorIf(contentCh.Err.Trace(), "Unable to list broken folder link.")
|
||||
continue
|
||||
}
|
||||
}
|
||||
errorIf(contentCh.Err.Trace(), "Unable to list.")
|
||||
continue
|
||||
}
|
||||
err = contentCh.Err.Trace()
|
||||
break
|
||||
}
|
||||
if multipleArgs && parentContent.Type.IsDir() {
|
||||
contentCh.Content.Name = filepath.Join(parentContent.Name, strings.TrimPrefix(contentCh.Content.Name, parentContent.Name))
|
||||
}
|
||||
Prints("%s\n", parseContent(contentCh.Content))
|
||||
}
|
||||
if err != nil {
|
||||
return err.Trace()
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// doListIncomplete - list all incomplete uploads entities inside a folder.
|
||||
func doListIncomplete(clnt client.Client, recursive, multipleArgs bool) *probe.Error {
|
||||
var err *probe.Error
|
||||
var parentContent *client.Content
|
||||
parentContent, err = clnt.Stat()
|
||||
if err != nil {
|
||||
return err.Trace(clnt.URL().String())
|
||||
}
|
||||
for contentCh := range clnt.List(recursive, true) {
|
||||
if contentCh.Err != nil {
|
||||
switch contentCh.Err.ToGoError().(type) {
|
||||
// handle this specifically for filesystem
|
||||
|
||||
@@ -28,7 +28,7 @@ import (
|
||||
type Client interface {
|
||||
// Common operations
|
||||
Stat() (content *Content, err *probe.Error)
|
||||
List(recursive bool) <-chan ContentOnChannel
|
||||
List(recursive, incomplete bool) <-chan ContentOnChannel
|
||||
|
||||
// Bucket operations
|
||||
MakeBucket() *probe.Error
|
||||
|
||||
+7
-1
@@ -197,8 +197,14 @@ func (f *fsClient) Remove() *probe.Error {
|
||||
}
|
||||
|
||||
// List - list files and folders
|
||||
func (f *fsClient) List(recursive bool) <-chan client.ContentOnChannel {
|
||||
func (f *fsClient) List(recursive, incomplete bool) <-chan client.ContentOnChannel {
|
||||
contentCh := make(chan client.ContentOnChannel)
|
||||
if incomplete {
|
||||
go func() {
|
||||
defer close(contentCh)
|
||||
}()
|
||||
return contentCh
|
||||
}
|
||||
switch recursive {
|
||||
case true:
|
||||
go f.listRecursiveInRoutine(contentCh)
|
||||
|
||||
@@ -61,7 +61,7 @@ func (s *MySuite) TestList(c *C) {
|
||||
c.Assert(err, IsNil)
|
||||
|
||||
var contents []*client.Content
|
||||
for contentCh := range fsc.List(false) {
|
||||
for contentCh := range fsc.List(false, false) {
|
||||
if contentCh.Err != nil {
|
||||
perr = contentCh.Err
|
||||
break
|
||||
@@ -86,7 +86,7 @@ func (s *MySuite) TestList(c *C) {
|
||||
c.Assert(err, IsNil)
|
||||
|
||||
contents = nil
|
||||
for contentCh := range fsc.List(false) {
|
||||
for contentCh := range fsc.List(false, false) {
|
||||
if contentCh.Err != nil {
|
||||
perr = contentCh.Err
|
||||
break
|
||||
@@ -108,7 +108,7 @@ func (s *MySuite) TestList(c *C) {
|
||||
c.Assert(err, IsNil)
|
||||
|
||||
contents = nil
|
||||
for contentCh := range fsc.List(true) {
|
||||
for contentCh := range fsc.List(true, false) {
|
||||
if contentCh.Err != nil {
|
||||
perr = contentCh.Err
|
||||
break
|
||||
|
||||
+138
-7
@@ -206,7 +206,7 @@ func (c *s3Client) Stat() (*client.Content, *probe.Error) {
|
||||
errResponse := minio.ToErrorResponse(err)
|
||||
if errResponse != nil {
|
||||
if errResponse.Code == "NoSuchKey" {
|
||||
for content := range c.List(false) {
|
||||
for content := range c.List(false, false) {
|
||||
if content.Err != nil {
|
||||
return nil, content.Err.Trace()
|
||||
}
|
||||
@@ -267,17 +267,148 @@ func (c *s3Client) url2BucketAndObject() (bucketName, objectName string) {
|
||||
/// Bucket API operations
|
||||
|
||||
// List - list at delimited path, if not recursive
|
||||
func (c *s3Client) List(recursive bool) <-chan client.ContentOnChannel {
|
||||
func (c *s3Client) List(recursive, incomplete bool) <-chan client.ContentOnChannel {
|
||||
contentCh := make(chan client.ContentOnChannel)
|
||||
switch recursive {
|
||||
case true:
|
||||
go c.listRecursiveInRoutine(contentCh)
|
||||
default:
|
||||
go c.listInRoutine(contentCh)
|
||||
if incomplete {
|
||||
if recursive {
|
||||
go c.listIncompleteRecursiveInRoutine(contentCh)
|
||||
} else {
|
||||
go c.listIncompleteInRoutine(contentCh)
|
||||
}
|
||||
} else {
|
||||
if recursive {
|
||||
go c.listRecursiveInRoutine(contentCh)
|
||||
} else {
|
||||
go c.listInRoutine(contentCh)
|
||||
}
|
||||
}
|
||||
return contentCh
|
||||
}
|
||||
|
||||
func (c *s3Client) listIncompleteInRoutine(contentCh chan client.ContentOnChannel) {
|
||||
defer close(contentCh)
|
||||
b, o := c.url2BucketAndObject()
|
||||
switch {
|
||||
case b == "" && o == "":
|
||||
for bucket := range c.api.ListBuckets() {
|
||||
if bucket.Err != nil {
|
||||
contentCh <- client.ContentOnChannel{
|
||||
Content: nil,
|
||||
Err: probe.NewError(bucket.Err),
|
||||
}
|
||||
return
|
||||
}
|
||||
content := new(client.Content)
|
||||
content.Name = bucket.Stat.Name
|
||||
content.Size = 0
|
||||
content.Time = bucket.Stat.CreationDate
|
||||
content.Type = os.ModeDir
|
||||
contentCh <- client.ContentOnChannel{
|
||||
Content: content,
|
||||
Err: nil,
|
||||
}
|
||||
}
|
||||
default:
|
||||
for object := range c.api.ListIncompleteUploads(b, o, false) {
|
||||
if object.Err != nil {
|
||||
contentCh <- client.ContentOnChannel{
|
||||
Content: nil,
|
||||
Err: probe.NewError(object.Err),
|
||||
}
|
||||
return
|
||||
}
|
||||
content := new(client.Content)
|
||||
normalizedPrefix := strings.TrimSuffix(o, string(c.hostURL.Separator)) + string(c.hostURL.Separator)
|
||||
normalizedKey := object.Stat.Key
|
||||
if normalizedPrefix != object.Stat.Key && strings.HasPrefix(object.Stat.Key, normalizedPrefix) {
|
||||
normalizedKey = strings.TrimPrefix(object.Stat.Key, normalizedPrefix)
|
||||
}
|
||||
content.Name = normalizedKey
|
||||
switch {
|
||||
case strings.HasSuffix(object.Stat.Key, string(c.hostURL.Separator)):
|
||||
content.Time = time.Now()
|
||||
content.Type = os.ModeDir
|
||||
default:
|
||||
content.Size = object.Stat.Size
|
||||
content.Time = object.Stat.Initiated
|
||||
content.Type = os.ModeTemporary
|
||||
}
|
||||
contentCh <- client.ContentOnChannel{
|
||||
Content: content,
|
||||
Err: nil,
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (c *s3Client) listIncompleteRecursiveInRoutine(contentCh chan client.ContentOnChannel) {
|
||||
defer close(contentCh)
|
||||
b, o := c.url2BucketAndObject()
|
||||
switch {
|
||||
case b == "" && o == "":
|
||||
for bucket := range c.api.ListBuckets() {
|
||||
if bucket.Err != nil {
|
||||
contentCh <- client.ContentOnChannel{
|
||||
Content: nil,
|
||||
Err: probe.NewError(bucket.Err),
|
||||
}
|
||||
return
|
||||
}
|
||||
for object := range c.api.ListIncompleteUploads(bucket.Stat.Name, o, true) {
|
||||
if object.Err != nil {
|
||||
contentCh <- client.ContentOnChannel{
|
||||
Content: nil,
|
||||
Err: probe.NewError(object.Err),
|
||||
}
|
||||
return
|
||||
}
|
||||
content := new(client.Content)
|
||||
content.Name = filepath.Join(bucket.Stat.Name, object.Stat.Key)
|
||||
content.Size = object.Stat.Size
|
||||
content.Time = object.Stat.Initiated
|
||||
content.Type = os.ModeTemporary
|
||||
contentCh <- client.ContentOnChannel{
|
||||
Content: content,
|
||||
Err: nil,
|
||||
}
|
||||
}
|
||||
}
|
||||
default:
|
||||
for object := range c.api.ListIncompleteUploads(b, o, true) {
|
||||
if object.Err != nil {
|
||||
contentCh <- client.ContentOnChannel{
|
||||
Content: nil,
|
||||
Err: probe.NewError(object.Err),
|
||||
}
|
||||
return
|
||||
}
|
||||
content := new(client.Content)
|
||||
normalizedKey := object.Stat.Key
|
||||
switch {
|
||||
case o == "":
|
||||
// if no prefix provided and also URL is not delimited then we add bucket back into object name
|
||||
if strings.LastIndex(c.hostURL.Path, string(c.hostURL.Separator)) == 0 {
|
||||
if c.hostURL.String()[:strings.LastIndex(c.hostURL.String(), string(c.hostURL.Separator))+1] != b {
|
||||
normalizedKey = filepath.Join(b, object.Stat.Key)
|
||||
}
|
||||
}
|
||||
default:
|
||||
if strings.HasSuffix(o, string(c.hostURL.Separator)) {
|
||||
normalizedKey = strings.TrimPrefix(object.Stat.Key, o)
|
||||
}
|
||||
}
|
||||
content.Name = normalizedKey
|
||||
content.Size = object.Stat.Size
|
||||
content.Time = object.Stat.Initiated
|
||||
content.Type = os.ModeTemporary
|
||||
contentCh <- client.ContentOnChannel{
|
||||
Content: content,
|
||||
Err: nil,
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (c *s3Client) listInRoutine(contentCh chan client.ContentOnChannel) {
|
||||
defer close(contentCh)
|
||||
b, o := c.url2BucketAndObject()
|
||||
|
||||
@@ -147,7 +147,7 @@ func (s *MySuite) TestBucketOperations(c *C) {
|
||||
s3c, err = New(conf)
|
||||
c.Assert(err, IsNil)
|
||||
|
||||
for content := range s3c.List(false) {
|
||||
for content := range s3c.List(false, false) {
|
||||
c.Assert(content.Err, IsNil)
|
||||
c.Assert(content.Content.Name, Equals, "bucket")
|
||||
c.Assert(content.Content.Type.IsDir(), Equals, true)
|
||||
@@ -157,7 +157,7 @@ func (s *MySuite) TestBucketOperations(c *C) {
|
||||
s3c, err = New(conf)
|
||||
c.Assert(err, IsNil)
|
||||
|
||||
for content := range s3c.List(false) {
|
||||
for content := range s3c.List(false, false) {
|
||||
c.Assert(content.Err, IsNil)
|
||||
c.Assert(content.Content.Name, Equals, "object")
|
||||
c.Assert(content.Content.Type.IsRegular(), Equals, true)
|
||||
|
||||
+138
-7
@@ -206,7 +206,7 @@ func (c *s3Client) Stat() (*client.Content, *probe.Error) {
|
||||
errResponse := minio.ToErrorResponse(err)
|
||||
if errResponse != nil {
|
||||
if errResponse.Code == "NoSuchKey" {
|
||||
for content := range c.List(false) {
|
||||
for content := range c.List(false, false) {
|
||||
if content.Err != nil {
|
||||
return nil, content.Err.Trace()
|
||||
}
|
||||
@@ -266,17 +266,148 @@ func (c *s3Client) url2BucketAndObject() (bucketName, objectName string) {
|
||||
/// Bucket API operations
|
||||
|
||||
// List - list at delimited path, if not recursive
|
||||
func (c *s3Client) List(recursive bool) <-chan client.ContentOnChannel {
|
||||
func (c *s3Client) List(recursive, incomplete bool) <-chan client.ContentOnChannel {
|
||||
contentCh := make(chan client.ContentOnChannel)
|
||||
switch recursive {
|
||||
case true:
|
||||
go c.listRecursiveInRoutine(contentCh)
|
||||
default:
|
||||
go c.listInRoutine(contentCh)
|
||||
if incomplete {
|
||||
if recursive {
|
||||
go c.listIncompleteRecursiveInRoutine(contentCh)
|
||||
} else {
|
||||
go c.listIncompleteInRoutine(contentCh)
|
||||
}
|
||||
} else {
|
||||
if recursive {
|
||||
go c.listRecursiveInRoutine(contentCh)
|
||||
} else {
|
||||
go c.listInRoutine(contentCh)
|
||||
}
|
||||
}
|
||||
return contentCh
|
||||
}
|
||||
|
||||
func (c *s3Client) listIncompleteInRoutine(contentCh chan client.ContentOnChannel) {
|
||||
defer close(contentCh)
|
||||
b, o := c.url2BucketAndObject()
|
||||
switch {
|
||||
case b == "" && o == "":
|
||||
for bucket := range c.api.ListBuckets() {
|
||||
if bucket.Err != nil {
|
||||
contentCh <- client.ContentOnChannel{
|
||||
Content: nil,
|
||||
Err: probe.NewError(bucket.Err),
|
||||
}
|
||||
return
|
||||
}
|
||||
content := new(client.Content)
|
||||
content.Name = bucket.Stat.Name
|
||||
content.Size = 0
|
||||
content.Time = bucket.Stat.CreationDate
|
||||
content.Type = os.ModeDir
|
||||
contentCh <- client.ContentOnChannel{
|
||||
Content: content,
|
||||
Err: nil,
|
||||
}
|
||||
}
|
||||
default:
|
||||
for object := range c.api.ListIncompleteUploads(b, o, false) {
|
||||
if object.Err != nil {
|
||||
contentCh <- client.ContentOnChannel{
|
||||
Content: nil,
|
||||
Err: probe.NewError(object.Err),
|
||||
}
|
||||
return
|
||||
}
|
||||
content := new(client.Content)
|
||||
normalizedPrefix := strings.TrimSuffix(o, string(c.hostURL.Separator)) + string(c.hostURL.Separator)
|
||||
normalizedKey := object.Stat.Key
|
||||
if normalizedPrefix != object.Stat.Key && strings.HasPrefix(object.Stat.Key, normalizedPrefix) {
|
||||
normalizedKey = strings.TrimPrefix(object.Stat.Key, normalizedPrefix)
|
||||
}
|
||||
content.Name = normalizedKey
|
||||
switch {
|
||||
case strings.HasSuffix(object.Stat.Key, string(c.hostURL.Separator)):
|
||||
content.Time = time.Now()
|
||||
content.Type = os.ModeDir
|
||||
default:
|
||||
content.Size = object.Stat.Size
|
||||
content.Time = object.Stat.Initiated
|
||||
content.Type = os.ModeTemporary
|
||||
}
|
||||
contentCh <- client.ContentOnChannel{
|
||||
Content: content,
|
||||
Err: nil,
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (c *s3Client) listIncompleteRecursiveInRoutine(contentCh chan client.ContentOnChannel) {
|
||||
defer close(contentCh)
|
||||
b, o := c.url2BucketAndObject()
|
||||
switch {
|
||||
case b == "" && o == "":
|
||||
for bucket := range c.api.ListBuckets() {
|
||||
if bucket.Err != nil {
|
||||
contentCh <- client.ContentOnChannel{
|
||||
Content: nil,
|
||||
Err: probe.NewError(bucket.Err),
|
||||
}
|
||||
return
|
||||
}
|
||||
for object := range c.api.ListIncompleteUploads(bucket.Stat.Name, o, true) {
|
||||
if object.Err != nil {
|
||||
contentCh <- client.ContentOnChannel{
|
||||
Content: nil,
|
||||
Err: probe.NewError(object.Err),
|
||||
}
|
||||
return
|
||||
}
|
||||
content := new(client.Content)
|
||||
content.Name = filepath.Join(bucket.Stat.Name, object.Stat.Key)
|
||||
content.Size = object.Stat.Size
|
||||
content.Time = object.Stat.Initiated
|
||||
content.Type = os.ModeTemporary
|
||||
contentCh <- client.ContentOnChannel{
|
||||
Content: content,
|
||||
Err: nil,
|
||||
}
|
||||
}
|
||||
}
|
||||
default:
|
||||
for object := range c.api.ListIncompleteUploads(b, o, true) {
|
||||
if object.Err != nil {
|
||||
contentCh <- client.ContentOnChannel{
|
||||
Content: nil,
|
||||
Err: probe.NewError(object.Err),
|
||||
}
|
||||
return
|
||||
}
|
||||
content := new(client.Content)
|
||||
normalizedKey := object.Stat.Key
|
||||
switch {
|
||||
case o == "":
|
||||
// if no prefix provided and also URL is not delimited then we add bucket back into object name
|
||||
if strings.LastIndex(c.hostURL.Path, string(c.hostURL.Separator)) == 0 {
|
||||
if c.hostURL.String()[:strings.LastIndex(c.hostURL.String(), string(c.hostURL.Separator))+1] != b {
|
||||
normalizedKey = filepath.Join(b, object.Stat.Key)
|
||||
}
|
||||
}
|
||||
default:
|
||||
if strings.HasSuffix(o, string(c.hostURL.Separator)) {
|
||||
normalizedKey = strings.TrimPrefix(object.Stat.Key, o)
|
||||
}
|
||||
}
|
||||
content.Name = normalizedKey
|
||||
content.Size = object.Stat.Size
|
||||
content.Time = object.Stat.Initiated
|
||||
content.Type = os.ModeTemporary
|
||||
contentCh <- client.ContentOnChannel{
|
||||
Content: content,
|
||||
Err: nil,
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (c *s3Client) listInRoutine(contentCh chan client.ContentOnChannel) {
|
||||
defer close(contentCh)
|
||||
b, o := c.url2BucketAndObject()
|
||||
|
||||
@@ -147,7 +147,7 @@ func (s *MySuite) TestBucketOperations(c *C) {
|
||||
s3c, err = New(conf)
|
||||
c.Assert(err, IsNil)
|
||||
|
||||
for content := range s3c.List(false) {
|
||||
for content := range s3c.List(false, false) {
|
||||
c.Assert(content.Err, IsNil)
|
||||
c.Assert(content.Content.Name, Equals, "bucket")
|
||||
c.Assert(content.Content.Type.IsDir(), Equals, true)
|
||||
@@ -157,7 +157,7 @@ func (s *MySuite) TestBucketOperations(c *C) {
|
||||
s3c, err = New(conf)
|
||||
c.Assert(err, IsNil)
|
||||
|
||||
for content := range s3c.List(false) {
|
||||
for content := range s3c.List(false, false) {
|
||||
c.Assert(content.Err, IsNil)
|
||||
c.Assert(content.Content.Name, Equals, "object")
|
||||
c.Assert(content.Content.Type.IsRegular(), Equals, true)
|
||||
|
||||
+1
-1
@@ -63,7 +63,7 @@ func rmList(url string) (<-chan string, *probe.Error) {
|
||||
errorIf(err.Trace(), "Unable to get client object for "+url)
|
||||
return nil, err.Trace()
|
||||
}
|
||||
in := clnt.List(true)
|
||||
in := clnt.List(true, false)
|
||||
out := make(chan string)
|
||||
|
||||
var depthFirst func(currentDir string) (*client.Content, bool)
|
||||
|
||||
@@ -106,7 +106,7 @@ func doShareDownloadURL(targetURL string, recursive bool, expires time.Duration)
|
||||
if expires.Seconds() > 604800 {
|
||||
return probe.NewError(errors.New("Too high expires, expiration cannot be larger than 7 days."))
|
||||
}
|
||||
for contentCh := range clnt.List(recursive) {
|
||||
for contentCh := range clnt.List(recursive, false) {
|
||||
if contentCh.Err != nil {
|
||||
return contentCh.Err.Trace()
|
||||
}
|
||||
|
||||
+1
-1
@@ -76,7 +76,7 @@ func (sl *sortedList) Create(clnt client.Client, id string) *probe.Error {
|
||||
}
|
||||
sl.enc = gob.NewEncoder(sl.file)
|
||||
sl.dec = gob.NewDecoder(sl.file)
|
||||
for content := range clnt.List(true) {
|
||||
for content := range clnt.List(true, false) {
|
||||
if content.Err != nil {
|
||||
switch err := content.Err.ToGoError().(type) {
|
||||
case client.BrokenSymlink:
|
||||
|
||||
+3
-3
@@ -43,9 +43,9 @@ func main() {
|
||||
* [RemoveBucket(bucket) error](examples/removebucket.go)
|
||||
* [GetBucketACL(bucket) (BucketACL, error)](examples/getbucketacl.go)
|
||||
* [SetBucketACL(bucket, BucketACL) error)](examples/setbucketacl.go)
|
||||
* [ListObjects(bucket, prefix, recursive) <-chan ObjectStat](examples/listobjects.go)
|
||||
* [ListBuckets() <-chan BucketStat](examples/listbuckets.go)
|
||||
* [DropAllIncompleteUploads(bucket) <-chan error](examples/dropallincompleteuploads.go)
|
||||
* [ListObjects(bucket, prefix, recursive) <-chan ObjectStat](examples/listobjects.go)
|
||||
* [ListIncompleteUploads(bucket, prefix, recursive) <-chan ObjectMultipartStat](examples/listincompleteuploads.go)
|
||||
|
||||
### Object Level
|
||||
* [PutObject(bucket, object, size, io.Reader) error](examples/putobject.go)
|
||||
@@ -68,4 +68,4 @@ func main() {
|
||||
|
||||
[Contributors Guide](./CONTRIBUTING.md)
|
||||
|
||||
[](https://travis-ci.org/minio/minio-go-legacy) [](https://ci.appveyor.com/project/harshavardhana/minio-go)
|
||||
[](https://travis-ci.org/minio/minio-go-legacy) [](https://ci.appveyor.com/project/harshavardhana/minio-go)
|
||||
|
||||
+147
-58
@@ -53,9 +53,7 @@ type BucketAPI interface {
|
||||
|
||||
ListBuckets() <-chan BucketStatCh
|
||||
ListObjects(bucket, prefix string, recursive bool) <-chan ObjectStatCh
|
||||
|
||||
// Drop all incomplete uploads
|
||||
DropAllIncompleteUploads(bucket string) <-chan error
|
||||
ListIncompleteUploads(bucket, prefix string, recursive bool) <-chan ObjectMultipartStatCh
|
||||
}
|
||||
|
||||
// ObjectAPI - object specific Read/Write/Stat interface
|
||||
@@ -89,6 +87,12 @@ type ObjectStatCh struct {
|
||||
Err error
|
||||
}
|
||||
|
||||
// ObjectMultipartStatCh - multipart object metadata over read channel
|
||||
type ObjectMultipartStatCh struct {
|
||||
Stat ObjectMultipartStat
|
||||
Err error
|
||||
}
|
||||
|
||||
// BucketStat container for bucket metadata
|
||||
type BucketStat struct {
|
||||
// The name of the bucket.
|
||||
@@ -114,6 +118,24 @@ type ObjectStat struct {
|
||||
StorageClass string
|
||||
}
|
||||
|
||||
// ObjectMultipartStat container for multipart object metadata
|
||||
type ObjectMultipartStat struct {
|
||||
// Date and time at which the multipart upload was initiated.
|
||||
Initiated time.Time `type:"timestamp" timestampFormat:"iso8601"`
|
||||
|
||||
Initiator initiator
|
||||
Owner owner
|
||||
|
||||
StorageClass string
|
||||
|
||||
// Key of the object for which the multipart upload was initiated.
|
||||
Key string
|
||||
Size int64
|
||||
|
||||
// Upload ID that identifies the multipart upload.
|
||||
UploadID string `xml:"UploadId"`
|
||||
}
|
||||
|
||||
// Regions s3 region map used by bucket location constraint
|
||||
var regions = map[string]string{
|
||||
"s3-fips-us-gov-west-1.amazonaws.com": "us-gov-west-1",
|
||||
@@ -448,6 +470,17 @@ func (a api) listObjectPartsRecursiveInRoutine(bucket, object, uploadID string,
|
||||
}
|
||||
}
|
||||
|
||||
func (a api) getMultipartSize(bucket, object, uploadID string) (int64, error) {
|
||||
var size int64
|
||||
for part := range a.listObjectPartsRecursive(bucket, object, uploadID) {
|
||||
if part.Err != nil {
|
||||
return 0, part.Err
|
||||
}
|
||||
size += part.Metadata.Size
|
||||
}
|
||||
return size, nil
|
||||
}
|
||||
|
||||
func (a api) continueObjectUpload(bucket, object, uploadID string, size int64, data io.Reader) error {
|
||||
var skipParts []skipPart
|
||||
completeMultipartUpload := completeMultipartUpload{}
|
||||
@@ -531,7 +564,7 @@ func (a api) continueObjectUpload(bucket, object, uploadID string, size int64, d
|
||||
}
|
||||
|
||||
type multiPartUploadCh struct {
|
||||
Metadata multiPartUpload
|
||||
Metadata ObjectMultipartStat
|
||||
Err error
|
||||
}
|
||||
|
||||
@@ -546,7 +579,7 @@ func (a api) listMultipartUploadsRecursiveInRoutine(bucket, object string, ch ch
|
||||
listMultipartUplResult, err := a.listMultipartUploads(bucket, "", "", object, "", 1000)
|
||||
if err != nil {
|
||||
ch <- multiPartUploadCh{
|
||||
Metadata: multiPartUpload{},
|
||||
Metadata: ObjectMultipartStat{},
|
||||
Err: err,
|
||||
}
|
||||
return
|
||||
@@ -565,7 +598,7 @@ func (a api) listMultipartUploadsRecursiveInRoutine(bucket, object string, ch ch
|
||||
listMultipartUplResult.NextKeyMarker, listMultipartUplResult.NextUploadIDMarker, object, "", 1000)
|
||||
if err != nil {
|
||||
ch <- multiPartUploadCh{
|
||||
Metadata: multiPartUpload{},
|
||||
Metadata: ObjectMultipartStat{},
|
||||
Err: err,
|
||||
}
|
||||
return
|
||||
@@ -789,6 +822,113 @@ func (a api) RemoveBucket(bucket string) error {
|
||||
return a.deleteBucket(bucket)
|
||||
}
|
||||
|
||||
// listIncompleteUploadsInRoutine is an internal goroutine function called for listing objects
|
||||
// This function feeds data into channel
|
||||
func (a api) listIncompleteUploadsInRoutine(bucket, prefix string, recursive bool, ch chan ObjectMultipartStatCh) {
|
||||
defer close(ch)
|
||||
if err := invalidBucketError(bucket); err != nil {
|
||||
ch <- ObjectMultipartStatCh{
|
||||
Stat: ObjectMultipartStat{},
|
||||
Err: err,
|
||||
}
|
||||
return
|
||||
}
|
||||
switch {
|
||||
case recursive == true:
|
||||
var multipartMarker string
|
||||
var uploadIDMarker string
|
||||
for {
|
||||
result, err := a.listMultipartUploads(bucket, multipartMarker, uploadIDMarker, prefix, "", 1000)
|
||||
if err != nil {
|
||||
ch <- ObjectMultipartStatCh{
|
||||
Stat: ObjectMultipartStat{},
|
||||
Err: err,
|
||||
}
|
||||
return
|
||||
}
|
||||
for _, objectSt := range result.Uploads {
|
||||
objectSt.Size, err = a.getMultipartSize(bucket, objectSt.Key, objectSt.UploadID)
|
||||
if err != nil {
|
||||
ch <- ObjectMultipartStatCh{
|
||||
Stat: ObjectMultipartStat{},
|
||||
Err: err,
|
||||
}
|
||||
}
|
||||
ch <- ObjectMultipartStatCh{
|
||||
Stat: objectSt,
|
||||
Err: nil,
|
||||
}
|
||||
multipartMarker = result.NextKeyMarker
|
||||
uploadIDMarker = result.NextUploadIDMarker
|
||||
}
|
||||
if !result.IsTruncated {
|
||||
break
|
||||
}
|
||||
}
|
||||
default:
|
||||
var multipartMarker string
|
||||
var uploadIDMarker string
|
||||
for {
|
||||
result, err := a.listMultipartUploads(bucket, multipartMarker, uploadIDMarker, prefix, "/", 1000)
|
||||
if err != nil {
|
||||
ch <- ObjectMultipartStatCh{
|
||||
Stat: ObjectMultipartStat{},
|
||||
Err: err,
|
||||
}
|
||||
return
|
||||
}
|
||||
multipartMarker = result.NextKeyMarker
|
||||
uploadIDMarker = result.NextUploadIDMarker
|
||||
for _, objectSt := range result.Uploads {
|
||||
objectSt.Size, err = a.getMultipartSize(bucket, objectSt.Key, objectSt.UploadID)
|
||||
if err != nil {
|
||||
ch <- ObjectMultipartStatCh{
|
||||
Stat: ObjectMultipartStat{},
|
||||
Err: err,
|
||||
}
|
||||
}
|
||||
ch <- ObjectMultipartStatCh{
|
||||
Stat: objectSt,
|
||||
Err: nil,
|
||||
}
|
||||
}
|
||||
for _, prefix := range result.CommonPrefixes {
|
||||
object := ObjectMultipartStat{}
|
||||
object.Key = prefix.Prefix
|
||||
object.Size = 0
|
||||
ch <- ObjectMultipartStatCh{
|
||||
Stat: object,
|
||||
Err: nil,
|
||||
}
|
||||
}
|
||||
if !result.IsTruncated {
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// ListIncompleteUploads - (List incompletely uploaded multipart objects) - List some multipart objects or all recursively
|
||||
//
|
||||
// ListIncompleteUploads is a channel based API implemented to facilitate ease of usage of S3 API ListMultipartUploads()
|
||||
// by automatically recursively traversing all multipart objects on a given bucket if specified.
|
||||
//
|
||||
// Your input paramters are just bucket, prefix and recursive
|
||||
//
|
||||
// If you enable recursive as 'true' this function will return back all the multipart objects in a given bucket
|
||||
//
|
||||
// eg:-
|
||||
// api := client.New(....)
|
||||
// for message := range api.ListIncompleteUploads("mytestbucket", "starthere", true) {
|
||||
// fmt.Println(message.Stat)
|
||||
// }
|
||||
//
|
||||
func (a api) ListIncompleteUploads(bucket, prefix string, recursive bool) <-chan ObjectMultipartStatCh {
|
||||
ch := make(chan ObjectMultipartStatCh, 1000)
|
||||
go a.listIncompleteUploadsInRoutine(bucket, prefix, recursive, ch)
|
||||
return ch
|
||||
}
|
||||
|
||||
// listObjectsInRoutine is an internal goroutine function called for listing objects
|
||||
// This function feeds data into channel
|
||||
func (a api) listObjectsInRoutine(bucket, prefix string, recursive bool, ch chan ObjectStatCh) {
|
||||
@@ -966,61 +1106,10 @@ func (a api) dropIncompleteUploadInRoutine(bucket, object string, errorCh chan e
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
//
|
||||
// NOTE:
|
||||
// These set of calls require explicit authentication, no anonymous
|
||||
// requests are allowed for multipart API
|
||||
|
||||
// DropIncompleteUpload - abort a specific in progress active multipart upload
|
||||
// requires explicit authentication, no anonymous requests are allowed for multipart API
|
||||
func (a api) DropIncompleteUpload(bucket, object string) <-chan error {
|
||||
errorCh := make(chan error)
|
||||
go a.dropIncompleteUploadInRoutine(bucket, object, errorCh)
|
||||
return errorCh
|
||||
}
|
||||
|
||||
func (a api) dropAllIncompleteUploadsInRoutine(bucket string, errorCh chan error) {
|
||||
defer close(errorCh)
|
||||
if err := invalidBucketError(bucket); err != nil {
|
||||
errorCh <- err
|
||||
return
|
||||
}
|
||||
listMultipartUplResult, err := a.listMultipartUploads(bucket, "", "", "", "", 1000)
|
||||
if err != nil {
|
||||
errorCh <- err
|
||||
return
|
||||
}
|
||||
for _, multiPartUpload := range listMultipartUplResult.Uploads {
|
||||
err := a.abortMultipartUpload(bucket, multiPartUpload.Key, multiPartUpload.UploadID)
|
||||
if err != nil {
|
||||
errorCh <- err
|
||||
return
|
||||
}
|
||||
}
|
||||
for {
|
||||
if !listMultipartUplResult.IsTruncated {
|
||||
break
|
||||
}
|
||||
listMultipartUplResult, err = a.listMultipartUploads(bucket,
|
||||
listMultipartUplResult.NextKeyMarker, listMultipartUplResult.NextUploadIDMarker, "", "", 1000)
|
||||
if err != nil {
|
||||
errorCh <- err
|
||||
return
|
||||
}
|
||||
for _, multiPartUpload := range listMultipartUplResult.Uploads {
|
||||
err := a.abortMultipartUpload(bucket, multiPartUpload.Key, multiPartUpload.UploadID)
|
||||
if err != nil {
|
||||
errorCh <- err
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
// DropAllIncompleteUploads - abort all inprogress active multipart uploads
|
||||
func (a api) DropAllIncompleteUploads(bucket string) <-chan error {
|
||||
errorCh := make(chan error)
|
||||
go a.dropAllIncompleteUploadsInRoutine(bucket, errorCh)
|
||||
return errorCh
|
||||
}
|
||||
|
||||
+3
-3
@@ -14,9 +14,9 @@ environment:
|
||||
# scripts that run after cloning repository
|
||||
install:
|
||||
- set PATH=%GOPATH%\bin;c:\go\bin;%PATH%
|
||||
- rmdir c:\go /s /q
|
||||
- appveyor DownloadFile https://storage.googleapis.com/golang/go1.5.1.windows-amd64.msi
|
||||
- msiexec /i go1.5.1.windows-amd64.msi /q
|
||||
- rd C:\Go /s /q
|
||||
- appveyor DownloadFile https://storage.googleapis.com/golang/go1.5.1.windows-amd64.zip
|
||||
- 7z x go1.5.1.windows-amd64.zip -oC:\ >nul
|
||||
- go version
|
||||
- go env
|
||||
- go get -u github.com/golang/lint/golint
|
||||
|
||||
+1
-18
@@ -68,23 +68,6 @@ type listBucketResult struct {
|
||||
Prefix string
|
||||
}
|
||||
|
||||
// multiPartUpload container for multipart session
|
||||
type multiPartUpload struct {
|
||||
// Date and time at which the multipart upload was initiated.
|
||||
Initiated time.Time `type:"timestamp" timestampFormat:"iso8601"`
|
||||
|
||||
Initiator initiator
|
||||
Owner owner
|
||||
|
||||
StorageClass string
|
||||
|
||||
// Key of the object for which the multipart upload was initiated.
|
||||
Key string
|
||||
|
||||
// Upload ID that identifies the multipart upload.
|
||||
UploadID string `xml:"UploadId"`
|
||||
}
|
||||
|
||||
// listMultipartUploadsResult container for ListMultipartUploads response
|
||||
type listMultipartUploadsResult struct {
|
||||
Bucket string
|
||||
@@ -95,7 +78,7 @@ type listMultipartUploadsResult struct {
|
||||
EncodingType string
|
||||
MaxUploads int64
|
||||
IsTruncated bool
|
||||
Uploads []multiPartUpload `xml:"Upload"`
|
||||
Uploads []ObjectMultipartStat `xml:"Upload"`
|
||||
Prefix string
|
||||
Delimiter string
|
||||
CommonPrefixes []commonPrefix // A response can contain CommonPrefixes only if you specify a delimiter
|
||||
|
||||
+2
-2
@@ -43,9 +43,9 @@ func main() {
|
||||
* [RemoveBucket(bucket) error](examples/s3/removebucket.go)
|
||||
* [GetBucketACL(bucket) (BucketACL, error)](examples/s3/getbucketacl.go)
|
||||
* [SetBucketACL(bucket, BucketACL) error)](examples/s3/setbucketacl.go)
|
||||
* [ListObjects(bucket, prefix, recursive) <-chan ObjectStat](examples/s3/listobjects.go)
|
||||
* [ListBuckets() <-chan BucketStat](examples/s3/listbuckets.go)
|
||||
* [DropAllIncompleteUploads(bucket) <-chan error](examples/s3/dropallincompleteuploads.go)
|
||||
* [ListObjects(bucket, prefix, recursive) <-chan ObjectStat](examples/s3/listobjects.go)
|
||||
* [ListIncompleteUploads(bucket, prefix, recursive) <-chan ObjectMultipartStat](examples/s3/listincompleteuploads.go)
|
||||
* [DropIncompleteUpload(bucket, object) <-chan error](examples/s3/dropincompleteuploads.go)
|
||||
|
||||
### Object Level
|
||||
|
||||
+193
-105
@@ -53,9 +53,7 @@ type BucketAPI interface {
|
||||
|
||||
ListBuckets() <-chan BucketStatCh
|
||||
ListObjects(bucket, prefix string, recursive bool) <-chan ObjectStatCh
|
||||
|
||||
// Drop all incomplete uploads
|
||||
DropAllIncompleteUploads(bucket string) <-chan error
|
||||
ListIncompleteUploads(bucket, prefix string, recursive bool) <-chan ObjectMultipartStatCh
|
||||
}
|
||||
|
||||
// ObjectAPI - object specific Read/Write/Stat interface
|
||||
@@ -89,6 +87,12 @@ type ObjectStatCh struct {
|
||||
Err error
|
||||
}
|
||||
|
||||
// ObjectMultipartStatCh - multipart object metadata over read channel
|
||||
type ObjectMultipartStatCh struct {
|
||||
Stat ObjectMultipartStat
|
||||
Err error
|
||||
}
|
||||
|
||||
// BucketStat container for bucket metadata
|
||||
type BucketStat struct {
|
||||
// The name of the bucket.
|
||||
@@ -114,6 +118,24 @@ type ObjectStat struct {
|
||||
StorageClass string
|
||||
}
|
||||
|
||||
// ObjectMultipartStat container for multipart object metadata
|
||||
type ObjectMultipartStat struct {
|
||||
// Date and time at which the multipart upload was initiated.
|
||||
Initiated time.Time `type:"timestamp" timestampFormat:"iso8601"`
|
||||
|
||||
Initiator initiator
|
||||
Owner owner
|
||||
|
||||
StorageClass string
|
||||
|
||||
// Key of the object for which the multipart upload was initiated.
|
||||
Key string
|
||||
Size int64
|
||||
|
||||
// Upload ID that identifies the multipart upload.
|
||||
UploadID string `xml:"UploadId"`
|
||||
}
|
||||
|
||||
// Regions s3 region map used by bucket location constraint
|
||||
var regions = map[string]string{
|
||||
"s3-fips-us-gov-west-1.amazonaws.com": "us-gov-west-1",
|
||||
@@ -435,6 +457,17 @@ func (a api) listObjectPartsRecursiveInRoutine(bucket, object, uploadID string,
|
||||
}
|
||||
}
|
||||
|
||||
func (a api) getMultipartSize(bucket, object, uploadID string) (int64, error) {
|
||||
var size int64
|
||||
for part := range a.listObjectPartsRecursive(bucket, object, uploadID) {
|
||||
if part.Err != nil {
|
||||
return 0, part.Err
|
||||
}
|
||||
size += part.Metadata.Size
|
||||
}
|
||||
return size, nil
|
||||
}
|
||||
|
||||
func (a api) continueObjectUpload(bucket, object, uploadID string, size int64, data io.Reader) error {
|
||||
var skipParts []skipPart
|
||||
completeMultipartUpload := completeMultipartUpload{}
|
||||
@@ -517,55 +550,6 @@ func (a api) continueObjectUpload(bucket, object, uploadID string, size int64, d
|
||||
return nil
|
||||
}
|
||||
|
||||
type multiPartUploadCh struct {
|
||||
Metadata multiPartUpload
|
||||
Err error
|
||||
}
|
||||
|
||||
func (a api) listMultipartUploadsRecursive(bucket, object string) <-chan multiPartUploadCh {
|
||||
ch := make(chan multiPartUploadCh, 1000)
|
||||
go a.listMultipartUploadsRecursiveInRoutine(bucket, object, ch)
|
||||
return ch
|
||||
}
|
||||
|
||||
func (a api) listMultipartUploadsRecursiveInRoutine(bucket, object string, ch chan multiPartUploadCh) {
|
||||
defer close(ch)
|
||||
listMultipartUplResult, err := a.listMultipartUploads(bucket, "", "", object, "", 1000)
|
||||
if err != nil {
|
||||
ch <- multiPartUploadCh{
|
||||
Metadata: multiPartUpload{},
|
||||
Err: err,
|
||||
}
|
||||
return
|
||||
}
|
||||
for _, multiPartUpload := range listMultipartUplResult.Uploads {
|
||||
ch <- multiPartUploadCh{
|
||||
Metadata: multiPartUpload,
|
||||
Err: nil,
|
||||
}
|
||||
}
|
||||
for {
|
||||
if !listMultipartUplResult.IsTruncated {
|
||||
break
|
||||
}
|
||||
listMultipartUplResult, err = a.listMultipartUploads(bucket,
|
||||
listMultipartUplResult.NextKeyMarker, listMultipartUplResult.NextUploadIDMarker, object, "", 1000)
|
||||
if err != nil {
|
||||
ch <- multiPartUploadCh{
|
||||
Metadata: multiPartUpload{},
|
||||
Err: err,
|
||||
}
|
||||
return
|
||||
}
|
||||
for _, multiPartUpload := range listMultipartUplResult.Uploads {
|
||||
ch <- multiPartUploadCh{
|
||||
Metadata: multiPartUpload,
|
||||
Err: nil,
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// PresignedPostPolicy return POST form data that can be used for object upload
|
||||
func (a api) PresignedPostPolicy(p *PostPolicy) (map[string]string, error) {
|
||||
if p.expiration.IsZero() {
|
||||
@@ -790,6 +774,162 @@ func (a api) RemoveBucket(bucket string) error {
|
||||
return a.deleteBucket(bucket)
|
||||
}
|
||||
|
||||
type multiPartUploadCh struct {
|
||||
Metadata ObjectMultipartStat
|
||||
Err error
|
||||
}
|
||||
|
||||
func (a api) listMultipartUploadsRecursive(bucket, object string) <-chan multiPartUploadCh {
|
||||
ch := make(chan multiPartUploadCh, 1000)
|
||||
go a.listMultipartUploadsRecursiveInRoutine(bucket, object, ch)
|
||||
return ch
|
||||
}
|
||||
|
||||
func (a api) listMultipartUploadsRecursiveInRoutine(bucket, object string, ch chan multiPartUploadCh) {
|
||||
defer close(ch)
|
||||
listMultipartUplResult, err := a.listMultipartUploads(bucket, "", "", object, "", 1000)
|
||||
if err != nil {
|
||||
ch <- multiPartUploadCh{
|
||||
Metadata: ObjectMultipartStat{},
|
||||
Err: err,
|
||||
}
|
||||
return
|
||||
}
|
||||
for _, multiPartUpload := range listMultipartUplResult.Uploads {
|
||||
ch <- multiPartUploadCh{
|
||||
Metadata: multiPartUpload,
|
||||
Err: nil,
|
||||
}
|
||||
}
|
||||
for {
|
||||
if !listMultipartUplResult.IsTruncated {
|
||||
break
|
||||
}
|
||||
listMultipartUplResult, err = a.listMultipartUploads(bucket,
|
||||
listMultipartUplResult.NextKeyMarker, listMultipartUplResult.NextUploadIDMarker, object, "", 1000)
|
||||
if err != nil {
|
||||
ch <- multiPartUploadCh{
|
||||
Metadata: ObjectMultipartStat{},
|
||||
Err: err,
|
||||
}
|
||||
return
|
||||
}
|
||||
for _, multiPartUpload := range listMultipartUplResult.Uploads {
|
||||
ch <- multiPartUploadCh{
|
||||
Metadata: multiPartUpload,
|
||||
Err: nil,
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// listIncompleteUploadsInRoutine is an internal goroutine function called for listing objects
|
||||
// This function feeds data into channel
|
||||
func (a api) listIncompleteUploadsInRoutine(bucket, prefix string, recursive bool, ch chan ObjectMultipartStatCh) {
|
||||
defer close(ch)
|
||||
if err := invalidBucketError(bucket); err != nil {
|
||||
ch <- ObjectMultipartStatCh{
|
||||
Stat: ObjectMultipartStat{},
|
||||
Err: err,
|
||||
}
|
||||
return
|
||||
}
|
||||
switch {
|
||||
case recursive == true:
|
||||
var multipartMarker string
|
||||
var uploadIDMarker string
|
||||
for {
|
||||
result, err := a.listMultipartUploads(bucket, multipartMarker, uploadIDMarker, prefix, "", 1000)
|
||||
if err != nil {
|
||||
ch <- ObjectMultipartStatCh{
|
||||
Stat: ObjectMultipartStat{},
|
||||
Err: err,
|
||||
}
|
||||
return
|
||||
}
|
||||
for _, objectSt := range result.Uploads {
|
||||
objectSt.Size, err = a.getMultipartSize(bucket, objectSt.Key, objectSt.UploadID)
|
||||
if err != nil {
|
||||
ch <- ObjectMultipartStatCh{
|
||||
Stat: ObjectMultipartStat{},
|
||||
Err: err,
|
||||
}
|
||||
}
|
||||
ch <- ObjectMultipartStatCh{
|
||||
Stat: objectSt,
|
||||
Err: nil,
|
||||
}
|
||||
multipartMarker = result.NextKeyMarker
|
||||
uploadIDMarker = result.NextUploadIDMarker
|
||||
}
|
||||
if !result.IsTruncated {
|
||||
break
|
||||
}
|
||||
}
|
||||
default:
|
||||
var multipartMarker string
|
||||
var uploadIDMarker string
|
||||
for {
|
||||
result, err := a.listMultipartUploads(bucket, multipartMarker, uploadIDMarker, prefix, "/", 1000)
|
||||
if err != nil {
|
||||
ch <- ObjectMultipartStatCh{
|
||||
Stat: ObjectMultipartStat{},
|
||||
Err: err,
|
||||
}
|
||||
return
|
||||
}
|
||||
multipartMarker = result.NextKeyMarker
|
||||
uploadIDMarker = result.NextUploadIDMarker
|
||||
for _, objectSt := range result.Uploads {
|
||||
objectSt.Size, err = a.getMultipartSize(bucket, objectSt.Key, objectSt.UploadID)
|
||||
if err != nil {
|
||||
ch <- ObjectMultipartStatCh{
|
||||
Stat: ObjectMultipartStat{},
|
||||
Err: err,
|
||||
}
|
||||
}
|
||||
ch <- ObjectMultipartStatCh{
|
||||
Stat: objectSt,
|
||||
Err: nil,
|
||||
}
|
||||
}
|
||||
for _, prefix := range result.CommonPrefixes {
|
||||
object := ObjectMultipartStat{}
|
||||
object.Key = prefix.Prefix
|
||||
object.Size = 0
|
||||
ch <- ObjectMultipartStatCh{
|
||||
Stat: object,
|
||||
Err: nil,
|
||||
}
|
||||
}
|
||||
if !result.IsTruncated {
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// ListIncompleteUploads - (List incompletely uploaded multipart objects) - List some multipart objects or all recursively
|
||||
//
|
||||
// ListIncompleteUploads is a channel based API implemented to facilitate ease of usage of S3 API ListMultipartUploads()
|
||||
// by automatically recursively traversing all multipart objects on a given bucket if specified.
|
||||
//
|
||||
// Your input paramters are just bucket, prefix and recursive
|
||||
//
|
||||
// If you enable recursive as 'true' this function will return back all the multipart objects in a given bucket
|
||||
//
|
||||
// eg:-
|
||||
// api := client.New(....)
|
||||
// for message := range api.ListIncompleteUploads("mytestbucket", "starthere", true) {
|
||||
// fmt.Println(message.Stat)
|
||||
// }
|
||||
//
|
||||
func (a api) ListIncompleteUploads(bucket, prefix string, recursive bool) <-chan ObjectMultipartStatCh {
|
||||
ch := make(chan ObjectMultipartStatCh, 1000)
|
||||
go a.listIncompleteUploadsInRoutine(bucket, prefix, recursive, ch)
|
||||
return ch
|
||||
}
|
||||
|
||||
// listObjectsInRoutine is an internal goroutine function called for listing objects
|
||||
// This function feeds data into channel
|
||||
func (a api) listObjectsInRoutine(bucket, prefix string, recursive bool, ch chan ObjectStatCh) {
|
||||
@@ -897,7 +1037,6 @@ func (a api) listBucketsInRoutine(ch chan BucketStatCh) {
|
||||
Err: nil,
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// ListBuckets list of all buckets owned by the authenticated sender of the request
|
||||
@@ -967,61 +1106,10 @@ func (a api) dropIncompleteUploadInRoutine(bucket, object string, errorCh chan e
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
//
|
||||
// NOTE:
|
||||
// These set of calls require explicit authentication, no anonymous
|
||||
// requests are allowed for multipart API
|
||||
|
||||
// DropIncompleteUpload - abort a specific in progress active multipart upload
|
||||
// requires explicit authentication, no anonymous requests are allowed for multipart API
|
||||
func (a api) DropIncompleteUpload(bucket, object string) <-chan error {
|
||||
errorCh := make(chan error)
|
||||
go a.dropIncompleteUploadInRoutine(bucket, object, errorCh)
|
||||
return errorCh
|
||||
}
|
||||
|
||||
func (a api) dropAllIncompleteUploadsInRoutine(bucket string, errorCh chan error) {
|
||||
defer close(errorCh)
|
||||
if err := invalidBucketError(bucket); err != nil {
|
||||
errorCh <- err
|
||||
return
|
||||
}
|
||||
listMultipartUplResult, err := a.listMultipartUploads(bucket, "", "", "", "", 1000)
|
||||
if err != nil {
|
||||
errorCh <- err
|
||||
return
|
||||
}
|
||||
for _, multiPartUpload := range listMultipartUplResult.Uploads {
|
||||
err := a.abortMultipartUpload(bucket, multiPartUpload.Key, multiPartUpload.UploadID)
|
||||
if err != nil {
|
||||
errorCh <- err
|
||||
return
|
||||
}
|
||||
}
|
||||
for {
|
||||
if !listMultipartUplResult.IsTruncated {
|
||||
break
|
||||
}
|
||||
listMultipartUplResult, err = a.listMultipartUploads(bucket,
|
||||
listMultipartUplResult.NextKeyMarker, listMultipartUplResult.NextUploadIDMarker, "", "", 1000)
|
||||
if err != nil {
|
||||
errorCh <- err
|
||||
return
|
||||
}
|
||||
for _, multiPartUpload := range listMultipartUplResult.Uploads {
|
||||
err := a.abortMultipartUpload(bucket, multiPartUpload.Key, multiPartUpload.UploadID)
|
||||
if err != nil {
|
||||
errorCh <- err
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
// DropAllIncompleteUploads - abort all inprogress active multipart uploads
|
||||
func (a api) DropAllIncompleteUploads(bucket string) <-chan error {
|
||||
errorCh := make(chan error)
|
||||
go a.dropAllIncompleteUploadsInRoutine(bucket, errorCh)
|
||||
return errorCh
|
||||
}
|
||||
|
||||
+3
-3
@@ -14,9 +14,9 @@ environment:
|
||||
# scripts that run after cloning repository
|
||||
install:
|
||||
- set PATH=%GOPATH%\bin;c:\go\bin;%PATH%
|
||||
- rmdir c:\go /s /q
|
||||
- appveyor DownloadFile https://storage.googleapis.com/golang/go1.5.1.windows-amd64.msi
|
||||
- msiexec /i go1.5.1.windows-amd64.msi /q
|
||||
- rd C:\Go /s /q
|
||||
- appveyor DownloadFile https://storage.googleapis.com/golang/go1.5.1.windows-amd64.zip
|
||||
- 7z x go1.5.1.windows-amd64.zip -oC:\ >nul
|
||||
- go version
|
||||
- go env
|
||||
- go get -u github.com/golang/lint/golint
|
||||
|
||||
+1
-18
@@ -68,23 +68,6 @@ type listBucketResult struct {
|
||||
Prefix string
|
||||
}
|
||||
|
||||
// multiPartUpload container for multipart session
|
||||
type multiPartUpload struct {
|
||||
// Date and time at which the multipart upload was initiated.
|
||||
Initiated time.Time `type:"timestamp" timestampFormat:"iso8601"`
|
||||
|
||||
Initiator initiator
|
||||
Owner owner
|
||||
|
||||
StorageClass string
|
||||
|
||||
// Key of the object for which the multipart upload was initiated.
|
||||
Key string
|
||||
|
||||
// Upload ID that identifies the multipart upload.
|
||||
UploadID string `xml:"UploadId"`
|
||||
}
|
||||
|
||||
// listMultipartUploadsResult container for ListMultipartUploads response
|
||||
type listMultipartUploadsResult struct {
|
||||
Bucket string
|
||||
@@ -95,7 +78,7 @@ type listMultipartUploadsResult struct {
|
||||
EncodingType string
|
||||
MaxUploads int64
|
||||
IsTruncated bool
|
||||
Uploads []multiPartUpload `xml:"Upload"`
|
||||
Uploads []ObjectMultipartStat `xml:"Upload"`
|
||||
Prefix string
|
||||
Delimiter string
|
||||
CommonPrefixes []commonPrefix // A response can contain CommonPrefixes only if you specify a delimiter
|
||||
|
||||
Vendored
+4
-4
@@ -29,13 +29,13 @@
|
||||
},
|
||||
{
|
||||
"path": "github.com/minio/minio-go",
|
||||
"revision": "4f7eabdfdaa652a3f329f163361042e0def4ac89",
|
||||
"revisionTime": "2015-10-17T10:23:30-07:00"
|
||||
"revision": "c1f2d26734709729b0a3e20262ea6ecf8e4a3606",
|
||||
"revisionTime": "2015-10-19T19:40:25-07:00"
|
||||
},
|
||||
{
|
||||
"path": "github.com/minio/minio-go-legacy",
|
||||
"revision": "58eb2eb70a67819d2ea5a9e2a8f6c10bee164efc",
|
||||
"revisionTime": "2015-10-17T10:22:58-07:00"
|
||||
"revision": "9c6317ea5db59384f3d4ff493e790e61950fe958",
|
||||
"revisionTime": "2015-10-19T19:40:01-07:00"
|
||||
},
|
||||
{
|
||||
"path": "github.com/minio/minio-xl/pkg/probe",
|
||||
|
||||
Reference in New Issue
Block a user