Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix fat32 case-insensitivity when creating files, add test for it #249

Merged
merged 1 commit into from
Aug 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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))
}
}
Loading