6978511: (file) Path.toRealPath should fail if not resolving links and file does not exist
Reviewed-by: forax, chegar
This commit is contained in:
parent
b0942f5a43
commit
b7ca44871e
@ -1141,6 +1141,13 @@ class UnixPath
|
|||||||
}
|
}
|
||||||
result = result.resolve(element);
|
result = result.resolve(element);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// check file exists (without following links)
|
||||||
|
try {
|
||||||
|
UnixFileAttributes.get(result, false);
|
||||||
|
} catch (UnixException x) {
|
||||||
|
x.rethrowAsIOException(result);
|
||||||
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -260,6 +260,21 @@ public class Misc {
|
|||||||
*/
|
*/
|
||||||
assertTrue(file.toRealPath(true).isSameFile(file.toRealPath(false)));
|
assertTrue(file.toRealPath(true).isSameFile(file.toRealPath(false)));
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test: toRealPath should fail if file does not exist
|
||||||
|
*/
|
||||||
|
Path doesNotExist = dir.resolve("DoesNotExist");
|
||||||
|
try {
|
||||||
|
doesNotExist.toRealPath(true);
|
||||||
|
throw new RuntimeException("IOException expected");
|
||||||
|
} catch (IOException expected) {
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
doesNotExist.toRealPath(false);
|
||||||
|
throw new RuntimeException("IOException expected");
|
||||||
|
} catch (IOException expected) {
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test: toRealPath(true) should resolve links
|
* Test: toRealPath(true) should resolve links
|
||||||
*/
|
*/
|
||||||
|
Loading…
x
Reference in New Issue
Block a user