From 052c832188f9e7b3fd726ddab00fc7fa0ec3300f Mon Sep 17 00:00:00 2001 From: Daniel Lublin Date: Sun, 21 Jul 2024 21:52:23 +0200 Subject: [PATCH] Make fat32 ReadDir not return special volume label Fixes https://github.com/diskfs/go-diskfs/issues/239 --- filesystem/fat32/fat32.go | 13 ++++++++----- filesystem/fat32/fat32_test.go | 7 +++---- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/filesystem/fat32/fat32.go b/filesystem/fat32/fat32.go index acb68ed1..ae653173 100644 --- a/filesystem/fat32/fat32.go +++ b/filesystem/fat32/fat32.go @@ -493,9 +493,12 @@ func (fs *FileSystem) ReadDir(p string) ([]os.FileInfo, error) { } // once we have made it here, looping is done. We have found the final entry // we need to return all of the file info - count := len(entries) - ret := make([]os.FileInfo, count) - for i, e := range entries { + //nolint:prealloc // because the following loop may omit some entry + var ret []os.FileInfo + for _, e := range entries { + if e.isVolumeLabel { + continue + } shortName := e.filenameShort if e.lowercaseShortname { shortName = strings.ToLower(shortName) @@ -507,13 +510,13 @@ func (fs *FileSystem) ReadDir(p string) ([]os.FileInfo, error) { if fileExtension != "" { shortName = fmt.Sprintf("%s.%s", shortName, fileExtension) } - ret[i] = FileInfo{ + ret = append(ret, FileInfo{ modTime: e.modifyTime, name: e.filenameLong, shortName: shortName, size: int64(e.fileSize), isDir: e.isSubdirectory, - } + }) } return ret, nil } diff --git a/filesystem/fat32/fat32_test.go b/filesystem/fat32/fat32_test.go index 5b1bca19..fab083ce 100644 --- a/filesystem/fat32/fat32_test.go +++ b/filesystem/fat32/fat32_test.go @@ -304,13 +304,12 @@ func TestFat32ReadDir(t *testing.T) { isDir bool err error }{ - // should have 4 entries - //