| 
									
										
										
										
											2016-04-30 08:52:17 +08:00
										 |  |  | /* | 
					
						
							| 
									
										
										
										
											2019-04-18 00:52:08 +08:00
										 |  |  |  * MinIO Cloud Storage, (C) 2016-2019 MinIO, Inc. | 
					
						
							| 
									
										
										
										
											2016-04-30 08:52:17 +08:00
										 |  |  |  * | 
					
						
							|  |  |  |  * Licensed under the Apache License, Version 2.0 (the "License"); | 
					
						
							|  |  |  |  * you may not use this file except in compliance with the License. | 
					
						
							|  |  |  |  * You may obtain a copy of the License at | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  *     http://www.apache.org/licenses/LICENSE-2.0
 | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * Unless required by applicable law or agreed to in writing, software | 
					
						
							|  |  |  |  * distributed under the License is distributed on an "AS IS" BASIS, | 
					
						
							|  |  |  |  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | 
					
						
							|  |  |  |  * See the License for the specific language governing permissions and | 
					
						
							|  |  |  |  * limitations under the License. | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-08-19 07:23:42 +08:00
										 |  |  | package cmd | 
					
						
							| 
									
										
										
										
											2016-04-30 08:52:17 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-05-25 16:33:39 +08:00
										 |  |  | import ( | 
					
						
							| 
									
										
										
										
											2018-03-16 04:27:16 +08:00
										 |  |  | 	"context" | 
					
						
							| 
									
										
										
										
											2018-01-30 10:43:13 +08:00
										 |  |  | 	"path" | 
					
						
							| 
									
										
										
										
											2016-05-25 16:33:39 +08:00
										 |  |  | 	"sync" | 
					
						
							| 
									
										
										
										
											2016-11-23 10:18:22 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	humanize "github.com/dustin/go-humanize" | 
					
						
							| 
									
										
										
										
											2018-04-06 06:04:40 +08:00
										 |  |  | 	"github.com/minio/minio/cmd/logger" | 
					
						
							| 
									
										
										
										
											2016-05-25 16:33:39 +08:00
										 |  |  | ) | 
					
						
							| 
									
										
										
										
											2016-04-30 08:52:17 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-05-30 06:38:14 +08:00
										 |  |  | const ( | 
					
						
							|  |  |  | 	// Block size used for all internal operations version 1.
 | 
					
						
							| 
									
										
										
										
											2016-11-23 10:18:22 +08:00
										 |  |  | 	blockSizeV1 = 10 * humanize.MiByte | 
					
						
							| 
									
										
										
										
											2016-06-25 18:03:27 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	// Staging buffer read size for all internal operations version 1.
 | 
					
						
							| 
									
										
										
										
											2016-11-23 10:18:22 +08:00
										 |  |  | 	readSizeV1 = 1 * humanize.MiByte | 
					
						
							| 
									
										
										
										
											2016-07-22 08:31:14 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	// Buckets meta prefix.
 | 
					
						
							|  |  |  | 	bucketMetaPrefix = "buckets" | 
					
						
							| 
									
										
										
										
											2017-04-11 10:51:23 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-05-15 03:05:51 +08:00
										 |  |  | 	// ETag (hex encoded md5sum) of empty string.
 | 
					
						
							|  |  |  | 	emptyETag = "d41d8cd98f00b204e9800998ecf8427e" | 
					
						
							| 
									
										
										
										
											2016-05-30 06:38:14 +08:00
										 |  |  | ) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-10-10 14:03:10 +08:00
										 |  |  | // Global object layer mutex, used for safely updating object layer.
 | 
					
						
							| 
									
										
										
										
											2017-03-03 17:07:45 +08:00
										 |  |  | var globalObjLayerMutex *sync.RWMutex | 
					
						
							| 
									
										
										
										
											2016-10-10 14:03:10 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | // Global object layer, only accessed by newObjectLayerFn().
 | 
					
						
							|  |  |  | var globalObjectAPI ObjectLayer | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-03-29 05:14:06 +08:00
										 |  |  | //Global cacheObjects, only accessed by newCacheObjectsFn().
 | 
					
						
							|  |  |  | var globalCacheObjectAPI CacheObjectLayer | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-10-10 14:03:10 +08:00
										 |  |  | func init() { | 
					
						
							|  |  |  | 	// Initialize this once per server initialization.
 | 
					
						
							| 
									
										
										
										
											2017-03-03 17:07:45 +08:00
										 |  |  | 	globalObjLayerMutex = &sync.RWMutex{} | 
					
						
							| 
									
										
										
										
											2016-10-10 14:03:10 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-21 08:33:01 +08:00
										 |  |  | // Checks if the object is a directory, this logic uses
 | 
					
						
							|  |  |  | // if size == 0 and object ends with slashSeparator then
 | 
					
						
							|  |  |  | // returns true.
 | 
					
						
							|  |  |  | func isObjectDir(object string, size int64) bool { | 
					
						
							| 
									
										
										
										
											2017-02-17 06:52:14 +08:00
										 |  |  | 	return hasSuffix(object, slashSeparator) && size == 0 | 
					
						
							| 
									
										
										
										
											2017-01-21 08:33:01 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | // Converts just bucket, object metadata into ObjectInfo datatype.
 | 
					
						
							|  |  |  | func dirObjectInfo(bucket, object string, size int64, metadata map[string]string) ObjectInfo { | 
					
						
							|  |  |  | 	// This is a special case with size as '0' and object ends with
 | 
					
						
							|  |  |  | 	// a slash separator, we treat it like a valid operation and
 | 
					
						
							|  |  |  | 	// return success.
 | 
					
						
							| 
									
										
										
										
											2017-05-15 03:05:51 +08:00
										 |  |  | 	etag := metadata["etag"] | 
					
						
							|  |  |  | 	delete(metadata, "etag") | 
					
						
							|  |  |  | 	if etag == "" { | 
					
						
							|  |  |  | 		etag = emptyETag | 
					
						
							| 
									
										
										
										
											2017-04-11 10:51:23 +08:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-21 08:33:01 +08:00
										 |  |  | 	return ObjectInfo{ | 
					
						
							|  |  |  | 		Bucket:      bucket, | 
					
						
							|  |  |  | 		Name:        object, | 
					
						
							| 
									
										
										
										
											2017-03-19 02:28:41 +08:00
										 |  |  | 		ModTime:     UTCNow(), | 
					
						
							| 
									
										
										
										
											2017-01-21 08:33:01 +08:00
										 |  |  | 		ContentType: "application/octet-stream", | 
					
						
							|  |  |  | 		IsDir:       true, | 
					
						
							|  |  |  | 		Size:        size, | 
					
						
							| 
									
										
										
										
											2017-05-15 03:05:51 +08:00
										 |  |  | 		ETag:        etag, | 
					
						
							| 
									
										
										
										
											2017-01-21 08:33:01 +08:00
										 |  |  | 		UserDefined: metadata, | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-04-06 06:04:40 +08:00
										 |  |  | func deleteBucketMetadata(ctx context.Context, bucket string, objAPI ObjectLayer) { | 
					
						
							| 
									
										
										
										
											2018-02-13 10:34:30 +08:00
										 |  |  | 	// Delete bucket access policy, if present - ignore any errors.
 | 
					
						
							| 
									
										
										
										
											2018-04-25 06:53:30 +08:00
										 |  |  | 	removePolicyConfig(ctx, objAPI, bucket) | 
					
						
							| 
									
										
										
										
											2018-02-13 10:34:30 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	// Delete notification config, if present - ignore any errors.
 | 
					
						
							| 
									
										
										
										
											2018-04-06 06:04:40 +08:00
										 |  |  | 	removeNotificationConfig(ctx, objAPI, bucket) | 
					
						
							| 
									
										
										
										
											2018-02-13 10:34:30 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	// Delete listener config, if present - ignore any errors.
 | 
					
						
							| 
									
										
										
										
											2018-04-06 06:04:40 +08:00
										 |  |  | 	removeListenerConfig(ctx, objAPI, bucket) | 
					
						
							| 
									
										
										
										
											2018-02-13 10:34:30 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-06-02 16:49:46 +08:00
										 |  |  | // Depending on the disk type network or local, initialize storage API.
 | 
					
						
							| 
									
										
										
										
											2017-04-12 06:44:27 +08:00
										 |  |  | func newStorageAPI(endpoint Endpoint) (storage StorageAPI, err error) { | 
					
						
							|  |  |  | 	if endpoint.IsLocal { | 
					
						
							|  |  |  | 		return newPosix(endpoint.Path) | 
					
						
							| 
									
										
										
										
											2016-06-02 16:49:46 +08:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2017-04-12 06:44:27 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-02-15 09:53:46 +08:00
										 |  |  | 	return newStorageRESTClient(endpoint) | 
					
						
							| 
									
										
										
										
											2016-06-02 16:49:46 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-05-09 01:15:34 +08:00
										 |  |  | // Cleanup a directory recursively.
 | 
					
						
							| 
									
										
										
										
											2018-04-06 06:04:40 +08:00
										 |  |  | func cleanupDir(ctx context.Context, storage StorageAPI, volume, dirPath string) error { | 
					
						
							| 
									
										
										
										
											2016-05-09 01:15:34 +08:00
										 |  |  | 	var delFunc func(string) error | 
					
						
							|  |  |  | 	// Function to delete entries recursively.
 | 
					
						
							|  |  |  | 	delFunc = func(entryPath string) error { | 
					
						
							| 
									
										
										
										
											2017-02-17 06:52:14 +08:00
										 |  |  | 		if !hasSuffix(entryPath, slashSeparator) { | 
					
						
							| 
									
										
										
										
											2016-07-12 16:01:47 +08:00
										 |  |  | 			// Delete the file entry.
 | 
					
						
							| 
									
										
										
										
											2018-04-06 06:04:40 +08:00
										 |  |  | 			err := storage.DeleteFile(volume, entryPath) | 
					
						
							|  |  |  | 			logger.LogIf(ctx, err) | 
					
						
							|  |  |  | 			return err | 
					
						
							| 
									
										
										
										
											2016-05-09 01:15:34 +08:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2016-07-12 16:01:47 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-05-09 01:15:34 +08:00
										 |  |  | 		// If it's a directory, list and call delFunc() for each entry.
 | 
					
						
							| 
									
										
										
										
											2019-04-24 05:54:28 +08:00
										 |  |  | 		entries, err := storage.ListDir(volume, entryPath, -1, "") | 
					
						
							| 
									
										
										
										
											2016-07-12 16:01:47 +08:00
										 |  |  | 		// If entryPath prefix never existed, safe to ignore.
 | 
					
						
							|  |  |  | 		if err == errFileNotFound { | 
					
						
							|  |  |  | 			return nil | 
					
						
							|  |  |  | 		} else if err != nil { // For any other errors fail.
 | 
					
						
							| 
									
										
										
										
											2018-04-06 06:04:40 +08:00
										 |  |  | 			logger.LogIf(ctx, err) | 
					
						
							|  |  |  | 			return err | 
					
						
							| 
									
										
										
										
											2016-07-12 16:01:47 +08:00
										 |  |  | 		} // else on success..
 | 
					
						
							| 
									
										
										
										
											2016-06-14 16:39:40 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-01-30 10:43:13 +08:00
										 |  |  | 		// Entry path is empty, just delete it.
 | 
					
						
							|  |  |  | 		if len(entries) == 0 { | 
					
						
							| 
									
										
										
										
											2018-04-06 06:04:40 +08:00
										 |  |  | 			err = storage.DeleteFile(volume, path.Clean(entryPath)) | 
					
						
							|  |  |  | 			logger.LogIf(ctx, err) | 
					
						
							|  |  |  | 			return err | 
					
						
							| 
									
										
										
										
											2018-01-30 10:43:13 +08:00
										 |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-07-12 16:01:47 +08:00
										 |  |  | 		// Recurse and delete all other entries.
 | 
					
						
							|  |  |  | 		for _, entry := range entries { | 
					
						
							|  |  |  | 			if err = delFunc(pathJoin(entryPath, entry)); err != nil { | 
					
						
							| 
									
										
										
										
											2016-05-09 01:15:34 +08:00
										 |  |  | 				return err | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		return nil | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2016-06-03 07:34:15 +08:00
										 |  |  | 	err := delFunc(retainSlash(pathJoin(dirPath))) | 
					
						
							|  |  |  | 	return err | 
					
						
							| 
									
										
										
										
											2016-05-09 01:15:34 +08:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2018-03-16 04:03:41 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-05-14 03:25:49 +08:00
										 |  |  | // Cleanup objects in bulk and recursively: each object will have a list of sub-files to delete in the backend
 | 
					
						
							|  |  |  | func cleanupObjectsBulk(ctx context.Context, storage StorageAPI, volume string, objsPaths []string, errs []error) ([]error, error) { | 
					
						
							|  |  |  | 	// The list of files in disk to delete
 | 
					
						
							|  |  |  | 	var filesToDelete []string | 
					
						
							|  |  |  | 	// Map files to delete to the passed objsPaths
 | 
					
						
							|  |  |  | 	var filesToDeleteObjsIndexes []int | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// Traverse and return the list of sub entries
 | 
					
						
							|  |  |  | 	var traverse func(string) ([]string, error) | 
					
						
							|  |  |  | 	traverse = func(entryPath string) ([]string, error) { | 
					
						
							|  |  |  | 		var output = make([]string, 0) | 
					
						
							|  |  |  | 		if !hasSuffix(entryPath, slashSeparator) { | 
					
						
							|  |  |  | 			output = append(output, entryPath) | 
					
						
							|  |  |  | 			return output, nil | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		entries, err := storage.ListDir(volume, entryPath, -1, "") | 
					
						
							|  |  |  | 		if err != nil { | 
					
						
							|  |  |  | 			if err == errFileNotFound { | 
					
						
							|  |  |  | 				return nil, nil | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 			return nil, err | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		for _, entry := range entries { | 
					
						
							|  |  |  | 			subEntries, err := traverse(pathJoin(entryPath, entry)) | 
					
						
							|  |  |  | 			if err != nil { | 
					
						
							|  |  |  | 				return nil, err | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 			output = append(output, subEntries...) | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		return output, nil | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// Find and collect the list of files to remove associated
 | 
					
						
							|  |  |  | 	// to the passed objects paths
 | 
					
						
							|  |  |  | 	for idx, objPath := range objsPaths { | 
					
						
							|  |  |  | 		if errs[idx] != nil { | 
					
						
							|  |  |  | 			continue | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		output, err := traverse(objPath) | 
					
						
							|  |  |  | 		if err != nil { | 
					
						
							|  |  |  | 			errs[idx] = err | 
					
						
							|  |  |  | 			continue | 
					
						
							|  |  |  | 		} else { | 
					
						
							|  |  |  | 			errs[idx] = nil | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		filesToDelete = append(filesToDelete, output...) | 
					
						
							|  |  |  | 		for i := 0; i < len(output); i++ { | 
					
						
							|  |  |  | 			filesToDeleteObjsIndexes = append(filesToDeleteObjsIndexes, idx) | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// Reverse the list so remove can succeed
 | 
					
						
							|  |  |  | 	reverseStringSlice(filesToDelete) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	dErrs, err := storage.DeleteFileBulk(volume, filesToDelete) | 
					
						
							|  |  |  | 	if err != nil { | 
					
						
							|  |  |  | 		return nil, err | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// Map files deletion errors to the correspondent objects
 | 
					
						
							|  |  |  | 	for i := range dErrs { | 
					
						
							|  |  |  | 		if dErrs[i] != nil { | 
					
						
							|  |  |  | 			if errs[filesToDeleteObjsIndexes[i]] != nil { | 
					
						
							|  |  |  | 				errs[filesToDeleteObjsIndexes[i]] = dErrs[i] | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return errs, nil | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-03-16 04:03:41 +08:00
										 |  |  | // Removes notification.xml for a given bucket, only used during DeleteBucket.
 | 
					
						
							| 
									
										
										
										
											2018-04-06 06:04:40 +08:00
										 |  |  | func removeNotificationConfig(ctx context.Context, objAPI ObjectLayer, bucket string) error { | 
					
						
							| 
									
										
										
										
											2018-03-16 04:03:41 +08:00
										 |  |  | 	// Verify bucket is valid.
 | 
					
						
							|  |  |  | 	if !IsValidBucketName(bucket) { | 
					
						
							|  |  |  | 		return BucketNameInvalid{Bucket: bucket} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	ncPath := path.Join(bucketConfigPrefix, bucket, bucketNotificationConfig) | 
					
						
							| 
									
										
										
										
											2018-04-06 06:04:40 +08:00
										 |  |  | 	return objAPI.DeleteObject(ctx, minioMetaBucket, ncPath) | 
					
						
							| 
									
										
										
										
											2018-03-16 04:03:41 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | // Remove listener configuration from storage layer. Used when a bucket is deleted.
 | 
					
						
							| 
									
										
										
										
											2018-04-06 06:04:40 +08:00
										 |  |  | func removeListenerConfig(ctx context.Context, objAPI ObjectLayer, bucket string) error { | 
					
						
							| 
									
										
										
										
											2018-03-16 04:03:41 +08:00
										 |  |  | 	// make the path
 | 
					
						
							|  |  |  | 	lcPath := path.Join(bucketConfigPrefix, bucket, bucketListenerConfig) | 
					
						
							| 
									
										
										
										
											2018-04-06 06:04:40 +08:00
										 |  |  | 	return objAPI.DeleteObject(ctx, minioMetaBucket, lcPath) | 
					
						
							| 
									
										
										
										
											2018-03-16 04:03:41 +08:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2019-04-18 00:52:08 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-05-02 13:06:57 +08:00
										 |  |  | func listObjects(ctx context.Context, obj ObjectLayer, bucket, prefix, marker, delimiter string, maxKeys int, tpool *TreeWalkPool, listDir ListDirFunc, getObjInfo func(context.Context, string, string) (ObjectInfo, error), getObjectInfoDirs ...func(context.Context, string, string) (ObjectInfo, error)) (loi ListObjectsInfo, err error) { | 
					
						
							| 
									
										
										
										
											2019-04-18 00:52:08 +08:00
										 |  |  | 	if err := checkListObjsArgs(ctx, bucket, prefix, marker, delimiter, obj); err != nil { | 
					
						
							|  |  |  | 		return loi, err | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// Marker is set validate pre-condition.
 | 
					
						
							|  |  |  | 	if marker != "" { | 
					
						
							|  |  |  | 		// Marker not common with prefix is not implemented. Send an empty response
 | 
					
						
							|  |  |  | 		if !hasPrefix(marker, prefix) { | 
					
						
							|  |  |  | 			return loi, nil | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// With max keys of zero we have reached eof, return right here.
 | 
					
						
							|  |  |  | 	if maxKeys == 0 { | 
					
						
							|  |  |  | 		return loi, nil | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// For delimiter and prefix as '/' we do not list anything at all
 | 
					
						
							|  |  |  | 	// since according to s3 spec we stop at the 'delimiter'
 | 
					
						
							|  |  |  | 	// along // with the prefix. On a flat namespace with 'prefix'
 | 
					
						
							|  |  |  | 	// as '/' we don't have any entries, since all the keys are
 | 
					
						
							|  |  |  | 	// of form 'keyName/...'
 | 
					
						
							|  |  |  | 	if delimiter == slashSeparator && prefix == slashSeparator { | 
					
						
							|  |  |  | 		return loi, nil | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// Over flowing count - reset to maxObjectList.
 | 
					
						
							|  |  |  | 	if maxKeys < 0 || maxKeys > maxObjectList { | 
					
						
							|  |  |  | 		maxKeys = maxObjectList | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// Default is recursive, if delimiter is set then list non recursive.
 | 
					
						
							|  |  |  | 	recursive := true | 
					
						
							|  |  |  | 	if delimiter == slashSeparator { | 
					
						
							|  |  |  | 		recursive = false | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-06-09 13:14:07 +08:00
										 |  |  | 	walkResultCh, endWalkCh := tpool.Release(listParams{bucket, recursive, marker, prefix, false}) | 
					
						
							| 
									
										
										
										
											2019-04-18 00:52:08 +08:00
										 |  |  | 	if walkResultCh == nil { | 
					
						
							|  |  |  | 		endWalkCh = make(chan struct{}) | 
					
						
							| 
									
										
										
										
											2019-05-02 13:06:57 +08:00
										 |  |  | 		walkResultCh = startTreeWalk(ctx, bucket, prefix, marker, recursive, listDir, endWalkCh) | 
					
						
							| 
									
										
										
										
											2019-04-18 00:52:08 +08:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	var objInfos []ObjectInfo | 
					
						
							|  |  |  | 	var eof bool | 
					
						
							|  |  |  | 	var nextMarker string | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// List until maxKeys requested.
 | 
					
						
							|  |  |  | 	for i := 0; i < maxKeys; { | 
					
						
							|  |  |  | 		walkResult, ok := <-walkResultCh | 
					
						
							|  |  |  | 		if !ok { | 
					
						
							|  |  |  | 			// Closed channel.
 | 
					
						
							|  |  |  | 			eof = true | 
					
						
							|  |  |  | 			break | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		var objInfo ObjectInfo | 
					
						
							|  |  |  | 		var err error | 
					
						
							|  |  |  | 		if hasSuffix(walkResult.entry, slashSeparator) { | 
					
						
							|  |  |  | 			for _, getObjectInfoDir := range getObjectInfoDirs { | 
					
						
							|  |  |  | 				objInfo, err = getObjectInfoDir(ctx, bucket, walkResult.entry) | 
					
						
							|  |  |  | 				if err == nil { | 
					
						
							|  |  |  | 					break | 
					
						
							|  |  |  | 				} | 
					
						
							| 
									
										
										
										
											2019-04-24 05:54:28 +08:00
										 |  |  | 				if err == errFileNotFound { | 
					
						
							|  |  |  | 					err = nil | 
					
						
							|  |  |  | 					objInfo = ObjectInfo{ | 
					
						
							|  |  |  | 						Bucket: bucket, | 
					
						
							|  |  |  | 						Name:   walkResult.entry, | 
					
						
							|  |  |  | 						IsDir:  true, | 
					
						
							|  |  |  | 					} | 
					
						
							|  |  |  | 				} | 
					
						
							| 
									
										
										
										
											2019-04-18 00:52:08 +08:00
										 |  |  | 			} | 
					
						
							|  |  |  | 		} else { | 
					
						
							|  |  |  | 			objInfo, err = getObjInfo(ctx, bucket, walkResult.entry) | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		if err != nil { | 
					
						
							|  |  |  | 			// Ignore errFileNotFound as the object might have got
 | 
					
						
							|  |  |  | 			// deleted in the interim period of listing and getObjectInfo(),
 | 
					
						
							|  |  |  | 			// ignore quorum error as it might be an entry from an outdated disk.
 | 
					
						
							|  |  |  | 			if IsErrIgnored(err, []error{ | 
					
						
							|  |  |  | 				errFileNotFound, | 
					
						
							|  |  |  | 				errXLReadQuorum, | 
					
						
							|  |  |  | 			}...) { | 
					
						
							|  |  |  | 				continue | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 			return loi, toObjectErr(err, bucket, prefix) | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		nextMarker = objInfo.Name | 
					
						
							|  |  |  | 		objInfos = append(objInfos, objInfo) | 
					
						
							|  |  |  | 		if walkResult.end { | 
					
						
							|  |  |  | 			eof = true | 
					
						
							|  |  |  | 			break | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		i++ | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// Save list routine for the next marker if we haven't reached EOF.
 | 
					
						
							| 
									
										
										
										
											2019-06-09 13:14:07 +08:00
										 |  |  | 	params := listParams{bucket, recursive, nextMarker, prefix, false} | 
					
						
							| 
									
										
										
										
											2019-04-18 00:52:08 +08:00
										 |  |  | 	if !eof { | 
					
						
							|  |  |  | 		tpool.Set(params, walkResultCh, endWalkCh) | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	result := ListObjectsInfo{} | 
					
						
							|  |  |  | 	for _, objInfo := range objInfos { | 
					
						
							|  |  |  | 		if objInfo.IsDir && delimiter == slashSeparator { | 
					
						
							|  |  |  | 			result.Prefixes = append(result.Prefixes, objInfo.Name) | 
					
						
							|  |  |  | 			continue | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		result.Objects = append(result.Objects, objInfo) | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if !eof { | 
					
						
							|  |  |  | 		result.IsTruncated = true | 
					
						
							|  |  |  | 		if len(objInfos) > 0 { | 
					
						
							|  |  |  | 			result.NextMarker = objInfos[len(objInfos)-1].Name | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// Success.
 | 
					
						
							|  |  |  | 	return result, nil | 
					
						
							|  |  |  | } |