mirror of
https://github.com/minio/minio.git
synced 2024-12-26 07:05:55 -05:00
ListMultipart fixes (#1392)
* ListMultipart: listLeafEntries() - return earlier if a directory is found. * ListMultipart: do listLeafEntries() only for directories.
This commit is contained in:
parent
90987df9b4
commit
d0e5470050
@ -52,7 +52,6 @@ func (o objectAPI) isBucketExist(bucketName string) (bool, error) {
|
|||||||
// directory, returns error if any - returns empty list if prefixPath
|
// directory, returns error if any - returns empty list if prefixPath
|
||||||
// is not a leaf directory.
|
// is not a leaf directory.
|
||||||
func (o objectAPI) listLeafEntries(prefixPath string) (entries []FileInfo, e error) {
|
func (o objectAPI) listLeafEntries(prefixPath string) (entries []FileInfo, e error) {
|
||||||
var allFileInfos []FileInfo
|
|
||||||
var markerPath string
|
var markerPath string
|
||||||
for {
|
for {
|
||||||
fileInfos, eof, e := o.storage.ListFiles(minioMetaVolume, prefixPath, markerPath, false, 1000)
|
fileInfos, eof, e := o.storage.ListFiles(minioMetaVolume, prefixPath, markerPath, false, 1000)
|
||||||
@ -63,22 +62,24 @@ func (o objectAPI) listLeafEntries(prefixPath string) (entries []FileInfo, e err
|
|||||||
}).Errorf("%s", e)
|
}).Errorf("%s", e)
|
||||||
return nil, e
|
return nil, e
|
||||||
}
|
}
|
||||||
allFileInfos = append(allFileInfos, fileInfos...)
|
for _, fileInfo := range fileInfos {
|
||||||
if eof {
|
// Set marker for next batch of ListFiles.
|
||||||
break
|
markerPath = fileInfo.Name
|
||||||
}
|
|
||||||
markerPath = allFileInfos[len(allFileInfos)-1].Name
|
|
||||||
}
|
|
||||||
for _, fileInfo := range allFileInfos {
|
|
||||||
if fileInfo.Mode.IsDir() {
|
if fileInfo.Mode.IsDir() {
|
||||||
// If a directory is found, doesn't return anything.
|
// If a directory is found, doesn't return anything.
|
||||||
return nil, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
fileName := path.Base(fileInfo.Name)
|
fileName := path.Base(fileInfo.Name)
|
||||||
if !strings.Contains(fileName, ".") {
|
if !strings.Contains(fileName, ".") {
|
||||||
|
// Skip the entry if it is of the pattern bucket/object/uploadID.partNum.md5sum
|
||||||
|
// and retain entries of the pattern bucket/object/uploadID
|
||||||
entries = append(entries, fileInfo)
|
entries = append(entries, fileInfo)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if eof {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
return entries, nil
|
return entries, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -106,8 +107,9 @@ func (o objectAPI) listMetaVolumeFiles(prefixPath string, markerPath string, rec
|
|||||||
// Loop through and validate individual file.
|
// Loop through and validate individual file.
|
||||||
for _, fi := range fileInfos {
|
for _, fi := range fileInfos {
|
||||||
var entries []FileInfo
|
var entries []FileInfo
|
||||||
|
if fi.Mode.IsDir() {
|
||||||
// List all the entries if fi.Name is a leaf directory, if
|
// List all the entries if fi.Name is a leaf directory, if
|
||||||
// fi.Name is not a leaf directory them the resulting
|
// fi.Name is not a leaf directory then the resulting
|
||||||
// entries are empty.
|
// entries are empty.
|
||||||
entries, e = o.listLeafEntries(fi.Name)
|
entries, e = o.listLeafEntries(fi.Name)
|
||||||
if e != nil {
|
if e != nil {
|
||||||
@ -116,41 +118,51 @@ func (o objectAPI) listMetaVolumeFiles(prefixPath string, markerPath string, rec
|
|||||||
}).Errorf("%s", e)
|
}).Errorf("%s", e)
|
||||||
return nil, false, e
|
return nil, false, e
|
||||||
}
|
}
|
||||||
|
}
|
||||||
// Set markerPath for next batch of listing.
|
// Set markerPath for next batch of listing.
|
||||||
markerPath = fi.Name
|
markerPath = fi.Name
|
||||||
if len(entries) > 0 {
|
if len(entries) > 0 {
|
||||||
|
|
||||||
|
// We reach here for non-recursive case and a leaf entry.
|
||||||
|
|
||||||
for _, entry := range entries {
|
for _, entry := range entries {
|
||||||
// Skip the entries for erasure parts if any.
|
allFileInfos = append(allFileInfos, entry)
|
||||||
if strings.Contains(path.Base(entry.Name), ".") {
|
newMaxKeys++
|
||||||
|
// If we have reached the maxKeys, it means we have listed
|
||||||
|
// everything that was requested. Return right here.
|
||||||
|
if newMaxKeys == maxKeys {
|
||||||
|
// Return values:
|
||||||
|
// allFileInfos : "maxKeys" number of entries.
|
||||||
|
// eof : eof returned by o.storage.ListFiles()
|
||||||
|
// error : nil
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
allFileInfos = append(allFileInfos, entry)
|
|
||||||
}
|
// We reach here for a non-recursive case non-leaf entry
|
||||||
} else {
|
// OR recursive case with fi.Name matching pattern bucket/object/uploadID[.partNum.md5sum]
|
||||||
// Skip special files.
|
|
||||||
|
if !fi.Mode.IsDir() { // Do not skip non-recursive case directory entries.
|
||||||
|
// Skip files matching pattern bucket/object/uploadID.partNum.md5sum
|
||||||
|
// and retain files matching pattern bucket/object/uploadID
|
||||||
specialFile := path.Base(fi.Name)
|
specialFile := path.Base(fi.Name)
|
||||||
if strings.Contains(specialFile, ".") {
|
if strings.Contains(specialFile, ".") {
|
||||||
// Contains partnumber and md5sum info, skip this.
|
// Contains partnumber and md5sum info, skip this.
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
allFileInfos = append(allFileInfos, fi)
|
|
||||||
}
|
}
|
||||||
|
allFileInfos = append(allFileInfos, fi)
|
||||||
newMaxKeys++
|
newMaxKeys++
|
||||||
// If we have reached the maxKeys, it means we have listed
|
// If we have reached the maxKeys, it means we have listed
|
||||||
// everything that was requested. Return right here.
|
// everything that was requested. Return right here.
|
||||||
if newMaxKeys == maxKeys {
|
if newMaxKeys == maxKeys {
|
||||||
// Returns all the entries until maxKeys entries.
|
// Return values:
|
||||||
//
|
// allFileInfos : "maxKeys" number of entries.
|
||||||
// eof is deliberately set as false since most of the
|
// eof : eof returned by o.storage.ListFiles()
|
||||||
// time if newMaxKeys == maxKeys, there are most
|
// error : nil
|
||||||
// probably more than 1000 multipart sessions in
|
return
|
||||||
// progress.
|
|
||||||
//
|
|
||||||
// Setting this here allows us to set proper Markers
|
|
||||||
// so that the subsequent call returns the next set of
|
|
||||||
// entries.
|
|
||||||
eof = false
|
|
||||||
return allFileInfos, eof, nil
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// If we have reached eof then we break out.
|
// If we have reached eof then we break out.
|
||||||
|
Loading…
Reference in New Issue
Block a user