You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
165 lines
4.9 KiB
165 lines
4.9 KiB
9 years ago
|
/*
|
||
|
* Minio Cloud Storage, (C) 2016 Minio, Inc.
|
||
|
*
|
||
|
* 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.
|
||
|
*/
|
||
|
|
||
8 years ago
|
package cmd
|
||
9 years ago
|
|
||
|
import "strings"
|
||
|
|
||
9 years ago
|
// listObjects - wrapper function implemented over file tree walk.
|
||
|
func (xl xlObjects) listObjects(bucket, prefix, marker, delimiter string, maxKeys int) (ListObjectsInfo, error) {
|
||
9 years ago
|
// Default is recursive, if delimiter is set then list non recursive.
|
||
|
recursive := true
|
||
|
if delimiter == slashSeparator {
|
||
|
recursive = false
|
||
|
}
|
||
|
|
||
8 years ago
|
heal := false // true only for xl.ListObjectsHeal
|
||
|
walkResultCh, endWalkCh := xl.listPool.Release(listParams{bucket, recursive, marker, prefix, heal})
|
||
9 years ago
|
if walkResultCh == nil {
|
||
|
endWalkCh = make(chan struct{})
|
||
9 years ago
|
isLeaf := xl.isObject
|
||
9 years ago
|
listDir := listDirFactory(isLeaf, xl.getLoadBalancedDisks()...)
|
||
9 years ago
|
walkResultCh = startTreeWalk(bucket, prefix, marker, recursive, listDir, isLeaf, endWalkCh)
|
||
9 years ago
|
}
|
||
9 years ago
|
|
||
9 years ago
|
var objInfos []ObjectInfo
|
||
|
var eof bool
|
||
|
var nextMarker string
|
||
|
for i := 0; i < maxKeys; {
|
||
9 years ago
|
walkResult, ok := <-walkResultCh
|
||
9 years ago
|
if !ok {
|
||
|
// Closed channel.
|
||
|
eof = true
|
||
|
break
|
||
|
}
|
||
|
// For any walk error return right away.
|
||
|
if walkResult.err != nil {
|
||
|
// File not found is a valid case.
|
||
|
if walkResult.err == errFileNotFound {
|
||
|
return ListObjectsInfo{}, nil
|
||
|
}
|
||
|
return ListObjectsInfo{}, toObjectErr(walkResult.err, bucket, prefix)
|
||
|
}
|
||
9 years ago
|
entry := walkResult.entry
|
||
|
var objInfo ObjectInfo
|
||
|
if strings.HasSuffix(entry, slashSeparator) {
|
||
|
// Object name needs to be full path.
|
||
|
objInfo.Bucket = bucket
|
||
|
objInfo.Name = entry
|
||
|
objInfo.IsDir = true
|
||
|
} else {
|
||
|
// Set the Mode to a "regular" file.
|
||
|
var err error
|
||
|
objInfo, err = xl.getObjectInfo(bucket, entry)
|
||
|
if err != nil {
|
||
9 years ago
|
// Ignore errFileNotFound
|
||
|
if err == errFileNotFound {
|
||
|
errorIf(err, "Unable to get object info", bucket, entry)
|
||
|
continue
|
||
|
}
|
||
9 years ago
|
return ListObjectsInfo{}, toObjectErr(err, bucket, prefix)
|
||
|
}
|
||
|
}
|
||
9 years ago
|
nextMarker = objInfo.Name
|
||
|
objInfos = append(objInfos, objInfo)
|
||
9 years ago
|
i++
|
||
|
if walkResult.end == true {
|
||
9 years ago
|
eof = true
|
||
|
break
|
||
|
}
|
||
|
}
|
||
9 years ago
|
|
||
8 years ago
|
params := listParams{bucket, recursive, nextMarker, prefix, heal}
|
||
9 years ago
|
if !eof {
|
||
9 years ago
|
xl.listPool.Set(params, walkResultCh, endWalkCh)
|
||
9 years ago
|
}
|
||
|
|
||
|
result := ListObjectsInfo{IsTruncated: !eof}
|
||
|
for _, objInfo := range objInfos {
|
||
9 years ago
|
result.NextMarker = objInfo.Name
|
||
|
if objInfo.IsDir {
|
||
|
result.Prefixes = append(result.Prefixes, objInfo.Name)
|
||
|
continue
|
||
9 years ago
|
}
|
||
|
result.Objects = append(result.Objects, ObjectInfo{
|
||
|
Name: objInfo.Name,
|
||
|
ModTime: objInfo.ModTime,
|
||
|
Size: objInfo.Size,
|
||
9 years ago
|
MD5Sum: objInfo.MD5Sum,
|
||
9 years ago
|
IsDir: false,
|
||
|
})
|
||
|
}
|
||
|
return result, nil
|
||
|
}
|
||
|
|
||
|
// ListObjects - list all objects at prefix, delimited by '/'.
|
||
|
func (xl xlObjects) ListObjects(bucket, prefix, marker, delimiter string, maxKeys int) (ListObjectsInfo, error) {
|
||
|
// Verify if bucket is valid.
|
||
|
if !IsValidBucketName(bucket) {
|
||
|
return ListObjectsInfo{}, BucketNameInvalid{Bucket: bucket}
|
||
|
}
|
||
|
// Verify if bucket exists.
|
||
|
if !xl.isBucketExist(bucket) {
|
||
|
return ListObjectsInfo{}, BucketNotFound{Bucket: bucket}
|
||
|
}
|
||
|
if !IsValidObjectPrefix(prefix) {
|
||
|
return ListObjectsInfo{}, ObjectNameInvalid{Bucket: bucket, Object: prefix}
|
||
|
}
|
||
|
// Verify if delimiter is anything other than '/', which we do not support.
|
||
|
if delimiter != "" && delimiter != slashSeparator {
|
||
|
return ListObjectsInfo{}, UnsupportedDelimiter{
|
||
|
Delimiter: delimiter,
|
||
|
}
|
||
|
}
|
||
|
// Verify if marker has prefix.
|
||
|
if marker != "" {
|
||
|
if !strings.HasPrefix(marker, prefix) {
|
||
|
return ListObjectsInfo{}, InvalidMarkerPrefixCombination{
|
||
|
Marker: marker,
|
||
|
Prefix: prefix,
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
// With max keys of zero we have reached eof, return right here.
|
||
|
if maxKeys == 0 {
|
||
|
return ListObjectsInfo{}, nil
|
||
|
}
|
||
|
|
||
9 years ago
|
// 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 ListObjectsInfo{}, nil
|
||
|
}
|
||
|
|
||
9 years ago
|
// Over flowing count - reset to maxObjectList.
|
||
|
if maxKeys < 0 || maxKeys > maxObjectList {
|
||
|
maxKeys = maxObjectList
|
||
|
}
|
||
|
|
||
|
// Initiate a list operation, if successful filter and return quickly.
|
||
9 years ago
|
listObjInfo, err := xl.listObjects(bucket, prefix, marker, delimiter, maxKeys)
|
||
9 years ago
|
if err == nil {
|
||
|
// We got the entries successfully return.
|
||
|
return listObjInfo, nil
|
||
|
}
|
||
|
|
||
|
// Return error at the end.
|
||
|
return ListObjectsInfo{}, toObjectErr(err, bucket, prefix)
|
||
|
}
|