Skip to content

Commit 7f3f4db

Browse files
committed
Fixed case-insensitive name check in checkSketchFile
1 parent c4109e7 commit 7f3f4db

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

arduino-core/src/processing/app/Sketch.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,10 +68,10 @@ static public File checkSketchFile(File file) {
6868
if (pdeName.equals(fileName) || inoName.equals(fileName))
6969
return file;
7070

71-
if (altPdeFile.exists())
71+
if (FileUtils.fileExistsCaseSensitive(altPdeFile, pdeName))
7272
return altPdeFile;
7373

74-
if (altInoFile.exists())
74+
if (FileUtils.fileExistsCaseSensitive(altInoFile, inoName))
7575
return altInoFile;
7676

7777
return null;

arduino-core/src/processing/app/helpers/FileUtils.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -309,4 +309,20 @@ public static List<File> listFiles(File folder, boolean recursive,
309309
return result;
310310
}
311311

312+
/**
313+
* Checks for the existence of a file with the given name but accounts
314+
* for case-sensitivity on case-insensitive file systems.
315+
* https://stackoverflow.com/a/34730781
316+
*
317+
* @param file The file being checked
318+
* @param name The actual name the file is expected to have
319+
*/
320+
public static boolean fileExistsCaseSensitive(File file, String name) {
321+
try {
322+
return file.exists() && file.getCanonicalFile().getName().equals(name);
323+
} catch (IOException e) {
324+
return false;
325+
}
326+
}
327+
312328
}

0 commit comments

Comments
 (0)