From 8cae137525a4ae986a1701b7ce3a3f5f065dfa31 Mon Sep 17 00:00:00 2001 From: Harshavardhana Date: Fri, 3 Apr 2020 22:22:20 -0700 Subject: [PATCH] fix all the build errors --- cmd/admin-prometheus-generate.go | 1 + cmd/admin-trace.go | 6 +- cmd/client-fs.go | 64 ++++++------ cmd/client-fs_test.go | 2 +- cmd/client-s3.go | 167 ++++++++++++++++--------------- cmd/client-url.go | 22 ++-- cmd/client.go | 16 +-- cmd/config-fix.go | 2 +- cmd/cp-url-syntax.go | 2 +- cmd/cp-url.go | 8 +- cmd/diff-main.go | 4 +- cmd/difference.go | 2 +- cmd/event-list.go | 2 +- cmd/find_test.go | 20 ++-- cmd/lock-main.go | 2 +- cmd/ls-main.go | 2 +- cmd/ls.go | 4 +- cmd/main.go | 2 +- cmd/mirror-main.go | 18 ++-- cmd/mirror-url.go | 4 +- cmd/rb-main.go | 4 +- cmd/rm-main.go | 6 +- cmd/share-download-main.go | 2 +- cmd/stat.go | 6 +- cmd/stat_test.go | 10 +- cmd/tree-main.go | 2 +- cmd/urls.go | 4 +- cmd/watch.go | 13 +-- 28 files changed, 200 insertions(+), 197 deletions(-) diff --git a/cmd/admin-prometheus-generate.go b/cmd/admin-prometheus-generate.go index 313edef0..b1a48336 100644 --- a/cmd/admin-prometheus-generate.go +++ b/cmd/admin-prometheus-generate.go @@ -147,6 +147,7 @@ func generatePrometheusConfig(ctx *cli.Context) error { hostConfig := mustGetHostConfig(alias) if hostConfig == nil { fatalIf(errInvalidAliasedURL(alias), "No such alias `"+alias+"` found.") + return nil } u, err := url.Parse(hostConfig.URL) diff --git a/cmd/admin-trace.go b/cmd/admin-trace.go index 9437ac58..e6adafcf 100644 --- a/cmd/admin-trace.go +++ b/cmd/admin-trace.go @@ -240,9 +240,9 @@ func (s shortTraceMsg) String() string { fmt.Fprint(b, console.Colorize("HeaderValue", fmt.Sprintf(" %2s", s.CallStats.Duration.Round(time.Microsecond)))) spaces = 12 - len(fmt.Sprintf("%2s", s.CallStats.Duration.Round(time.Microsecond))) fmt.Fprintf(b, "%*s", spaces, " ") - fmt.Fprint(b, console.Colorize("Stat", fmt.Sprintf(" ↑ "))) + fmt.Fprint(b, console.Colorize("Stat", " ↑ ")) fmt.Fprint(b, console.Colorize("HeaderValue", humanize.IBytes(uint64(s.CallStats.Rx)))) - fmt.Fprint(b, console.Colorize("Stat", fmt.Sprintf(" ↓ "))) + fmt.Fprint(b, console.Colorize("Stat", " ↓ ")) fmt.Fprint(b, console.Colorize("HeaderValue", humanize.IBytes(uint64(s.CallStats.Tx)))) return b.String() @@ -333,7 +333,7 @@ func (t traceMessage) String() string { } fmt.Fprintf(b, "%s%s", nodeNameStr, console.Colorize("Body", fmt.Sprintf("%s\n", string(ri.Body)))) - fmt.Fprintf(b, "%s%s", nodeNameStr, console.Colorize("Response", fmt.Sprintf("[RESPONSE] "))) + fmt.Fprintf(b, "%s%s", nodeNameStr, console.Colorize("Response", "[RESPONSE] ")) fmt.Fprintf(b, "[%s] ", rs.Time.Format(timeFormat)) fmt.Fprint(b, console.Colorize("Stat", fmt.Sprintf("[ Duration %2s ↑ %s ↓ %s ]\n", trc.CallStats.Latency.Round(time.Microsecond), humanize.IBytes(uint64(trc.CallStats.InputBytes)), humanize.IBytes(uint64(trc.CallStats.OutputBytes))))) diff --git a/cmd/client-fs.go b/cmd/client-fs.go index fcf6b6e4..70bd5127 100644 --- a/cmd/client-fs.go +++ b/cmd/client-fs.go @@ -1,5 +1,5 @@ /* - * MinIO Client (C) 2015 MinIO, Inc. + * MinIO Client (C) 2015-2020 MinIO, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this fs except in compliance with the License. @@ -45,7 +45,7 @@ import ( // filesystem client type fsClient struct { - PathURL *clientURL + PathURL *ClientURL } const ( @@ -113,7 +113,7 @@ func isIgnoredFile(filename string) bool { } // URL get url. -func (f *fsClient) GetURL() clientURL { +func (f *fsClient) GetURL() ClientURL { return *f.PathURL } @@ -126,7 +126,7 @@ func (f *fsClient) Select(expression string, sse encrypt.ServerSide, opts Select } // Watches for all fs events on an input path. -func (f *fsClient) Watch(params watchParams) (*watchObject, *probe.Error) { +func (f *fsClient) Watch(params watchParams) (*WatchObject, *probe.Error) { eventChan := make(chan EventInfo) errorChan := make(chan *probe.Error) doneChan := make(chan bool) @@ -214,7 +214,7 @@ func (f *fsClient) Watch(params watchParams) (*watchObject, *probe.Error) { } }() - return &watchObject{ + return &WatchObject{ eventInfoChan: eventChan, errorChan: errorChan, doneChan: doneChan, @@ -503,8 +503,8 @@ func deleteFile(deletePath string) error { return nil } -// Remove - remove entry read from clientContent channel. -func (f *fsClient) Remove(isIncomplete, isRemoveBucket bool, contentCh <-chan *clientContent) <-chan *probe.Error { +// Remove - remove entry read from ClientContent channel. +func (f *fsClient) Remove(isIncomplete, isRemoveBucket bool, contentCh <-chan *ClientContent) <-chan *probe.Error { errorCh := make(chan *probe.Error) // Goroutine reads from contentCh and removes the entry in content. @@ -536,9 +536,9 @@ func (f *fsClient) Remove(isIncomplete, isRemoveBucket bool, contentCh <-chan *c } // List - list files and folders. -func (f *fsClient) List(isRecursive, isIncomplete, isMetadata bool, showDir DirOpt) <-chan *clientContent { - contentCh := make(chan *clientContent) - filteredCh := make(chan *clientContent) +func (f *fsClient) List(isRecursive, isIncomplete, isMetadata bool, showDir DirOpt) <-chan *ClientContent { + contentCh := make(chan *ClientContent) + filteredCh := make(chan *ClientContent) if isRecursive { if showDir == DirNone { @@ -613,12 +613,12 @@ func readDir(dirname string) ([]os.FileInfo, error) { } // listPrefixes - list all files for any given prefix. -func (f *fsClient) listPrefixes(prefix string, contentCh chan<- *clientContent) { +func (f *fsClient) listPrefixes(prefix string, contentCh chan<- *ClientContent) { dirName := filepath.Dir(prefix) files, e := readDir(dirName) if e != nil { err := f.toClientError(e, dirName) - contentCh <- &clientContent{ + contentCh <- &ClientContent{ Err: err.Trace(dirName), } return @@ -637,7 +637,7 @@ func (f *fsClient) listPrefixes(prefix string, contentCh chan<- *clientContent) continue } if strings.HasPrefix(file, prefix) { - contentCh <- &clientContent{ + contentCh <- &ClientContent{ URL: *newClientURL(file), Time: st.ModTime(), Size: st.Size(), @@ -648,7 +648,7 @@ func (f *fsClient) listPrefixes(prefix string, contentCh chan<- *clientContent) } } if strings.HasPrefix(file, prefix) { - contentCh <- &clientContent{ + contentCh <- &ClientContent{ URL: *newClientURL(file), Time: fi.ModTime(), Size: fi.Size(), @@ -659,7 +659,7 @@ func (f *fsClient) listPrefixes(prefix string, contentCh chan<- *clientContent) } } -func (f *fsClient) listInRoutine(contentCh chan<- *clientContent, isMetadata bool) { +func (f *fsClient) listInRoutine(contentCh chan<- *ClientContent, isMetadata bool) { // close the channel when the function returns. defer close(contentCh) @@ -676,7 +676,7 @@ func (f *fsClient) listInRoutine(contentCh chan<- *clientContent, isMetadata boo return } // For all other errors we return genuine error back to the caller. - contentCh <- &clientContent{Err: err.Trace(fpath)} + contentCh <- &ClientContent{Err: err.Trace(fpath)} return } @@ -692,7 +692,7 @@ func (f *fsClient) listInRoutine(contentCh chan<- *clientContent, isMetadata boo case true: files, e := readDir(fpath) if err != nil { - contentCh <- &clientContent{Err: probe.NewError(e)} + contentCh <- &ClientContent{Err: probe.NewError(e)} return } for _, file := range files { @@ -714,7 +714,7 @@ func (f *fsClient) listInRoutine(contentCh chan<- *clientContent, isMetadata boo continue } - contentCh <- &clientContent{ + contentCh <- &ClientContent{ URL: pathURL, Time: fi.ModTime(), Size: fi.Size(), @@ -724,7 +724,7 @@ func (f *fsClient) listInRoutine(contentCh chan<- *clientContent, isMetadata boo } } default: - contentCh <- &clientContent{ + contentCh <- &ClientContent{ URL: pathURL, Time: fst.ModTime(), Size: fst.Size(), @@ -735,7 +735,7 @@ func (f *fsClient) listInRoutine(contentCh chan<- *clientContent, isMetadata boo } // List files recursively using non-recursive mode. -func (f *fsClient) listDirOpt(contentCh chan *clientContent, isIncomplete bool, isMetadata bool, dirOpt DirOpt) { +func (f *fsClient) listDirOpt(contentCh chan *ClientContent, isIncomplete bool, isMetadata bool, dirOpt DirOpt) { defer close(contentCh) // Trim trailing / or \. @@ -751,7 +751,7 @@ func (f *fsClient) listDirOpt(contentCh chan *clientContent, isIncomplete bool, files, e := readDir(currentPath) if e != nil { if os.IsPermission(e) { - contentCh <- &clientContent{ + contentCh <- &ClientContent{ Err: probe.NewError(PathInsufficientPermission{ Path: currentPath, }), @@ -759,13 +759,13 @@ func (f *fsClient) listDirOpt(contentCh chan *clientContent, isIncomplete bool, return false } - contentCh <- &clientContent{Err: probe.NewError(e)} + contentCh <- &ClientContent{Err: probe.NewError(e)} return true } for _, file := range files { name := filepath.Join(currentPath, file.Name()) - content := clientContent{ + content := ClientContent{ URL: *newClientURL(name), Time: file.ModTime(), Size: file.Size(), @@ -795,17 +795,17 @@ func (f *fsClient) listDirOpt(contentCh chan *clientContent, isIncomplete bool, // listDir() does not send currentPath to contentCh. We send it here depending on dirOpt. if dirOpt == DirFirst && !isIncomplete { - contentCh <- &clientContent{URL: *newClientURL(currentPath), Type: os.ModeDir} + contentCh <- &ClientContent{URL: *newClientURL(currentPath), Type: os.ModeDir} } listDir(currentPath) if dirOpt == DirLast && !isIncomplete { - contentCh <- &clientContent{URL: *newClientURL(currentPath), Type: os.ModeDir} + contentCh <- &ClientContent{URL: *newClientURL(currentPath), Type: os.ModeDir} } } -func (f *fsClient) listRecursiveInRoutine(contentCh chan *clientContent, isMetadata bool) { +func (f *fsClient) listRecursiveInRoutine(contentCh chan *ClientContent, isMetadata bool) { // close channels upon return. defer close(contentCh) var dirName string @@ -853,13 +853,13 @@ func (f *fsClient) listRecursiveInRoutine(contentCh chan *clientContent, isMetad if e != nil { // If operation is not permitted, we throw quickly back. if strings.Contains(e.Error(), "operation not permitted") { - contentCh <- &clientContent{ + contentCh <- &ClientContent{ Err: probe.NewError(e), } return nil } if os.IsPermission(e) { - contentCh <- &clientContent{ + contentCh <- &ClientContent{ Err: probe.NewError(PathInsufficientPermission{Path: fp}), } return nil @@ -874,7 +874,7 @@ func (f *fsClient) listRecursiveInRoutine(contentCh chan *clientContent, isMetad } } if fi.Mode().IsRegular() { - contentCh <- &clientContent{ + contentCh <- &ClientContent{ URL: *newClientURL(fp), Time: fi.ModTime(), Size: fi.Size(), @@ -903,7 +903,7 @@ func (f *fsClient) listRecursiveInRoutine(contentCh chan *clientContent, isMetad // walks invokes our custom function. e := ioutils.FTW(dirName, visitFS) if e != nil { - contentCh <- &clientContent{ + contentCh <- &ClientContent{ Err: probe.NewError(e), } } @@ -1020,13 +1020,13 @@ func (f *fsClient) SetAccess(access string, isJSON bool) *probe.Error { } // Stat - get metadata from path. -func (f *fsClient) Stat(isIncomplete, isFetchMeta, isPreserve bool, sse encrypt.ServerSide) (content *clientContent, err *probe.Error) { +func (f *fsClient) Stat(isIncomplete, isFetchMeta, isPreserve bool, sse encrypt.ServerSide) (content *ClientContent, err *probe.Error) { st, err := f.fsStat(isIncomplete) if err != nil { return nil, err.Trace(f.PathURL.String()) } - content = &clientContent{} + content = &ClientContent{} content.URL = *f.PathURL content.Size = st.Size() content.Time = st.ModTime() diff --git a/cmd/client-fs_test.go b/cmd/client-fs_test.go index fd677eea..d27c45be 100644 --- a/cmd/client-fs_test.go +++ b/cmd/client-fs_test.go @@ -64,7 +64,7 @@ func (s *TestSuite) TestList(c *C) { c.Assert(err, IsNil) // Verify previously create files and list them. - var contents []*clientContent + var contents []*ClientContent for content := range fsClient.List(false, false, false, DirNone) { if content.Err != nil { err = content.Err diff --git a/cmd/client-s3.go b/cmd/client-s3.go index f3c12afd..95018508 100644 --- a/cmd/client-s3.go +++ b/cmd/client-s3.go @@ -1,5 +1,5 @@ /* - * MinIO Client (C) 2015, 2016, 2017, 2018 MinIO, Inc. + * MinIO Client (C) 2015-2020 MinIO, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -47,10 +47,10 @@ import ( "github.com/minio/minio/pkg/mimedb" ) -// S3 client +// S3Client construct type S3Client struct { - mutex *sync.Mutex - targetURL *clientURL + sync.Mutex + targetURL *ClientURL api *minio.Client virtualStyle bool } @@ -84,7 +84,7 @@ var timeSentinel = time.Unix(0, 0).UTC() // newFactory encloses New function with client cache. func newFactory() func(config *Config) (Client, *probe.Error) { clientCache := make(map[uint32]*minio.Client) - mutex := &sync.Mutex{} + var mutex sync.Mutex // Return New function. return func(config *Config) (Client, *probe.Error) { @@ -98,8 +98,6 @@ func newFactory() func(config *Config) (Client, *probe.Error) { // Instantiate s3 s3Clnt := &S3Client{} - // Allocate a new mutex. - s3Clnt.mutex = new(sync.Mutex) // Save the target URL. s3Clnt.targetURL = targetURL @@ -226,11 +224,11 @@ func newFactory() func(config *Config) (Client, *probe.Error) { var S3New = newFactory() // GetURL get url. -func (c *S3Client) GetURL() clientURL { +func (c *S3Client) GetURL() ClientURL { return *c.targetURL } -// Add bucket notification +// AddNotificationConfig - Add bucket notification func (c *S3Client) AddNotificationConfig(arn string, events []string, prefix, suffix string, ignoreExisting bool) *probe.Error { bucket, _ := c.url2BucketAndObject() // Validate total fields in ARN. @@ -295,7 +293,7 @@ func (c *S3Client) AddNotificationConfig(arn string, events []string, prefix, su return nil } -// Remove bucket notification +// RemoveNotificationConfig - Remove bucket notification func (c *S3Client) RemoveNotificationConfig(arn string) *probe.Error { bucket, _ := c.url2BucketAndObject() // Remove all notification configs if arn is empty @@ -335,7 +333,8 @@ func (c *S3Client) RemoveNotificationConfig(arn string) *probe.Error { return nil } -type notificationConfig struct { +// NotificationConfig notification config +type NotificationConfig struct { ID string `json:"id"` Arn string `json:"arn"` Events []string `json:"events"` @@ -343,9 +342,9 @@ type notificationConfig struct { Suffix string `json:"suffix"` } -// List notification configs -func (c *S3Client) ListNotificationConfigs(arn string) ([]notificationConfig, *probe.Error) { - var configs []notificationConfig +// ListNotificationConfigs - List notification configs +func (c *S3Client) ListNotificationConfigs(arn string) ([]NotificationConfig, *probe.Error) { + var configs []NotificationConfig bucket, _ := c.url2BucketAndObject() mb, e := c.api.GetBucketNotification(bucket) if e != nil { @@ -382,7 +381,7 @@ func (c *S3Client) ListNotificationConfigs(arn string) ([]notificationConfig, *p continue } prefix, suffix := getFilters(config.NotificationConfig) - configs = append(configs, notificationConfig{ID: config.ID, + configs = append(configs, NotificationConfig{ID: config.ID, Arn: config.Topic, Events: prettyEventNames(config.Events), Prefix: prefix, @@ -394,7 +393,7 @@ func (c *S3Client) ListNotificationConfigs(arn string) ([]notificationConfig, *p continue } prefix, suffix := getFilters(config.NotificationConfig) - configs = append(configs, notificationConfig{ID: config.ID, + configs = append(configs, NotificationConfig{ID: config.ID, Arn: config.Queue, Events: prettyEventNames(config.Events), Prefix: prefix, @@ -406,7 +405,7 @@ func (c *S3Client) ListNotificationConfigs(arn string) ([]notificationConfig, *p continue } prefix, suffix := getFilters(config.NotificationConfig) - configs = append(configs, notificationConfig{ID: config.ID, + configs = append(configs, NotificationConfig{ID: config.ID, Arn: config.Lambda, Events: prettyEventNames(config.Events), Prefix: prefix, @@ -553,6 +552,7 @@ func selectCompressionType(selOpts SelectObjectOpts, object string) minio.Select return minio.SelectCompressionNONE } +// Select - select object content wrapper. func (c *S3Client) Select(expression string, sse encrypt.ServerSide, selOpts SelectObjectOpts) (io.ReadCloser, *probe.Error) { opts := minio.SelectObjectOptions{ Expression: expression, @@ -667,8 +667,8 @@ func (c *S3Client) watchOneBucket(bucket, prefix, suffix string, events []string } } -// Start watching on all bucket events for a given account ID. -func (c *S3Client) Watch(params watchParams) (*watchObject, *probe.Error) { +// Watch - Start watching on all bucket events for a given account ID. +func (c *S3Client) Watch(params watchParams) (*WatchObject, *probe.Error) { // Extract bucket and object. bucket, object := c.url2BucketAndObject() @@ -707,7 +707,7 @@ func (c *S3Client) Watch(params watchParams) (*watchObject, *probe.Error) { buckets = append(buckets, bucket) } - wo := &watchObject{ + wo := &WatchObject{ eventInfoChan: make(chan EventInfo), errorChan: make(chan *probe.Error), doneChan: make(chan bool), @@ -956,12 +956,13 @@ func (c *S3Client) removeIncompleteObjects(bucket string, objectsCh <-chan strin return removeObjectErrorCh } +// AddUserAgent - add custom user agent. func (c *S3Client) AddUserAgent(app string, version string) { c.api.SetAppInfo(app, version) } // Remove - remove object or bucket(s). -func (c *S3Client) Remove(isIncomplete, isRemoveBucket bool, contentCh <-chan *clientContent) <-chan *probe.Error { +func (c *S3Client) Remove(isIncomplete, isRemoveBucket bool, contentCh <-chan *ClientContent) <-chan *probe.Error { errorCh := make(chan *probe.Error) prevBucket := "" @@ -1226,9 +1227,9 @@ func (c *S3Client) listObjectWrapper(bucket, object string, isRecursive bool, do } // Stat - send a 'HEAD' on a bucket or object to fetch its metadata. -func (c *S3Client) Stat(isIncomplete, isFetchMeta, isPreserve bool, sse encrypt.ServerSide) (*clientContent, *probe.Error) { - c.mutex.Lock() - defer c.mutex.Unlock() +func (c *S3Client) Stat(isIncomplete, isFetchMeta, isPreserve bool, sse encrypt.ServerSide) (*ClientContent, *probe.Error) { + c.Lock() + defer c.Unlock() bucket, object := c.url2BucketAndObject() // Bucket name cannot be empty, stat on URL has no meaning. if bucket == "" { @@ -1252,7 +1253,7 @@ func (c *S3Client) Stat(isIncomplete, isFetchMeta, isPreserve bool, sse encrypt. // - /path/to/empty_directory/ nonRecursive := false - objectMetadata := &clientContent{} + objectMetadata := &ClientContent{} // Prefix to pass to minio-go listing in order to fetch a given object/directory prefix := strings.TrimRight(object, string(c.targetURL.Separator)) @@ -1327,8 +1328,8 @@ func (c *S3Client) Stat(isIncomplete, isFetchMeta, isPreserve bool, sse encrypt. } // getObjectStat returns the metadata of an object from a HEAD call. -func (c *S3Client) getObjectStat(bucket, object string, opts minio.StatObjectOptions) (*clientContent, *probe.Error) { - objectMetadata := &clientContent{} +func (c *S3Client) getObjectStat(bucket, object string, opts minio.StatObjectOptions) (*ClientContent, *probe.Error) { + objectMetadata := &ClientContent{} objectStat, e := c.api.StatObject(bucket, object, opts) if e != nil { errResponse := minio.ToErrorResponse(e) @@ -1450,11 +1451,11 @@ func (c *S3Client) splitPath(path string) (bucketName, objectName string) { /// Bucket API operations. // List - list at delimited path, if not recursive. -func (c *S3Client) List(isRecursive, isIncomplete, isMetadata bool, showDir DirOpt) <-chan *clientContent { - c.mutex.Lock() - defer c.mutex.Unlock() +func (c *S3Client) List(isRecursive, isIncomplete, isMetadata bool, showDir DirOpt) <-chan *ClientContent { + c.Lock() + defer c.Unlock() - contentCh := make(chan *clientContent) + contentCh := make(chan *ClientContent) if isIncomplete { if isRecursive { if showDir == DirNone { @@ -1480,7 +1481,7 @@ func (c *S3Client) List(isRecursive, isIncomplete, isMetadata bool, showDir DirO return contentCh } -func (c *S3Client) listIncompleteInRoutine(contentCh chan *clientContent) { +func (c *S3Client) listIncompleteInRoutine(contentCh chan *ClientContent) { defer close(contentCh) // get bucket and object from URL. b, o := c.url2BucketAndObject() @@ -1488,7 +1489,7 @@ func (c *S3Client) listIncompleteInRoutine(contentCh chan *clientContent) { case b == "" && o == "": buckets, err := c.api.ListBuckets() if err != nil { - contentCh <- &clientContent{ + contentCh <- &ClientContent{ Err: probe.NewError(err), } return @@ -1497,12 +1498,12 @@ func (c *S3Client) listIncompleteInRoutine(contentCh chan *clientContent) { for _, bucket := range buckets { for object := range c.api.ListIncompleteUploads(bucket.Name, o, isRecursive, nil) { if object.Err != nil { - contentCh <- &clientContent{ + contentCh <- &ClientContent{ Err: probe.NewError(object.Err), } return } - content := &clientContent{} + content := &ClientContent{} url := *c.targetURL // Join bucket with - incoming object key. url.Path = c.joinPath(bucket.Name, object.Key) @@ -1525,12 +1526,12 @@ func (c *S3Client) listIncompleteInRoutine(contentCh chan *clientContent) { isRecursive := false for object := range c.api.ListIncompleteUploads(b, o, isRecursive, nil) { if object.Err != nil { - contentCh <- &clientContent{ + contentCh <- &ClientContent{ Err: probe.NewError(object.Err), } return } - content := &clientContent{} + content := &ClientContent{} url := *c.targetURL // Join bucket with - incoming object key. url.Path = c.joinPath(b, object.Key) @@ -1551,7 +1552,7 @@ func (c *S3Client) listIncompleteInRoutine(contentCh chan *clientContent) { } } -func (c *S3Client) listIncompleteRecursiveInRoutine(contentCh chan *clientContent) { +func (c *S3Client) listIncompleteRecursiveInRoutine(contentCh chan *ClientContent) { defer close(contentCh) // get bucket and object from URL. b, o := c.url2BucketAndObject() @@ -1559,7 +1560,7 @@ func (c *S3Client) listIncompleteRecursiveInRoutine(contentCh chan *clientConten case b == "" && o == "": buckets, err := c.api.ListBuckets() if err != nil { - contentCh <- &clientContent{ + contentCh <- &ClientContent{ Err: probe.NewError(err), } return @@ -1568,14 +1569,14 @@ func (c *S3Client) listIncompleteRecursiveInRoutine(contentCh chan *clientConten for _, bucket := range buckets { for object := range c.api.ListIncompleteUploads(bucket.Name, o, isRecursive, nil) { if object.Err != nil { - contentCh <- &clientContent{ + contentCh <- &ClientContent{ Err: probe.NewError(object.Err), } return } url := *c.targetURL url.Path = c.joinPath(bucket.Name, object.Key) - content := &clientContent{} + content := &ClientContent{} content.URL = url content.Size = object.Size content.Time = object.Initiated @@ -1587,7 +1588,7 @@ func (c *S3Client) listIncompleteRecursiveInRoutine(contentCh chan *clientConten isRecursive := true for object := range c.api.ListIncompleteUploads(b, o, isRecursive, nil) { if object.Err != nil { - contentCh <- &clientContent{ + contentCh <- &ClientContent{ Err: probe.NewError(object.Err), } return @@ -1595,7 +1596,7 @@ func (c *S3Client) listIncompleteRecursiveInRoutine(contentCh chan *clientConten url := *c.targetURL // Join bucket and incoming object key. url.Path = c.joinPath(b, object.Key) - content := &clientContent{} + content := &ClientContent{} content.URL = url content.Size = object.Size content.Time = object.Initiated @@ -1605,10 +1606,10 @@ func (c *S3Client) listIncompleteRecursiveInRoutine(contentCh chan *clientConten } } -// Convert objectMultipartInfo to clientContent -func (c *S3Client) objectMultipartInfo2ClientContent(bucket string, entry minio.ObjectMultipartInfo) clientContent { +// Convert objectMultipartInfo to ClientContent +func (c *S3Client) objectMultipartInfo2ClientContent(bucket string, entry minio.ObjectMultipartInfo) ClientContent { - content := clientContent{} + content := ClientContent{} url := *c.targetURL // Join bucket and incoming object key. url.Path = c.joinPath(bucket, entry.Key) @@ -1626,7 +1627,7 @@ func (c *S3Client) objectMultipartInfo2ClientContent(bucket string, entry minio. } // Recursively lists incomplete uploads. -func (c *S3Client) listIncompleteRecursiveInRoutineDirOpt(contentCh chan *clientContent, dirOpt DirOpt) { +func (c *S3Client) listIncompleteRecursiveInRoutineDirOpt(contentCh chan *ClientContent, dirOpt DirOpt) { defer close(contentCh) // Closure function reads list of incomplete uploads and sends to contentCh. If a directory is found, it lists @@ -1638,7 +1639,7 @@ func (c *S3Client) listIncompleteRecursiveInRoutineDirOpt(contentCh chan *client if entry.Err != nil { url := *c.targetURL url.Path = c.joinPath(bucket, object) - contentCh <- &clientContent{URL: url, Err: probe.NewError(entry.Err)} + contentCh <- &ClientContent{URL: url, Err: probe.NewError(entry.Err)} errResponse := minio.ToErrorResponse(entry.Err) if errResponse.Code == "AccessDenied" { @@ -1670,7 +1671,7 @@ func (c *S3Client) listIncompleteRecursiveInRoutineDirOpt(contentCh chan *client } bucket, object := c.url2BucketAndObject() - var cContent *clientContent + var cContent *ClientContent var buckets []minio.BucketInfo var allBuckets bool // List all buckets if bucket and object are empty. @@ -1679,14 +1680,14 @@ func (c *S3Client) listIncompleteRecursiveInRoutineDirOpt(contentCh chan *client allBuckets = true buckets, e = c.api.ListBuckets() if e != nil { - contentCh <- &clientContent{Err: probe.NewError(e)} + contentCh <- &ClientContent{Err: probe.NewError(e)} return } } else if object == "" { // Get bucket stat if object is empty. content, err := c.bucketStat(bucket) if err != nil { - contentCh <- &clientContent{Err: err.Trace(bucket)} + contentCh <- &ClientContent{Err: err.Trace(bucket)} return } buckets = append(buckets, minio.BucketInfo{Name: bucket, CreationDate: content.Time}) @@ -1696,7 +1697,7 @@ func (c *S3Client) listIncompleteRecursiveInRoutineDirOpt(contentCh chan *client content, perr := c.Stat(isIncomplete, false, false, nil) cContent = content if perr != nil { - contentCh <- &clientContent{Err: perr.Trace(bucket)} + contentCh <- &ClientContent{Err: perr.Trace(bucket)} return } buckets = append(buckets, minio.BucketInfo{Name: bucket, CreationDate: content.Time}) @@ -1705,7 +1706,7 @@ func (c *S3Client) listIncompleteRecursiveInRoutineDirOpt(contentCh chan *client if allBuckets { url := *c.targetURL url.Path = c.joinPath(bucket.Name) - cContent = &clientContent{ + cContent = &ClientContent{ URL: url, Time: bucket.CreationDate, Type: os.ModeDir, @@ -1732,9 +1733,9 @@ func (c *S3Client) joinPath(bucket string, objects ...string) string { return p } -// Convert objectInfo to clientContent -func (c *S3Client) objectInfo2ClientContent(bucket string, entry minio.ObjectInfo) *clientContent { - content := &clientContent{} +// Convert objectInfo to ClientContent +func (c *S3Client) objectInfo2ClientContent(bucket string, entry minio.ObjectInfo) *ClientContent { + content := &ClientContent{} url := *c.targetURL // Join bucket and incoming object key. url.Path = c.joinPath(bucket, entry.Key) @@ -1762,7 +1763,7 @@ func (c *S3Client) objectInfo2ClientContent(bucket string, entry minio.ObjectInf } // Returns bucket stat info of current bucket. -func (c *S3Client) bucketStat(bucket string) (*clientContent, *probe.Error) { +func (c *S3Client) bucketStat(bucket string) (*ClientContent, *probe.Error) { exists, e := c.api.BucketExists(bucket) if e != nil { return nil, probe.NewError(e) @@ -1770,11 +1771,11 @@ func (c *S3Client) bucketStat(bucket string) (*clientContent, *probe.Error) { if !exists { return nil, probe.NewError(BucketDoesNotExist{Bucket: bucket}) } - return &clientContent{URL: *c.targetURL, Time: time.Unix(0, 0), Type: os.ModeDir}, nil + return &ClientContent{URL: *c.targetURL, Time: time.Unix(0, 0), Type: os.ModeDir}, nil } // Recursively lists objects. -func (c *S3Client) listRecursiveInRoutineDirOpt(contentCh chan *clientContent, dirOpt DirOpt, metadata bool) { +func (c *S3Client) listRecursiveInRoutineDirOpt(contentCh chan *ClientContent, dirOpt DirOpt, metadata bool) { defer close(contentCh) // Closure function reads list objects and sends to contentCh. If a directory is found, it lists // objects of the directory content recursively. @@ -1785,7 +1786,7 @@ func (c *S3Client) listRecursiveInRoutineDirOpt(contentCh chan *clientContent, d if entry.Err != nil { url := *c.targetURL url.Path = c.joinPath(bucket, object) - contentCh <- &clientContent{URL: url, Err: probe.NewError(entry.Err)} + contentCh <- &ClientContent{URL: url, Err: probe.NewError(entry.Err)} errResponse := minio.ToErrorResponse(entry.Err) if errResponse.Code == "AccessDenied" { @@ -1816,7 +1817,7 @@ func (c *S3Client) listRecursiveInRoutineDirOpt(contentCh chan *clientContent, d bucket, object := c.url2BucketAndObject() - var cContent *clientContent + var cContent *ClientContent var buckets []minio.BucketInfo var allBuckets bool // List all buckets if bucket and object are empty. @@ -1825,14 +1826,14 @@ func (c *S3Client) listRecursiveInRoutineDirOpt(contentCh chan *clientContent, d allBuckets = true buckets, e = c.api.ListBuckets() if e != nil { - contentCh <- &clientContent{Err: probe.NewError(e)} + contentCh <- &ClientContent{Err: probe.NewError(e)} return } } else if object == "" { // Get bucket stat if object is empty. content, err := c.bucketStat(bucket) if err != nil { - contentCh <- &clientContent{Err: err.Trace(bucket)} + contentCh <- &ClientContent{Err: err.Trace(bucket)} return } buckets = append(buckets, minio.BucketInfo{Name: bucket, CreationDate: content.Time}) @@ -1843,7 +1844,7 @@ func (c *S3Client) listRecursiveInRoutineDirOpt(contentCh chan *clientContent, d content, perr := c.Stat(isIncomplete, isFetchMeta, false, nil) cContent = content if perr != nil { - contentCh <- &clientContent{Err: perr.Trace(bucket)} + contentCh <- &ClientContent{Err: perr.Trace(bucket)} return } buckets = append(buckets, minio.BucketInfo{Name: bucket, CreationDate: content.Time}) @@ -1853,7 +1854,7 @@ func (c *S3Client) listRecursiveInRoutineDirOpt(contentCh chan *clientContent, d if allBuckets { url := *c.targetURL url.Path = c.joinPath(bucket.Name) - cContent = &clientContent{ + cContent = &ClientContent{ URL: url, Time: bucket.CreationDate, Type: os.ModeDir, @@ -1871,7 +1872,7 @@ func (c *S3Client) listRecursiveInRoutineDirOpt(contentCh chan *clientContent, d } } -func (c *S3Client) listInRoutine(contentCh chan *clientContent, metadata bool) { +func (c *S3Client) listInRoutine(contentCh chan *ClientContent, metadata bool) { defer close(contentCh) // get bucket and object from URL. b, o := c.url2BucketAndObject() @@ -1879,7 +1880,7 @@ func (c *S3Client) listInRoutine(contentCh chan *clientContent, metadata bool) { case b == "" && o == "": buckets, e := c.api.ListBuckets() if e != nil { - contentCh <- &clientContent{ + contentCh <- &ClientContent{ Err: probe.NewError(e), } return @@ -1887,7 +1888,7 @@ func (c *S3Client) listInRoutine(contentCh chan *clientContent, metadata bool) { for _, bucket := range buckets { url := *c.targetURL url.Path = c.joinPath(bucket.Name) - content := &clientContent{} + content := &ClientContent{} content.URL = url content.Size = 0 content.Time = bucket.CreationDate @@ -1897,7 +1898,7 @@ func (c *S3Client) listInRoutine(contentCh chan *clientContent, metadata bool) { case b != "" && !strings.HasSuffix(c.targetURL.Path, string(c.targetURL.Separator)) && o == "": content, err := c.bucketStat(b) if err != nil { - contentCh <- &clientContent{Err: err.Trace(b)} + contentCh <- &ClientContent{Err: err.Trace(b)} return } contentCh <- content @@ -1905,7 +1906,7 @@ func (c *S3Client) listInRoutine(contentCh chan *clientContent, metadata bool) { isRecursive := false for object := range c.listObjectWrapper(b, o, isRecursive, nil, metadata) { if object.Err != nil { - contentCh <- &clientContent{ + contentCh <- &ClientContent{ Err: probe.NewError(object.Err), } return @@ -1934,7 +1935,7 @@ const ( s3StorageClassGlacier = "GLACIER" ) -func (c *S3Client) listRecursiveInRoutine(contentCh chan *clientContent, metadata bool) { +func (c *S3Client) listRecursiveInRoutine(contentCh chan *ClientContent, metadata bool) { defer close(contentCh) // get bucket and object from URL. b, o := c.url2BucketAndObject() @@ -1942,7 +1943,7 @@ func (c *S3Client) listRecursiveInRoutine(contentCh chan *clientContent, metadat case b == "" && o == "": buckets, err := c.api.ListBuckets() if err != nil { - contentCh <- &clientContent{ + contentCh <- &ClientContent{ Err: probe.NewError(err), } return @@ -1951,12 +1952,12 @@ func (c *S3Client) listRecursiveInRoutine(contentCh chan *clientContent, metadat isRecursive := true for object := range c.listObjectWrapper(bucket.Name, o, isRecursive, nil, metadata) { if object.Err != nil { - contentCh <- &clientContent{ + contentCh <- &ClientContent{ Err: probe.NewError(object.Err), } return } - content := &clientContent{} + content := &ClientContent{} objectURL := *c.targetURL objectURL.Path = c.joinPath(bucket.Name, object.Key) content.URL = objectURL @@ -1977,12 +1978,12 @@ func (c *S3Client) listRecursiveInRoutine(contentCh chan *clientContent, metadat isRecursive := true for object := range c.listObjectWrapper(b, o, isRecursive, nil, metadata) { if object.Err != nil { - contentCh <- &clientContent{ + contentCh <- &ClientContent{ Err: probe.NewError(object.Err), } return } - content := &clientContent{} + content := &ClientContent{} url := *c.targetURL // Join bucket and incoming object key. url.Path = c.joinPath(b, object.Key) @@ -2043,7 +2044,7 @@ func (c *S3Client) ShareUpload(isRecursive bool, expires time.Duration, contentT return u.String(), m, nil } -// Set object lock configurataion of bucket. +// SetObjectLockConfig - Set object lock configurataion of bucket. func (c *S3Client) SetObjectLockConfig(mode *minio.RetentionMode, validity *uint, unit *minio.ValidityUnit) *probe.Error { bucket, _ := c.url2BucketAndObject() @@ -2055,7 +2056,7 @@ func (c *S3Client) SetObjectLockConfig(mode *minio.RetentionMode, validity *uint return nil } -// Set object retention for a given object. +// PutObjectRetention - Set object retention for a given object. func (c *S3Client) PutObjectRetention(mode *minio.RetentionMode, retainUntilDate *time.Time, bypassGovernance bool) *probe.Error { bucket, object := c.url2BucketAndObject() @@ -2072,7 +2073,7 @@ func (c *S3Client) PutObjectRetention(mode *minio.RetentionMode, retainUntilDate return nil } -// Set object legal hold for a given object. +// PutObjectLegalHold - Set object legal hold for a given object. func (c *S3Client) PutObjectLegalHold(lhold *minio.LegalHoldStatus) *probe.Error { bucket, object := c.url2BucketAndObject() opts := minio.PutObjectLegalHoldOptions{ @@ -2085,7 +2086,7 @@ func (c *S3Client) PutObjectLegalHold(lhold *minio.LegalHoldStatus) *probe.Error return nil } -// Get object lock configuration of bucket. +// GetObjectLockConfig - Get object lock configuration of bucket. func (c *S3Client) GetObjectLockConfig() (mode *minio.RetentionMode, validity *uint, unit *minio.ValidityUnit, perr *probe.Error) { bucket, _ := c.url2BucketAndObject() @@ -2097,7 +2098,7 @@ func (c *S3Client) GetObjectLockConfig() (mode *minio.RetentionMode, validity *u return mode, validity, unit, nil } -// Get Object Tags +// GetObjectTagging - Get Object Tags func (c *S3Client) GetObjectTagging() (tagging.Tagging, *probe.Error) { var err error bucketName, objectName := c.url2BucketAndObject() @@ -2118,7 +2119,7 @@ func (c *S3Client) GetObjectTagging() (tagging.Tagging, *probe.Error) { return tagObj, nil } -// Set Object tags +// SetObjectTagging - Set Object tags func (c *S3Client) SetObjectTagging(tagMap map[string]string) *probe.Error { var err error bucketName, objectName := c.url2BucketAndObject() @@ -2134,7 +2135,7 @@ func (c *S3Client) SetObjectTagging(tagMap map[string]string) *probe.Error { return nil } -// Delete object tags +// DeleteObjectTagging - Delete object tags func (c *S3Client) DeleteObjectTagging() *probe.Error { bucketName, objectName := c.url2BucketAndObject() if bucketName == "" { diff --git a/cmd/client-url.go b/cmd/client-url.go index 7bb5fcce..21e6d8e8 100644 --- a/cmd/client-url.go +++ b/cmd/client-url.go @@ -27,9 +27,9 @@ import ( "github.com/minio/minio/pkg/mimedb" ) -// url client url structure -type clientURL struct { - Type clientURLType +// ClientURL url client url structure +type ClientURL struct { + Type ClientURLType Scheme string Host string Path string @@ -37,8 +37,8 @@ type clientURL struct { Separator rune } -// clientURLType - enum of different url types -type clientURLType int +// ClientURLType - enum of different url types +type ClientURLType int // enum types const ( @@ -91,7 +91,7 @@ func getHost(authority string) (host string) { } // newClientURL returns an abstracted URL for filesystems and object storage. -func newClientURL(urlStr string) *clientURL { +func newClientURL(urlStr string) *ClientURL { scheme, rest := getScheme(urlStr) if strings.HasPrefix(rest, "//") { // if rest has '//' prefix, skip them @@ -102,7 +102,7 @@ func newClientURL(urlStr string) *clientURL { } host := getHost(authority) if host != "" && (scheme == "http" || scheme == "https") { - return &clientURL{ + return &ClientURL{ Scheme: scheme, Type: objectStorage, Host: host, @@ -112,7 +112,7 @@ func newClientURL(urlStr string) *clientURL { } } } - return &clientURL{ + return &ClientURL{ Type: fileSystem, Path: rest, Separator: filepath.Separator, @@ -120,7 +120,7 @@ func newClientURL(urlStr string) *clientURL { } // joinURLs join two input urls and returns a url -func joinURLs(url1, url2 *clientURL) *clientURL { +func joinURLs(url1, url2 *ClientURL) *ClientURL { var url1Path, url2Path string url1Path = filepath.ToSlash(url1.Path) url2Path = filepath.ToSlash(url2.Path) @@ -133,7 +133,7 @@ func joinURLs(url1, url2 *clientURL) *clientURL { } // String convert URL into its canonical form. -func (u clientURL) String() string { +func (u ClientURL) String() string { var buf bytes.Buffer // if fileSystem no translation needed, return as is. if u.Type == fileSystem { @@ -171,7 +171,7 @@ func urlJoinPath(url1, url2 string) string { } // url2Stat returns stat info for URL. -func url2Stat(urlStr string, isFetchMeta, fileAttr bool, encKeyDB map[string][]prefixSSEPair) (client Client, content *clientContent, err *probe.Error) { +func url2Stat(urlStr string, isFetchMeta, fileAttr bool, encKeyDB map[string][]prefixSSEPair) (client Client, content *ClientContent, err *probe.Error) { client, err = newClient(urlStr) if err != nil { return nil, nil, err.Trace(urlStr) diff --git a/cmd/client.go b/cmd/client.go index e2357155..c20ee3c8 100644 --- a/cmd/client.go +++ b/cmd/client.go @@ -46,8 +46,8 @@ const defaultMultipartThreadsNum = 4 // Client - client interface type Client interface { // Common operations - Stat(isIncomplete, isFetchMeta, isPreserve bool, sse encrypt.ServerSide) (content *clientContent, err *probe.Error) - List(isRecursive, isIncomplete, isFetchMeta bool, showDir DirOpt) <-chan *clientContent + Stat(isIncomplete, isFetchMeta, isPreserve bool, sse encrypt.ServerSide) (content *ClientContent, err *probe.Error) + List(isRecursive, isIncomplete, isFetchMeta bool, showDir DirOpt) <-chan *ClientContent // Bucket operations MakeBucket(region string, ignoreExisting, withLock bool) *probe.Error @@ -77,13 +77,13 @@ type Client interface { ShareUpload(bool, time.Duration, string) (string, map[string]string, *probe.Error) // Watch events - Watch(params watchParams) (*watchObject, *probe.Error) + Watch(params watchParams) (*WatchObject, *probe.Error) // Delete operations - Remove(isIncomplete, isRemoveBucket bool, contentCh <-chan *clientContent) (errorCh <-chan *probe.Error) + Remove(isIncomplete, isRemoveBucket bool, contentCh <-chan *ClientContent) (errorCh <-chan *probe.Error) // GetURL returns back internal url - GetURL() clientURL + GetURL() ClientURL AddUserAgent(app, version string) @@ -93,9 +93,9 @@ type Client interface { DeleteObjectTagging() *probe.Error } -// Content container for content metadata -type clientContent struct { - URL clientURL +// ClientContent - Content container for content metadata +type ClientContent struct { + URL ClientURL Time time.Time Size int64 Type os.FileMode diff --git a/cmd/config-fix.go b/cmd/config-fix.go index e0eee2c0..6d327cbf 100644 --- a/cmd/config-fix.go +++ b/cmd/config-fix.go @@ -137,7 +137,7 @@ func fixConfigV6ForHosts() { newCfgV6.Aliases[k] = v } - url := &clientURL{} + url := &ClientURL{} // Copy hosts. for host, hostCfgV6 := range brokenMcCfgV6.Data().(*configV6).Hosts { // Already fixed - Copy and move on. diff --git a/cmd/cp-url-syntax.go b/cmd/cp-url-syntax.go index ee76d62c..e4b1beec 100644 --- a/cmd/cp-url-syntax.go +++ b/cmd/cp-url-syntax.go @@ -32,7 +32,7 @@ func checkCopySyntax(ctx *cli.Context, encKeyDB map[string][]prefixSSEPair) { // extract URLs. URLs := ctx.Args() if len(URLs) < 2 { - fatalIf(errDummy().Trace(ctx.Args()...), fmt.Sprintf("Unable to parse source and target arguments.")) + fatalIf(errDummy().Trace(ctx.Args()...), "Unable to parse source and target arguments.") } srcURLs := URLs[:len(URLs)-1] diff --git a/cmd/cp-url.go b/cmd/cp-url.go index 47210f77..7f922976 100644 --- a/cmd/cp-url.go +++ b/cmd/cp-url.go @@ -103,8 +103,8 @@ func prepareCopyURLsTypeA(sourceURL string, targetURL string, encKeyDB map[strin } // prepareCopyContentTypeA - makes CopyURLs content for copying. -func makeCopyContentTypeA(sourceAlias string, sourceContent *clientContent, targetAlias string, targetURL string, encKeyDB map[string][]prefixSSEPair) URLs { - targetContent := clientContent{URL: *newClientURL(targetURL)} +func makeCopyContentTypeA(sourceAlias string, sourceContent *ClientContent, targetAlias string, targetURL string, encKeyDB map[string][]prefixSSEPair) URLs { + targetContent := ClientContent{URL: *newClientURL(targetURL)} return URLs{ SourceAlias: sourceAlias, SourceContent: sourceContent, @@ -140,7 +140,7 @@ func prepareCopyURLsTypeB(sourceURL string, targetURL string, encKeyDB map[strin } // makeCopyContentTypeB - CopyURLs content for copying. -func makeCopyContentTypeB(sourceAlias string, sourceContent *clientContent, targetAlias string, targetURL string, encKeyDB map[string][]prefixSSEPair) URLs { +func makeCopyContentTypeB(sourceAlias string, sourceContent *ClientContent, targetAlias string, targetURL string, encKeyDB map[string][]prefixSSEPair) URLs { // All OK.. We can proceed. Type B: source is a file, target is a folder and exists. targetURLParse := newClientURL(targetURL) targetURLParse.Path = filepath.ToSlash(filepath.Join(targetURLParse.Path, filepath.Base(sourceContent.URL.Path))) @@ -185,7 +185,7 @@ func prepareCopyURLsTypeC(sourceURL, targetURL string, isRecursive bool, encKeyD } // makeCopyContentTypeC - CopyURLs content for copying. -func makeCopyContentTypeC(sourceAlias string, sourceURL clientURL, sourceContent *clientContent, targetAlias string, targetURL string, encKeyDB map[string][]prefixSSEPair) URLs { +func makeCopyContentTypeC(sourceAlias string, sourceURL ClientURL, sourceContent *ClientContent, targetAlias string, targetURL string, encKeyDB map[string][]prefixSSEPair) URLs { newSourceURL := sourceContent.URL pathSeparatorIndex := strings.LastIndex(sourceURL.Path, string(sourceURL.Separator)) newSourceSuffix := filepath.ToSlash(newSourceURL.Path) diff --git a/cmd/diff-main.go b/cmd/diff-main.go index 9fb9d8be..c0710fc0 100644 --- a/cmd/diff-main.go +++ b/cmd/diff-main.go @@ -72,8 +72,8 @@ type diffMessage struct { SecondURL string `json:"second"` Diff differType `json:"diff"` Error *probe.Error `json:"error,omitempty"` - firstContent *clientContent - secondContent *clientContent + firstContent *ClientContent + secondContent *ClientContent } // String colorized diff message diff --git a/cmd/difference.go b/cmd/difference.go index b7d6ab48..e848fce0 100644 --- a/cmd/difference.go +++ b/cmd/difference.go @@ -62,7 +62,7 @@ func (d differType) String() string { const multiMasterETagKey = "X-Amz-Meta-Mm-Etag" const multiMasterSTagKey = "X-Amz-Meta-Mm-Stag" -func eTagMatch(src, tgt *clientContent) bool { +func eTagMatch(src, tgt *ClientContent) bool { if tgt.UserMetadata[multiMasterETagKey] != "" { if tgt.UserMetadata[multiMasterETagKey] == src.UserMetadata[multiMasterETagKey] || tgt.UserMetadata[multiMasterETagKey] == src.ETag { return true diff --git a/cmd/event-list.go b/cmd/event-list.go index 0f077de7..22e42a3b 100644 --- a/cmd/event-list.go +++ b/cmd/event-list.go @@ -86,7 +86,7 @@ func (u eventListMessage) String() string { msg += "," } } - msg += console.Colorize("Filter", fmt.Sprintf(" Filter: ")) + msg += console.Colorize("Filter", " Filter: ") if u.Prefix != "" { msg += console.Colorize("Filter", fmt.Sprintf("prefix=\"%s\"", u.Prefix)) } diff --git a/cmd/find_test.go b/cmd/find_test.go index e86620f7..f2b30b1d 100644 --- a/cmd/find_test.go +++ b/cmd/find_test.go @@ -31,61 +31,61 @@ func TestMatchFind(t *testing.T) { var listFindContexts = []*findContext{ { clnt: &S3Client{ - targetURL: &clientURL{}, + targetURL: &ClientURL{}, }, ignorePattern: "*.go", }, { clnt: &S3Client{ - targetURL: &clientURL{}, + targetURL: &ClientURL{}, }, namePattern: "console", }, { clnt: &S3Client{ - targetURL: &clientURL{}, + targetURL: &ClientURL{}, }, pathPattern: "*console*", }, { clnt: &S3Client{ - targetURL: &clientURL{}, + targetURL: &ClientURL{}, }, regexPattern: `^(\d+\.){3}\d+$`, }, { clnt: &S3Client{ - targetURL: &clientURL{}, + targetURL: &ClientURL{}, }, olderThan: "1d", }, { clnt: &S3Client{ - targetURL: &clientURL{}, + targetURL: &ClientURL{}, }, newerThan: "32000d", }, { clnt: &S3Client{ - targetURL: &clientURL{}, + targetURL: &ClientURL{}, }, largerSize: 1024 * 1024, }, { clnt: &S3Client{ - targetURL: &clientURL{}, + targetURL: &ClientURL{}, }, smallerSize: 1024, }, { clnt: &S3Client{ - targetURL: &clientURL{}, + targetURL: &ClientURL{}, }, ignorePattern: "*.txt", }, { clnt: &S3Client{ - targetURL: &clientURL{}, + targetURL: &ClientURL{}, }, }, } diff --git a/cmd/lock-main.go b/cmd/lock-main.go index f740befd..55f96abb 100644 --- a/cmd/lock-main.go +++ b/cmd/lock-main.go @@ -80,7 +80,7 @@ type lockCmdMessage struct { // Colorized message for console printing. func (m lockCmdMessage) String() string { if m.Mode == nil { - return fmt.Sprintf("No object lock configuration is enabled") + return "No object lock configuration is enabled" } return fmt.Sprintf("%s mode is enabled for %s", console.Colorize("Mode", *m.Mode), console.Colorize("Validity", *m.Validity)) diff --git a/cmd/ls-main.go b/cmd/ls-main.go index efa8a15a..a7f5e423 100644 --- a/cmd/ls-main.go +++ b/cmd/ls-main.go @@ -132,7 +132,7 @@ func mainList(ctx *cli.Context) error { fatalIf(err.Trace(targetURL), "Unable to initialize target `"+targetURL+"`.") if !strings.HasSuffix(targetURL, string(clnt.GetURL().Separator)) { - var st *clientContent + var st *ClientContent st, err = clnt.Stat(isIncomplete, false, false, nil) if st != nil && err == nil && st.Type.IsDir() { targetURL = targetURL + string(clnt.GetURL().Separator) diff --git a/cmd/ls.go b/cmd/ls.go index bbf2ddc8..f3f3dfe0 100644 --- a/cmd/ls.go +++ b/cmd/ls.go @@ -67,7 +67,7 @@ func (c contentMessage) JSON() string { } // parseContent parse client Content container into printer struct. -func parseContent(c *clientContent) contentMessage { +func parseContent(c *ClientContent) contentMessage { content := contentMessage{} content.Time = c.Time.Local() @@ -89,7 +89,7 @@ func parseContent(c *clientContent) contentMessage { } // get content key -func getKey(c *clientContent) string { +func getKey(c *ClientContent) string { sep := "/" // for windows make sure to print in 'windows' specific style. diff --git a/cmd/main.go b/cmd/main.go index 339d107e..0c7916f1 100644 --- a/cmd/main.go +++ b/cmd/main.go @@ -125,7 +125,7 @@ func commandNotFound(ctx *cli.Context, command string) { msg := fmt.Sprintf("`%s` is not a mc command. See `mc --help`.", command) closestCommands := findClosestCommands(command) if len(closestCommands) > 0 { - msg += fmt.Sprintf("\n\nDid you mean one of these?\n") + msg += "\n\nDid you mean one of these?\n" if len(closestCommands) == 1 { cmd := closestCommands[0] msg += fmt.Sprintf(" `%s`", cmd) diff --git a/cmd/mirror-main.go b/cmd/mirror-main.go index f5cb42ff..3f51df5a 100644 --- a/cmd/mirror-main.go +++ b/cmd/mirror-main.go @@ -249,8 +249,8 @@ func (mj *mirrorJob) doRemove(sURLs URLs) URLs { return sURLs.WithError(pErr) } clnt.AddUserAgent(uaMirrorAppName, Version) - contentCh := make(chan *clientContent, 1) - contentCh <- &clientContent{URL: *newClientURL(sURLs.TargetContent.URL.Path)} + contentCh := make(chan *ClientContent, 1) + contentCh <- &ClientContent{URL: *newClientURL(sURLs.TargetContent.URL.Path)} close(contentCh) isRemoveBucket := false errorCh := clnt.Remove(false, isRemoveBucket, contentCh) @@ -431,14 +431,14 @@ func (mj *mirrorJob) watchMirror(ctx context.Context, cancelMirror context.Cance (event.Type == EventCreatePutRetention) { mirrorURL := URLs{ SourceAlias: sourceAlias, - SourceContent: &clientContent{ + SourceContent: &ClientContent{ URL: *sourceURL, Retention: event.Type == EventCreatePutRetention, Size: event.Size, Metadata: event.UserMetadata, }, TargetAlias: targetAlias, - TargetContent: &clientContent{URL: *targetURL}, + TargetContent: &ClientContent{URL: *targetURL}, encKeyDB: mj.encKeyDB, } if mirrorURL.SourceContent.Metadata[multiMasterETagKey] != "" { @@ -510,7 +510,7 @@ func (mj *mirrorJob) watchMirror(ctx context.Context, cancelMirror context.Cance SourceAlias: sourceAlias, SourceContent: nil, TargetAlias: targetAlias, - TargetContent: &clientContent{URL: *targetURL}, + TargetContent: &ClientContent{URL: *targetURL}, encKeyDB: mj.encKeyDB, } mirrorURL.TotalCount = mj.status.GetCounts() @@ -845,10 +845,10 @@ func runMirror(srcURL, dstURL string, ctx *cli.Context, encKeyDB map[string][]pr // and queue them for copying. if err := mj.watchURL(newSrcClt); err != nil { if mj.multiMasterEnable { - errorIf(err, fmt.Sprintf("Failed to start monitoring.")) + errorIf(err, "Failed to start monitoring.") return true } - mj.status.fatalIf(err, fmt.Sprintf("Failed to start monitoring.")) + mj.status.fatalIf(err, "Failed to start monitoring.") } } } @@ -893,10 +893,10 @@ func runMirror(srcURL, dstURL string, ctx *cli.Context, encKeyDB map[string][]pr // and queue them for copying. if err := mj.watchURL(srcClt); err != nil { if mj.multiMasterEnable { - errorIf(err, fmt.Sprintf("Failed to start monitoring.")) + errorIf(err, "Failed to start monitoring.") return true } - mj.status.fatalIf(err, fmt.Sprintf("Failed to start monitoring.")) + mj.status.fatalIf(err, "Failed to start monitoring.") } } diff --git a/cmd/mirror-url.go b/cmd/mirror-url.go index 5ed992c4..2f56e613 100644 --- a/cmd/mirror-url.go +++ b/cmd/mirror-url.go @@ -160,7 +160,7 @@ func deltaSourceTarget(sourceURL, targetURL string, isFake, isOverwrite, isRemov // Either available only in source or size differs and force is set targetPath := urlJoinPath(targetURL, sourceSuffix) sourceContent := diffMsg.firstContent - targetContent := &clientContent{URL: *newClientURL(targetPath)} + targetContent := &ClientContent{URL: *newClientURL(targetPath)} URLsCh <- URLs{ SourceAlias: sourceAlias, SourceContent: sourceContent, @@ -172,7 +172,7 @@ func deltaSourceTarget(sourceURL, targetURL string, isFake, isOverwrite, isRemov sourceSuffix := strings.TrimPrefix(diffMsg.FirstURL, sourceURL) targetPath := urlJoinPath(targetURL, sourceSuffix) sourceContent := diffMsg.firstContent - targetContent := &clientContent{URL: *newClientURL(targetPath)} + targetContent := &ClientContent{URL: *newClientURL(targetPath)} URLsCh <- URLs{ SourceAlias: sourceAlias, SourceContent: sourceContent, diff --git a/cmd/rb-main.go b/cmd/rb-main.go index 6d003d0f..28f24f69 100644 --- a/cmd/rb-main.go +++ b/cmd/rb-main.go @@ -121,7 +121,7 @@ func deleteBucket(url string) *probe.Error { } var isIncomplete bool isRemoveBucket := true - contentCh := make(chan *clientContent) + contentCh := make(chan *ClientContent) errorCh := clnt.Remove(isIncomplete, isRemoveBucket, contentCh) for content := range clnt.List(true, false, false, DirLast) { @@ -166,7 +166,7 @@ func deleteBucket(url string) *probe.Error { // Remove the given url since the user will always want to remove it. alias, _ := url2Alias(targetURL) if alias != "" { - contentCh <- &clientContent{URL: *newClientURL(targetURL)} + contentCh <- &ClientContent{URL: *newClientURL(targetURL)} } // Finish removing and print all the remaining errors diff --git a/cmd/rm-main.go b/cmd/rm-main.go index db1a5807..1b597eca 100644 --- a/cmd/rm-main.go +++ b/cmd/rm-main.go @@ -223,8 +223,8 @@ func removeSingle(url string, isIncomplete bool, isFake, isForce bool, olderThan targetURL = targetURL + string(clnt.GetURL().Separator) } - contentCh := make(chan *clientContent, 1) - contentCh <- &clientContent{URL: *newClientURL(targetURL)} + contentCh := make(chan *ClientContent, 1) + contentCh <- &ClientContent{URL: *newClientURL(targetURL)} close(contentCh) isRemoveBucket := false errorCh := clnt.Remove(isIncomplete, isRemoveBucket, contentCh) @@ -250,7 +250,7 @@ func removeRecursive(url string, isIncomplete bool, isFake bool, olderThan, newe errorIf(pErr.Trace(url), "Failed to remove `"+url+"` recursively.") return exitStatus(globalErrorExitStatus) // End of journey. } - contentCh := make(chan *clientContent) + contentCh := make(chan *ClientContent) isRemoveBucket := false errorCh := clnt.Remove(isIncomplete, isRemoveBucket, contentCh) diff --git a/cmd/share-download-main.go b/cmd/share-download-main.go index 69baf284..908a50c7 100644 --- a/cmd/share-download-main.go +++ b/cmd/share-download-main.go @@ -124,7 +124,7 @@ func doShareDownloadURL(targetURL string, isRecursive bool, expiry time.Duration isIncomplete := false isFetchMeta := false // Channel which will receive objects whose URLs need to be shared - objectsCh := make(chan *clientContent) + objectsCh := make(chan *ClientContent) content, err := clnt.Stat(isIncomplete, isFetchMeta, false, nil) if err != nil { diff --git a/cmd/stat.go b/cmd/stat.go index 4760b067..6eec2b1e 100644 --- a/cmd/stat.go +++ b/cmd/stat.go @@ -102,7 +102,7 @@ func (c statMessage) JSON() string { } // parseStat parses client Content container into statMessage struct. -func parseStat(c *clientContent) statMessage { +func parseStat(c *ClientContent) statMessage { content := statMessage{} content.Date = c.Time.Local() // guess file type. @@ -127,8 +127,8 @@ func getStandardizedURL(targetURL string) string { } // statURL - simple or recursive listing -func statURL(targetURL string, isIncomplete, isRecursive bool, encKeyDB map[string][]prefixSSEPair) ([]*clientContent, *probe.Error) { - var stats []*clientContent +func statURL(targetURL string, isIncomplete, isRecursive bool, encKeyDB map[string][]prefixSSEPair) ([]*ClientContent, *probe.Error) { + var stats []*ClientContent var clnt Client clnt, err := newClient(targetURL) if err != nil { diff --git a/cmd/stat_test.go b/cmd/stat_test.go index b2325480..a89d05c0 100644 --- a/cmd/stat_test.go +++ b/cmd/stat_test.go @@ -27,13 +27,13 @@ import ( func TestParseStat(t *testing.T) { localTime := time.Unix(12001, 0).UTC() testCases := []struct { - content clientContent + content ClientContent targetAlias string }{ - {clientContent{URL: *newClientURL("https://play.min.io/abc"), Size: 0, Time: localTime, Type: os.ModeDir, ETag: "blahblah", Metadata: map[string]string{"cusom-key": "custom-value"}, Expires: time.Now()}, "play"}, - {clientContent{URL: *newClientURL("https://play.min.io/testbucket"), Size: 500, Time: localTime, Type: os.ModeDir, ETag: "blahblah", Metadata: map[string]string{"cusom-key": "custom-value"}, Expires: time.Unix(0, 0).UTC()}, "play"}, - {clientContent{URL: *newClientURL("https://s3.amazonaws.com/yrdy"), Size: 0, Time: localTime, Type: 0644, ETag: "abcdefasaas", Metadata: map[string]string{}}, "s3"}, - {clientContent{URL: *newClientURL("https://play.min.io/yrdy"), Size: 10000, Time: localTime, Type: 0644, ETag: "blahblah", Metadata: map[string]string{"cusom-key": "custom-value"}}, "play"}, + {ClientContent{URL: *newClientURL("https://play.min.io/abc"), Size: 0, Time: localTime, Type: os.ModeDir, ETag: "blahblah", Metadata: map[string]string{"cusom-key": "custom-value"}, Expires: time.Now()}, "play"}, + {ClientContent{URL: *newClientURL("https://play.min.io/testbucket"), Size: 500, Time: localTime, Type: os.ModeDir, ETag: "blahblah", Metadata: map[string]string{"cusom-key": "custom-value"}, Expires: time.Unix(0, 0).UTC()}, "play"}, + {ClientContent{URL: *newClientURL("https://s3.amazonaws.com/yrdy"), Size: 0, Time: localTime, Type: 0644, ETag: "abcdefasaas", Metadata: map[string]string{}}, "s3"}, + {ClientContent{URL: *newClientURL("https://play.min.io/yrdy"), Size: 10000, Time: localTime, Type: 0644, ETag: "blahblah", Metadata: map[string]string{"cusom-key": "custom-value"}}, "play"}, } for _, testCase := range testCases { testCase := testCase diff --git a/cmd/tree-main.go b/cmd/tree-main.go index 1f6a8126..af373943 100644 --- a/cmd/tree-main.go +++ b/cmd/tree-main.go @@ -143,7 +143,7 @@ func doTree(url string, level int, leaf bool, branchString string, depth int, in } bucketNameShowed := false - var prev *clientContent + var prev *ClientContent show := func(end bool) error { currbranchString := branchString if level == 1 && !bucketNameShowed { diff --git a/cmd/urls.go b/cmd/urls.go index d39a8f34..61def1db 100644 --- a/cmd/urls.go +++ b/cmd/urls.go @@ -23,9 +23,9 @@ import ( // URLs contains source and target urls type URLs struct { SourceAlias string - SourceContent *clientContent + SourceContent *ClientContent TargetAlias string - TargetContent *clientContent + TargetContent *ClientContent TotalCount int64 TotalSize int64 DisableMultipart bool diff --git a/cmd/watch.go b/cmd/watch.go index 053d31b0..127feaad 100644 --- a/cmd/watch.go +++ b/cmd/watch.go @@ -65,7 +65,8 @@ type watchParams struct { recursive bool } -type watchObject struct { +// WatchObject captures watch channels to read and listen on. +type WatchObject struct { // eventInfo will be put on this chan eventInfoChan chan EventInfo // errors will be put on this chan @@ -75,17 +76,17 @@ type watchObject struct { } // Events returns the chan receiving events -func (w *watchObject) Events() chan EventInfo { +func (w *WatchObject) Events() chan EventInfo { return w.eventInfoChan } // Errors returns the chan receiving errors -func (w *watchObject) Errors() chan *probe.Error { +func (w *WatchObject) Errors() chan *probe.Error { return w.errorChan } // Close the watcher, will stop all goroutines -func (w *watchObject) Close() { +func (w *WatchObject) Close() { // Cleanup close(w.eventInfoChan) close(w.errorChan) @@ -102,7 +103,7 @@ type Watcher struct { eventInfoChan chan EventInfo // array of watchers joined - o []*watchObject + o []*WatchObject // all watchers joining will enter this waitgroup wg sync.WaitGroup @@ -114,7 +115,7 @@ func NewWatcher(sessionStartTime time.Time) *Watcher { sessionStartTime: sessionStartTime, errorChan: make(chan *probe.Error), eventInfoChan: make(chan EventInfo), - o: []*watchObject{}, + o: []*WatchObject{}, } }