Skip to content

Commit

Permalink
Make fat32 ReadDir not return special volume label
Browse files Browse the repository at this point in the history
Fixes #239
  • Loading branch information
quite committed Jul 22, 2024
1 parent bd61c20 commit 052c832
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 9 deletions.
13 changes: 8 additions & 5 deletions filesystem/fat32/fat32.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
}
Expand Down
7 changes: 3 additions & 4 deletions filesystem/fat32/fat32_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -304,13 +304,12 @@ func TestFat32ReadDir(t *testing.T) {
isDir bool
err error
}{
// should have 4 entries
// <LABEL>
// should have 4 entries (Volume Label is not returned)
// foo
// TERCER~1
// CORTO1.TXT
// UNARCH~1.DAT
{"/", 5, "foo", true, nil},
{"/", 4, "foo", true, nil},
// should have 80 entries:
// dir0-75 = 76 entries
// dir = 1 entry
Expand Down Expand Up @@ -589,7 +588,7 @@ func TestFat32OpenFile(t *testing.T) {
if err != nil {
t.Errorf("write many: error reading /: %v", err)
}
if len(dir) != fileCount+1 {
if len(dir) != fileCount {
t.Errorf("write many: entry count mismatch on /: expected %d, got %d -- %v", fileCount, len(dir), dir)
}
}
Expand Down

0 comments on commit 052c832

Please sign in to comment.