Merge pull request #518 from harshavardhana/pr_out_migrate_fully_to_list_with_channel_everywhere_deprecate_old_list_api
This commit is contained in:
+9
-7
@@ -37,19 +37,21 @@ func doCopyCmdRecursive(manager clientManager, sourceURLConfigMap map[string]*ho
|
||||
if err != nil {
|
||||
return fmt.Sprintf("instantiating a new client for URL [%s]", sourceURL), iodine.New(err, nil)
|
||||
}
|
||||
items, err := clnt.List()
|
||||
if err != nil {
|
||||
return fmt.Sprintf("listing objects failed for URL [%s]", sourceURL), iodine.New(err, nil)
|
||||
}
|
||||
for _, item := range items {
|
||||
for itemCh := range clnt.List() {
|
||||
if itemCh.Err != nil {
|
||||
return fmt.Sprintf("listing objects failed for URL [%s]", sourceURL), iodine.New(itemCh.Err, nil)
|
||||
}
|
||||
if itemCh.Item.FileType.IsDir() {
|
||||
continue
|
||||
}
|
||||
// populate source urls
|
||||
sourceURLs := make(map[string]*hostConfig)
|
||||
sourceObjectURL := strings.TrimSuffix(sourceURL, pathSeparator) + pathSeparator + item.Name
|
||||
sourceObjectURL := itemCh.Item.Name
|
||||
sourceURLs[sourceObjectURL] = sourceConfig
|
||||
// populate target urls
|
||||
targetURLs := make(map[string]*hostConfig)
|
||||
for targetURL, targetConfig := range targetURLConfigMap {
|
||||
targetObjectURL := strings.TrimSuffix(targetURL, pathSeparator) + pathSeparator + item.Name
|
||||
targetObjectURL := strings.TrimSuffix(targetURL, pathSeparator) + pathSeparator + itemCh.Item.Name
|
||||
targetURLs[targetObjectURL] = targetConfig
|
||||
}
|
||||
humanReadable, err := doCopyCmd(manager, sourceURLs, targetURLs)
|
||||
|
||||
@@ -33,16 +33,6 @@ const (
|
||||
printDate = "2006-01-02 15:04:05 MST"
|
||||
)
|
||||
|
||||
// printItems prints a metadata of a list of items
|
||||
func printItems(v []*client.Item) {
|
||||
if len(v) > 0 {
|
||||
// Items are already sorted
|
||||
for _, b := range v {
|
||||
printItem(b.Time, b.Size, b.Name)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// printItem prints item meta-data
|
||||
func printItem(date time.Time, v int64, name string) {
|
||||
fmt.Printf(console.Time("[%s] ", date.Local().Format(printDate)))
|
||||
@@ -52,12 +42,12 @@ func printItem(date time.Time, v int64, name string) {
|
||||
|
||||
func doList(clnt client.Client, targetURL string) (string, error) {
|
||||
var err error
|
||||
for itemOnChannel := range clnt.ListOnChannel() {
|
||||
if itemOnChannel.Err != nil {
|
||||
err = itemOnChannel.Err
|
||||
for itemCh := range clnt.List() {
|
||||
if itemCh.Err != nil {
|
||||
err = itemCh.Err
|
||||
break
|
||||
}
|
||||
printItem(itemOnChannel.Item.Time, itemOnChannel.Item.Size, itemOnChannel.Item.Name)
|
||||
printItem(itemCh.Item.Time, itemCh.Item.Size, itemCh.Item.Name)
|
||||
}
|
||||
if err != nil {
|
||||
err = iodine.New(err, nil)
|
||||
|
||||
+16
-6
@@ -147,12 +147,22 @@ func (s *CmdTestSuite) TestCopyRecursive(c *C) {
|
||||
targetURLConfigMap[targetURL] = targetConfig
|
||||
|
||||
manager.On("getNewClient", sourceURL, sourceConfig, false).Return(cl1, nil).Once()
|
||||
cl1.On("List").Return(items, nil).Once()
|
||||
itemCh := make(chan client.ItemOnChannel)
|
||||
go func() {
|
||||
defer close(itemCh)
|
||||
for _, item := range items {
|
||||
itemCh <- client.ItemOnChannel{
|
||||
Item: item,
|
||||
Err: nil,
|
||||
}
|
||||
}
|
||||
}()
|
||||
cl1.On("List").Return(itemCh).Once()
|
||||
sourceReader1 := ioutil.NopCloser(bytes.NewBufferString(data1))
|
||||
sourceReader2 := ioutil.NopCloser(bytes.NewBufferString(data2))
|
||||
manager.On("getSourceReader", sourceURL+"hello1", sourceConfig).Return(sourceReader1, dataLen1, etag1, nil).Once()
|
||||
manager.On("getSourceReader", "hello1", sourceConfig).Return(sourceReader1, dataLen1, etag1, nil).Once()
|
||||
manager.On("getTargetWriter", targetURL+"hello1", targetConfig, etag1, dataLen1).Return(writer1, nil).Once()
|
||||
manager.On("getSourceReader", sourceURL+"hello2", sourceConfig).Return(sourceReader2, dataLen2, etag2, nil).Once()
|
||||
manager.On("getSourceReader", "hello2", sourceConfig).Return(sourceReader2, dataLen2, etag2, nil).Once()
|
||||
manager.On("getTargetWriter", targetURL+"hello2", targetConfig, etag2, dataLen2).Return(writer2, nil).Once()
|
||||
|
||||
msg, err := doCopyCmdRecursive(manager, sourceURLConfigMap, targetURLConfigMap)
|
||||
@@ -299,7 +309,7 @@ func (s *CmdTestSuite) TestLsCmdWithBucket(c *C) {
|
||||
}
|
||||
}
|
||||
}()
|
||||
cl1.On("ListOnChannel").Return(itemCh).Once()
|
||||
cl1.On("List").Return(itemCh).Once()
|
||||
msg, err := doListCmd(manager, sourceURL, sourceConfig, false)
|
||||
c.Assert(msg, Equals, "")
|
||||
c.Assert(err, IsNil)
|
||||
@@ -343,7 +353,7 @@ func (s *CmdTestSuite) TestLsCmdWithFilePath(c *C) {
|
||||
}
|
||||
}
|
||||
}()
|
||||
cl1.On("ListOnChannel").Return(itemCh).Once()
|
||||
cl1.On("List").Return(itemCh).Once()
|
||||
msg, err := doListCmd(manager, sourceURL, sourceConfig, false)
|
||||
c.Assert(msg, Equals, "")
|
||||
c.Assert(err, IsNil)
|
||||
@@ -381,7 +391,7 @@ func (s *CmdTestSuite) TestLsCmdListsBuckets(c *C) {
|
||||
}
|
||||
}
|
||||
}()
|
||||
cl1.On("ListOnChannel").Return(itemCh).Once()
|
||||
cl1.On("List").Return(itemCh).Once()
|
||||
msg, err := doListCmd(manager, sourceURL, sourceConfig, false)
|
||||
c.Assert(msg, Equals, "")
|
||||
c.Assert(err, IsNil)
|
||||
|
||||
@@ -30,8 +30,7 @@ type Client interface {
|
||||
|
||||
// Common operations
|
||||
Stat() error
|
||||
List() (items []*Item, err error)
|
||||
ListOnChannel() <-chan ItemOnChannel
|
||||
List() <-chan ItemOnChannel
|
||||
|
||||
// Bucket operations
|
||||
PutBucket(acl string) error
|
||||
|
||||
@@ -27,6 +27,7 @@ import (
|
||||
"testing"
|
||||
|
||||
. "github.com/minio-io/check"
|
||||
"github.com/minio-io/mc/pkg/client"
|
||||
)
|
||||
|
||||
func Test(t *testing.T) { TestingT(t) }
|
||||
@@ -66,7 +67,10 @@ func (s *MySuite) TestList(c *C) {
|
||||
c.Assert(size, Equals, dataLen)
|
||||
|
||||
fsc = New(root)
|
||||
items, err := fsc.List()
|
||||
var items []*client.Item
|
||||
for itemCh := range fsc.List() {
|
||||
items = append(items, itemCh.Item)
|
||||
}
|
||||
c.Assert(err, IsNil)
|
||||
c.Assert(len(items), Equals, 3)
|
||||
}
|
||||
|
||||
@@ -109,7 +109,7 @@ func (f *fsClient) GetObjectMetadata() (item *client.Item, reterr error) {
|
||||
return item, nil
|
||||
}
|
||||
|
||||
func (f *fsClient) ListOnChannel() <-chan client.ItemOnChannel {
|
||||
func (f *fsClient) List() <-chan client.ItemOnChannel {
|
||||
itemCh := make(chan client.ItemOnChannel)
|
||||
go f.listInGoroutine(itemCh)
|
||||
return itemCh
|
||||
@@ -145,31 +145,6 @@ func (f *fsClient) listInGoroutine(itemCh chan client.ItemOnChannel) {
|
||||
}
|
||||
}
|
||||
|
||||
// List - get a list of items
|
||||
func (f *fsClient) List() (items []*client.Item, err error) {
|
||||
visitFS := func(fp string, fi os.FileInfo, err error) error {
|
||||
if err != nil {
|
||||
if os.IsPermission(err) { // skip inaccessible files
|
||||
return nil
|
||||
}
|
||||
return err // fatal
|
||||
}
|
||||
item := &client.Item{
|
||||
Name: fp,
|
||||
Time: fi.ModTime(),
|
||||
Size: fi.Size(),
|
||||
}
|
||||
|
||||
items = append(items, item)
|
||||
return nil
|
||||
}
|
||||
err = filepath.Walk(f.path, visitFS)
|
||||
if err != nil {
|
||||
return nil, iodine.New(err, nil)
|
||||
}
|
||||
return items, nil
|
||||
}
|
||||
|
||||
// PutBucket - create a new bucket
|
||||
func (f *fsClient) PutBucket(acl string) error {
|
||||
err := os.MkdirAll(f.path, 0700)
|
||||
|
||||
@@ -124,7 +124,7 @@ func (f *fsClient) listBuckets() ([]*client.Item, error) {
|
||||
return results, nil
|
||||
}
|
||||
|
||||
func (f *fsClient) ListOnChannel() <-chan client.ItemOnChannel {
|
||||
func (f *fsClient) List() <-chan client.ItemOnChannel {
|
||||
itemCh := make(chan client.ItemOnChannel)
|
||||
go f.listInGoroutine(itemCh)
|
||||
return itemCh
|
||||
@@ -160,37 +160,6 @@ func (f *fsClient) listInGoroutine(itemCh chan client.ItemOnChannel) {
|
||||
}
|
||||
}
|
||||
|
||||
// List - get a list of items
|
||||
func (f *fsClient) List() (items []*client.Item, err error) {
|
||||
item, err := f.GetObjectMetadata()
|
||||
switch err {
|
||||
case nil:
|
||||
items = append(items, item)
|
||||
return items, nil
|
||||
default:
|
||||
visitFS := func(fp string, fi os.FileInfo, err error) error {
|
||||
if err != nil {
|
||||
if os.IsPermission(err) { // skip inaccessible files
|
||||
return nil
|
||||
}
|
||||
return err // fatal
|
||||
}
|
||||
item := &client.Item{
|
||||
Name: fp,
|
||||
Time: fi.ModTime(),
|
||||
Size: fi.Size(),
|
||||
}
|
||||
items = append(items, item)
|
||||
return nil
|
||||
}
|
||||
err = filepath.Walk(f.path, visitFS)
|
||||
if err != nil {
|
||||
return nil, iodine.New(err, nil)
|
||||
}
|
||||
return items, nil
|
||||
}
|
||||
}
|
||||
|
||||
// PutBucket - create a new bucket
|
||||
func (f *fsClient) PutBucket(acl string) error {
|
||||
err := os.MkdirAll(f.path, 0700)
|
||||
|
||||
@@ -30,26 +30,13 @@ func (m *Client) Stat() error {
|
||||
return r0
|
||||
}
|
||||
|
||||
// ListOnChannel is a mock method
|
||||
func (m *Client) ListOnChannel() <-chan client.ItemOnChannel {
|
||||
// List is a mock method
|
||||
func (m *Client) List() <-chan client.ItemOnChannel {
|
||||
ret := m.Called()
|
||||
r0 := ret.Get(0).(chan client.ItemOnChannel)
|
||||
return r0
|
||||
}
|
||||
|
||||
// List is a mock method
|
||||
func (m *Client) List() ([]*client.Item, error) {
|
||||
ret := m.Called()
|
||||
|
||||
var r0 []*client.Item
|
||||
if ret.Get(0) != nil {
|
||||
r0 = ret.Get(0).([]*client.Item)
|
||||
}
|
||||
r1 := ret.Error(1)
|
||||
|
||||
return r0, r1
|
||||
}
|
||||
|
||||
// Get is a mock method
|
||||
func (m *Client) Get() (io.ReadCloser, int64, string, error) {
|
||||
ret := m.Called()
|
||||
|
||||
@@ -33,8 +33,8 @@ import (
|
||||
|
||||
/// Bucket API operations
|
||||
|
||||
// ListOnChannel -
|
||||
func (c *s3Client) ListOnChannel() <-chan client.ItemOnChannel {
|
||||
// List - list buckets and objects
|
||||
func (c *s3Client) List() <-chan client.ItemOnChannel {
|
||||
itemCh := make(chan client.ItemOnChannel)
|
||||
go c.listInGoroutine(itemCh)
|
||||
return itemCh
|
||||
@@ -88,29 +88,6 @@ func (c *s3Client) listInGoroutine(itemCh chan client.ItemOnChannel) {
|
||||
}
|
||||
}
|
||||
|
||||
// List - list objects inside a bucket or with prefix
|
||||
func (c *s3Client) List() (items []*client.Item, err error) {
|
||||
bucket, objectPrefix := c.url2BucketAndObject()
|
||||
item, err := c.GetObjectMetadata()
|
||||
switch err {
|
||||
case nil: // List a single object. Exact key
|
||||
items = append(items, item)
|
||||
return items, nil
|
||||
default:
|
||||
// if not bucket provided return list of all buckets
|
||||
if bucket == "" {
|
||||
return c.listBucketsInternal()
|
||||
}
|
||||
// List all objects matching the key prefix
|
||||
items, err = c.listObjectsInternal(bucket, "", objectPrefix, "", globalMaxKeys)
|
||||
if err != nil {
|
||||
return nil, iodine.New(err, nil)
|
||||
}
|
||||
// even if items are equal to '0' is valid case
|
||||
return items, nil
|
||||
}
|
||||
}
|
||||
|
||||
// populate s3 response and decode results into listBucketResults{}
|
||||
func (c *s3Client) decodeBucketResults(queryURL string) (*listBucketResults, error) {
|
||||
bres := &listBucketResults{}
|
||||
|
||||
Reference in New Issue
Block a user