From adaf04528d23af054794ac965c3f9b3fcbf57542 Mon Sep 17 00:00:00 2001 From: Michael Keller Date: Tue, 18 May 2021 01:34:42 +1200 Subject: [PATCH] Merge pull request #10739 from hexfet/sdcard_name_clash Fix name clashes in FAT filesystem --- src/main/io/asyncfatfs/asyncfatfs.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/main/io/asyncfatfs/asyncfatfs.c b/src/main/io/asyncfatfs/asyncfatfs.c index 3b4b2db9e8f..bc7bcc8f1ac 100644 --- a/src/main/io/asyncfatfs/asyncfatfs.c +++ b/src/main/io/asyncfatfs/asyncfatfs.c @@ -2615,8 +2615,18 @@ static void afatfs_createFileContinue(afatfsFile_t *file) opState->phase = AFATFS_CREATEFILE_PHASE_FAILURE; goto doMore; } + } else if (entry->attrib & FAT_FILE_ATTRIBUTE_VOLUME_ID) { + break; } else if (strncmp(entry->filename, (char*) opState->filename, FAT_FILENAME_LENGTH) == 0) { - // We found a file with this name! + // We found a file or directory with this name! + + // Do not open file as dir or dir as file + if (((entry->attrib ^ file->attrib) & FAT_FILE_ATTRIBUTE_DIRECTORY) != 0) { + afatfs_findLast(&afatfs.currentDirectory); + opState->phase = AFATFS_CREATEFILE_PHASE_FAILURE; + goto doMore; + } + afatfs_fileLoadDirectoryEntry(file, entry); afatfs_findLast(&afatfs.currentDirectory);