Close readers returned by Client.Get (#2595)

Change Client.Get to return an io.ReadCloser instead of io.Reader
so that it can be closed.
This commit is contained in:
Kale Blankenship
2018-11-08 17:02:14 -08:00
committed by kannappanr
parent b827fac635
commit 8137e79d0c
5 changed files with 9 additions and 7 deletions
+2 -1
View File
@@ -140,7 +140,7 @@ func checkCatSyntax(ctx *cli.Context) {
// catURL displays contents of a URL to stdout.
func catURL(sourceURL string, encKeyDB map[string][]prefixSSEPair) *probe.Error {
var reader io.Reader
var reader io.ReadCloser
size := int64(-1)
switch sourceURL {
case "-":
@@ -159,6 +159,7 @@ func catURL(sourceURL string, encKeyDB map[string][]prefixSSEPair) *probe.Error
if reader, err = getSourceStreamFromURL(sourceURL, encKeyDB); err != nil {
return err.Trace(sourceURL)
}
defer reader.Close()
}
return catOut(reader, size).Trace(sourceURL)
}
+2 -2
View File
@@ -422,7 +422,7 @@ func (f *fsClient) Copy(source string, size int64, progress io.Reader, srcSSEKey
}
// get - get wrapper returning object reader.
func (f *fsClient) get() (io.Reader, *probe.Error) {
func (f *fsClient) get() (io.ReadCloser, *probe.Error) {
tmppath := f.PathURL.Path
// Golang strips trailing / if you clean(..) or
// EvalSymlinks(..). Adding '.' prevents it from doing so.
@@ -445,7 +445,7 @@ func (f *fsClient) get() (io.Reader, *probe.Error) {
}
// Get returns reader and any additional metadata.
func (f *fsClient) Get(sseKey string) (io.Reader, *probe.Error) {
func (f *fsClient) Get(sseKey string) (io.ReadCloser, *probe.Error) {
return f.get()
}
+1 -1
View File
@@ -572,7 +572,7 @@ func (c *s3Client) Watch(params watchParams) (*watchObject, *probe.Error) {
}
// Get - get object with metadata.
func (c *s3Client) Get(sseKey string) (io.Reader, *probe.Error) {
func (c *s3Client) Get(sseKey string) (io.ReadCloser, *probe.Error) {
bucket, object := c.url2BucketAndObject()
var opts minio.GetObjectOptions
if sseKey != "" {
+1 -1
View File
@@ -62,7 +62,7 @@ type Client interface {
Select(expression string, sseKey string) (io.ReadCloser, *probe.Error)
// I/O operations with metadata.
Get(sseKey string) (reader io.Reader, err *probe.Error)
Get(sseKey string) (reader io.ReadCloser, err *probe.Error)
Put(ctx context.Context, reader io.Reader, size int64, metadata map[string]string, progress io.Reader, sseKey string) (n int64, err *probe.Error)
// I/O operations with expiration
+3 -2
View File
@@ -83,7 +83,7 @@ func isAliasURLDir(aliasURL string, keys map[string][]prefixSSEPair) bool {
}
// getSourceStreamFromURL gets a reader from URL.
func getSourceStreamFromURL(urlStr string, encKeyDB map[string][]prefixSSEPair) (reader io.Reader, err *probe.Error) {
func getSourceStreamFromURL(urlStr string, encKeyDB map[string][]prefixSSEPair) (reader io.ReadCloser, err *probe.Error) {
alias, urlStrFull, _, err := expandAlias(urlStr)
if err != nil {
return nil, err.Trace(urlStr)
@@ -94,7 +94,7 @@ func getSourceStreamFromURL(urlStr string, encKeyDB map[string][]prefixSSEPair)
}
// getSourceStream gets a reader from URL.
func getSourceStream(alias string, urlStr string, fetchStat bool, sseKey string) (reader io.Reader, metadata map[string]string, err *probe.Error) {
func getSourceStream(alias string, urlStr string, fetchStat bool, sseKey string) (reader io.ReadCloser, metadata map[string]string, err *probe.Error) {
sourceClnt, err := newClientFromAlias(alias, urlStr)
if err != nil {
return nil, nil, err.Trace(alias, urlStr)
@@ -180,6 +180,7 @@ func uploadSourceToTargetURL(ctx context.Context, urls URLs, progress io.Reader)
if err != nil {
return urls.WithError(err.Trace(sourceURL.String()))
}
defer reader.Close()
// Get metadata from target content as well
if urls.TargetContent.Metadata != nil {
for k, v := range urls.TargetContent.Metadata {