From 94424e14d70a1697d45f188dc4299b81d2e210ce Mon Sep 17 00:00:00 2001 From: Harshavardhana Date: Wed, 17 Jun 2020 13:58:38 -0700 Subject: [PATCH] fix: rename legacy xl.json to xl.meta properly in ListDir() (#9863) --- cmd/xl-storage.go | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/cmd/xl-storage.go b/cmd/xl-storage.go index 42fe7c9a7..86db8cf32 100644 --- a/cmd/xl-storage.go +++ b/cmd/xl-storage.go @@ -742,11 +742,11 @@ func (s *xlStorage) ListDirSplunk(volume, dirPath string, count int) (entries [] return nil, err } - dirPath = pathJoin(volumeDir, dirPath) + dirPathAbs := pathJoin(volumeDir, dirPath) if count > 0 { - entries, err = readDirN(dirPath, count) + entries, err = readDirN(dirPathAbs, count) } else { - entries, err = readDir(dirPath) + entries, err = readDir(dirPathAbs) } if err != nil { return nil, err @@ -756,13 +756,13 @@ func (s *xlStorage) ListDirSplunk(volume, dirPath string, count int) (entries [] if entry != receiptJSON { continue } - _, err = os.Stat(pathJoin(dirPath, entry, xlStorageFormatFile)) + _, err = os.Stat(pathJoin(dirPathAbs, entry, xlStorageFormatFile)) if err == nil { entries[i] = strings.TrimSuffix(entry, SlashSeparator) continue } if os.IsNotExist(err) { - if err = s.renameLegacyMetadata(volume, entry); err == nil { + if err = s.renameLegacyMetadata(volume, pathJoin(dirPath, entry)); err == nil { // Rename was successful means we found old `xl.json` entries[i] = strings.TrimSuffix(entry, SlashSeparator) } @@ -1033,27 +1033,26 @@ func (s *xlStorage) ListDir(volume, dirPath string, count int) (entries []string return nil, err } - dirPath = pathJoin(volumeDir, dirPath) + dirPathAbs := pathJoin(volumeDir, dirPath) if count > 0 { - entries, err = readDirN(dirPath, count) + entries, err = readDirN(dirPathAbs, count) } else { - entries, err = readDir(dirPath) + entries, err = readDir(dirPathAbs) } if err != nil { return nil, err } for i, entry := range entries { - _, err = os.Stat(pathJoin(dirPath, entry, xlStorageFormatFile)) + _, err = os.Stat(pathJoin(dirPathAbs, entry, xlStorageFormatFile)) if err == nil { entries[i] = strings.TrimSuffix(entry, SlashSeparator) continue } if os.IsNotExist(err) { - if err = s.renameLegacyMetadata(volume, entry); err == nil { + if err = s.renameLegacyMetadata(volume, pathJoin(dirPath, entry)); err == nil { // if rename was successful, means we did find old `xl.json` entries[i] = strings.TrimSuffix(entry, SlashSeparator) - continue } } }