Skip to content

Commit

Permalink
Merge pull request #249 from diskfs/fat32-case
Browse files Browse the repository at this point in the history
fix fat32 case-insensitivity when creating files, add test for it
  • Loading branch information
deitch authored Aug 27, 2024
2 parents e27b493 + 51f9efe commit ec071f7
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 1 deletion.
6 changes: 5 additions & 1 deletion filesystem/fat32/fat32.go
Original file line number Diff line number Diff line change
Expand Up @@ -830,7 +830,11 @@ func (fs *FileSystem) readDirWithMkdir(p string, doMake bool) (*Directory, []*di
// do we have an entry whose name is the same as this name?
found := false
for _, e := range entries {
if e.filenameLong != subp && e.filenameShort != subp && (!e.lowercaseShortname || (e.lowercaseShortname && !strings.EqualFold(e.filenameShort, subp))) {
// if the filename does not match, continue
// match is determined by any one of:
// - long filename == provided name
// - uppercase(short filename) == uppercase(provided name)
if e.filenameLong != subp && !strings.EqualFold(e.filenameShort, subp) {
continue
}
if !e.isSubdirectory {
Expand Down
32 changes: 32 additions & 0 deletions filesystem/fat32/fat32_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -946,3 +946,35 @@ func TestFat32Label(t *testing.T) {
}
})
}

func TestFat32MkdirCases(t *testing.T) {
f, err := tmpFat32(false, 0, 0)
if err != nil {
t.Fatal(err)
}
defer os.Remove(f.Name())
fs, err := fat32.Create(f, 1048576, 0, 512, "")
if err != nil {
t.Error(err.Error())
}
err = fs.Mkdir("/EFI/BOOT")
if err != nil {
t.Error(err.Error())
}
// Make the same folders but now lowercase ... I expect it not to create anything new,
// these folders exist but are named /EFI/BOOT
err = fs.Mkdir("/efi/boot")
if err != nil {
t.Error(err.Error())
}
files, err := fs.ReadDir("/")
if err != nil {
t.Error(err.Error())
}
if len(files) != 1 {
for _, file := range files {
fmt.Printf("file: %s\n", file.Name())
}
t.Fatalf("expected 1 file, found %d", len(files))
}
}

0 comments on commit ec071f7

Please sign in to comment.