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

Fixed case-insensitive name check in checkSketchFile #11554

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
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
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;
}
}

}