Make windows reserved filename detection more robust

This checks for more reserved filenames than just aux
This commit is contained in:
Ben Gruver 2013-09-14 11:35:53 -07:00
parent d868692e33
commit 6cd686fbf5

View File

@ -127,22 +127,26 @@ public class ClassFileNameHandler {
} }
private static boolean testForWindowsReservedFileNames(File path) { private static boolean testForWindowsReservedFileNames(File path) {
File f = new File(path, "aux.smali"); String[] reservedNames = new String[]{"aux", "con", "com1", "com9", "lpt1", "com9"};
if (f.exists()) {
return false;
}
try { for (String reservedName: reservedNames) {
FileWriter writer = new FileWriter(f); File f = new File(path, reservedName + ".smali");
writer.write("test"); if (f.exists()) {
writer.flush(); continue;
writer.close(); }
f.delete(); //doesn't throw IOException
return false; try {
} catch (IOException ex) { FileWriter writer = new FileWriter(f);
//if an exception occured, it's likely that we're on a windows system. writer.write("test");
return true; writer.flush();
writer.close();
f.delete(); //doesn't throw IOException
} catch (IOException ex) {
//if an exception occured, it's likely that we're on a windows system.
return true;
}
} }
return false;
} }
private static Pattern reservedFileNameRegex = Pattern.compile("^CON|PRN|AUX|NUL|COM[1-9]|LPT[1-9]$", private static Pattern reservedFileNameRegex = Pattern.compile("^CON|PRN|AUX|NUL|COM[1-9]|LPT[1-9]$",