mirror of
https://github.com/minio/minio.git
synced 2025-02-27 13:29:15 -05:00
Sort directory objects correctly (#10886)
Decode dir objects when listing and sort them correctly.
This commit is contained in:
parent
07859ef48b
commit
a3017c724e
@ -539,7 +539,7 @@ func (er *erasureObjects) streamMetadataParts(ctx context.Context, o listPathOpt
|
|||||||
func (er *erasureObjects) listPath(ctx context.Context, o listPathOptions) (entries metaCacheEntriesSorted, err error) {
|
func (er *erasureObjects) listPath(ctx context.Context, o listPathOptions) (entries metaCacheEntriesSorted, err error) {
|
||||||
const debugPrint = false
|
const debugPrint = false
|
||||||
if debugPrint {
|
if debugPrint {
|
||||||
console.Printf("listPath with options: %#v", o)
|
console.Printf("listPath with options: %#v\n", o)
|
||||||
}
|
}
|
||||||
// See if we have the listing stored.
|
// See if we have the listing stored.
|
||||||
if !o.Create {
|
if !o.Create {
|
||||||
|
@ -96,9 +96,16 @@ func (s *xlStorage) WalkDir(ctx context.Context, opts WalkDirOptions, wr io.Writ
|
|||||||
// Forward some errors?
|
// Forward some errors?
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
dirObjects := make(map[string]struct{})
|
||||||
for i, entry := range entries {
|
for i, entry := range entries {
|
||||||
if strings.HasSuffix(entry, slashSeparator) {
|
if strings.HasSuffix(entry, slashSeparator) {
|
||||||
|
if strings.HasSuffix(entry, globalDirSuffixWithSlash) {
|
||||||
|
// Add without extension so it is sorted correctly.
|
||||||
|
entry = strings.TrimSuffix(entry, globalDirSuffixWithSlash) + slashSeparator
|
||||||
|
dirObjects[entry] = struct{}{}
|
||||||
|
entries[i] = entry
|
||||||
|
continue
|
||||||
|
}
|
||||||
// Trim slash, maybe compiler is clever?
|
// Trim slash, maybe compiler is clever?
|
||||||
entries[i] = entries[i][:len(entry)-1]
|
entries[i] = entries[i][:len(entry)-1]
|
||||||
continue
|
continue
|
||||||
@ -116,6 +123,7 @@ func (s *xlStorage) WalkDir(ctx context.Context, opts WalkDirOptions, wr io.Writ
|
|||||||
}
|
}
|
||||||
meta.name = strings.TrimSuffix(meta.name, xlStorageFormatFile)
|
meta.name = strings.TrimSuffix(meta.name, xlStorageFormatFile)
|
||||||
meta.name = strings.TrimSuffix(meta.name, SlashSeparator)
|
meta.name = strings.TrimSuffix(meta.name, SlashSeparator)
|
||||||
|
meta.name = decodeDirObject(meta.name)
|
||||||
out <- meta
|
out <- meta
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@ -158,10 +166,18 @@ func (s *xlStorage) WalkDir(ctx context.Context, opts WalkDirOptions, wr io.Writ
|
|||||||
|
|
||||||
// All objects will be returned as directories, there has been no object check yet.
|
// All objects will be returned as directories, there has been no object check yet.
|
||||||
// Check it by attempting to read metadata.
|
// Check it by attempting to read metadata.
|
||||||
|
_, isDirObj := dirObjects[entry]
|
||||||
|
if isDirObj {
|
||||||
|
meta.name = meta.name[:len(meta.name)-1] + globalDirSuffixWithSlash
|
||||||
|
}
|
||||||
|
|
||||||
meta.metadata, err = ioutil.ReadFile(pathJoin(volumeDir, meta.name, xlStorageFormatFile))
|
meta.metadata, err = ioutil.ReadFile(pathJoin(volumeDir, meta.name, xlStorageFormatFile))
|
||||||
switch {
|
switch {
|
||||||
case err == nil:
|
case err == nil:
|
||||||
// It was an object
|
// It was an object
|
||||||
|
if isDirObj {
|
||||||
|
meta.name = strings.TrimSuffix(meta.name, globalDirSuffixWithSlash) + slashSeparator
|
||||||
|
}
|
||||||
out <- meta
|
out <- meta
|
||||||
case os.IsNotExist(err):
|
case os.IsNotExist(err):
|
||||||
meta.metadata, err = ioutil.ReadFile(pathJoin(volumeDir, meta.name, xlStorageFormatFileV1))
|
meta.metadata, err = ioutil.ReadFile(pathJoin(volumeDir, meta.name, xlStorageFormatFileV1))
|
||||||
@ -174,7 +190,10 @@ func (s *xlStorage) WalkDir(ctx context.Context, opts WalkDirOptions, wr io.Writ
|
|||||||
}
|
}
|
||||||
|
|
||||||
// NOT an object, append to stack (with slash)
|
// NOT an object, append to stack (with slash)
|
||||||
|
// If dirObject, but no metadata (which is unexpected) we skip it.
|
||||||
|
if !isDirObj {
|
||||||
dirStack = append(dirStack, meta.name+slashSeparator)
|
dirStack = append(dirStack, meta.name+slashSeparator)
|
||||||
|
}
|
||||||
default:
|
default:
|
||||||
logger.LogIf(ctx, err)
|
logger.LogIf(ctx, err)
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user