Skip to content

Commit 11ccf43

Browse files
authored
Merge pull request #241 from quite/ignore-volume-label
Make fat32 ReadDir not return special volume label
2 parents bd61c20 + 052c832 commit 11ccf43

File tree

2 files changed

+11
-9
lines changed

2 files changed

+11
-9
lines changed

filesystem/fat32/fat32.go

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -493,9 +493,12 @@ func (fs *FileSystem) ReadDir(p string) ([]os.FileInfo, error) {
493493
}
494494
// once we have made it here, looping is done. We have found the final entry
495495
// we need to return all of the file info
496-
count := len(entries)
497-
ret := make([]os.FileInfo, count)
498-
for i, e := range entries {
496+
//nolint:prealloc // because the following loop may omit some entry
497+
var ret []os.FileInfo
498+
for _, e := range entries {
499+
if e.isVolumeLabel {
500+
continue
501+
}
499502
shortName := e.filenameShort
500503
if e.lowercaseShortname {
501504
shortName = strings.ToLower(shortName)
@@ -507,13 +510,13 @@ func (fs *FileSystem) ReadDir(p string) ([]os.FileInfo, error) {
507510
if fileExtension != "" {
508511
shortName = fmt.Sprintf("%s.%s", shortName, fileExtension)
509512
}
510-
ret[i] = FileInfo{
513+
ret = append(ret, FileInfo{
511514
modTime: e.modifyTime,
512515
name: e.filenameLong,
513516
shortName: shortName,
514517
size: int64(e.fileSize),
515518
isDir: e.isSubdirectory,
516-
}
519+
})
517520
}
518521
return ret, nil
519522
}

filesystem/fat32/fat32_test.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -304,13 +304,12 @@ func TestFat32ReadDir(t *testing.T) {
304304
isDir bool
305305
err error
306306
}{
307-
// should have 4 entries
308-
// <LABEL>
307+
// should have 4 entries (Volume Label is not returned)
309308
// foo
310309
// TERCER~1
311310
// CORTO1.TXT
312311
// UNARCH~1.DAT
313-
{"/", 5, "foo", true, nil},
312+
{"/", 4, "foo", true, nil},
314313
// should have 80 entries:
315314
// dir0-75 = 76 entries
316315
// dir = 1 entry
@@ -589,7 +588,7 @@ func TestFat32OpenFile(t *testing.T) {
589588
if err != nil {
590589
t.Errorf("write many: error reading /: %v", err)
591590
}
592-
if len(dir) != fileCount+1 {
591+
if len(dir) != fileCount {
593592
t.Errorf("write many: entry count mismatch on /: expected %d, got %d -- %v", fileCount, len(dir), dir)
594593
}
595594
}

0 commit comments

Comments
 (0)