Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Open
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
Fixed case-insensitive name check in checkSketchFile
  • Loading branch information
magedrifaat committed May 22, 2021
commit 7f3f4db131008dce919ec399d989b867c46a5a86
4 changes: 2 additions & 2 deletions arduino-core/src/processing/app/Sketch.java
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,10 @@ static public File checkSketchFile(File file) {
if (pdeName.equals(fileName) || inoName.equals(fileName))
return file;

if (altPdeFile.exists())
if (FileUtils.fileExistsCaseSensitive(altPdeFile, pdeName))
return altPdeFile;

if (altInoFile.exists())
if (FileUtils.fileExistsCaseSensitive(altInoFile, inoName))
return altInoFile;

return null;
Expand Down
16 changes: 16 additions & 0 deletions arduino-core/src/processing/app/helpers/FileUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -309,4 +309,20 @@ public static List<File> listFiles(File folder, boolean recursive,
return result;
}

/**
* Checks for the existence of a file with the given name but accounts
* for case-sensitivity on case-insensitive file systems.
* https://stackoverflow.com/a/34730781
*
* @param file The file being checked
* @param name The actual name the file is expected to have
*/
public static boolean fileExistsCaseSensitive(File file, String name) {
try {
return file.exists() && file.getCanonicalFile().getName().equals(name);
} catch (IOException e) {
return false;
}
}

}