From 9480f8c9ae2934d63cea43dc54c4bc55b42b38ed Mon Sep 17 00:00:00 2001 From: Harshavardhana Date: Wed, 11 Nov 2015 21:35:29 -0800 Subject: [PATCH] rm/ls: Remove and List incomplete uploads properly Fixes #1271 --- pkg/client/s3/s3.go | 41 +++++++++++++++++++++++++++++++---------- 1 file changed, 31 insertions(+), 10 deletions(-) diff --git a/pkg/client/s3/s3.go b/pkg/client/s3/s3.go index 3dae0656..782b3cea 100644 --- a/pkg/client/s3/s3.go +++ b/pkg/client/s3/s3.go @@ -340,16 +340,37 @@ func (c *s3Client) listIncompleteInRoutine(contentCh chan client.ContentOnChanne } return } - url := *c.hostURL - url.Path = filepath.Join(url.Path, bucket.Stat.Name) - content := new(client.Content) - content.URL = url - content.Size = 0 - content.Time = bucket.Stat.CreationDate - content.Type = os.ModeDir - contentCh <- client.ContentOnChannel{ - Content: content, - Err: nil, + for object := range c.api.ListIncompleteUploads(bucket.Stat.Name, o, false) { + if object.Err != nil { + contentCh <- client.ContentOnChannel{ + Content: nil, + Err: probe.NewError(object.Err), + } + return + } + content := new(client.Content) + url := *c.hostURL + // join bucket with - incoming object key + url.Path = filepath.Join(string(url.Separator), bucket.Stat.Name, object.Stat.Key) + if c.virtualStyle { + url.Path = filepath.Join(string(url.Separator), object.Stat.Key) + } + switch { + case strings.HasSuffix(object.Stat.Key, string(c.hostURL.Separator)): + // We need to keep the trailing Separator, do not use filepath.Join() + content.URL = url + content.Time = time.Now() + content.Type = os.ModeDir + default: + content.URL = url + content.Size = object.Stat.Size + content.Time = object.Stat.Initiated + content.Type = os.ModeTemporary + } + contentCh <- client.ContentOnChannel{ + Content: content, + Err: nil, + } } } default: