mirror of
https://github.com/corda/corda.git
synced 2025-01-06 05:04:20 +00:00
strip trailing separators when normalizing java.io.File.path
This addresses the case of e.g. new File("c:/foo/").exists() returning false when the specified directory really does exist.
This commit is contained in:
parent
2642a167e2
commit
e2416ddb85
@ -72,12 +72,16 @@ public class File implements Serializable {
|
||||
}
|
||||
}
|
||||
|
||||
private static String normalize(String path) {
|
||||
if ("\\".equals(FileSeparator)) {
|
||||
return path.replace('/', '\\');
|
||||
} else {
|
||||
return path;
|
||||
private static String stripSeparators(String p) {
|
||||
while (p.endsWith(FileSeparator)) {
|
||||
p = p.substring(0, p.length() - 1);
|
||||
}
|
||||
return p;
|
||||
}
|
||||
|
||||
private static String normalize(String path) {
|
||||
return stripSeparators
|
||||
("\\".equals(FileSeparator) ? path.replace('/', '\\') : path);
|
||||
}
|
||||
|
||||
public static native boolean rename(String old, String new_);
|
||||
@ -148,13 +152,9 @@ public class File implements Serializable {
|
||||
}
|
||||
|
||||
public String getParent() {
|
||||
String p = path;
|
||||
while (p.endsWith(FileSeparator)) {
|
||||
p = p.substring(0, p.length() - 1);
|
||||
}
|
||||
int index = p.lastIndexOf(FileSeparator);
|
||||
int index = path.lastIndexOf(FileSeparator);
|
||||
if (index >= 0) {
|
||||
return p.substring(0, index);
|
||||
return normalize(path.substring(0, index));
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user