Give a better exception when running from freebsd jail without enforce_statfs=1

We can't track disk usage in this situation, failing is the correct thing to do.
But we can give a FreeBSD-specific error message, so the user can set the
necessary jail parameters, versus a vague IOException.

Closes #12018
This commit is contained in:
Robert Muir 2015-10-15 09:44:53 -04:00
parent a68c163959
commit b9e99cb240
2 changed files with 13 additions and 1 deletions

View File

@ -84,7 +84,18 @@ class ESFileStore extends FileStore {
return getFileStoreWindows(path, fileStores);
}
FileStore store = Files.getFileStore(path);
final FileStore store;
try {
store = Files.getFileStore(path);
} catch (IOException unexpected) {
// give a better error message if a filestore cannot be retrieved from inside a FreeBSD jail.
if (Constants.FREE_BSD) {
throw new IOException("Unable to retrieve mount point data for " + path +
". If you are running within a jail, set enforce_statfs=1. See jail(8)", unexpected);
} else {
throw unexpected;
}
}
try {
String mount = getMountPointLinux(store);

View File

@ -304,6 +304,7 @@ public class Environment {
* no permissions to the actual mount point are required.
* <li>Exception handling has the same semantics as {@link Files#getFileStore(Path)}.
* <li>Works around https://bugs.openjdk.java.net/browse/JDK-8034057.
* <li>Gives a better exception when filestore cannot be retrieved from inside a FreeBSD jail.
* </ul>
*/
public static FileStore getFileStore(Path path) throws IOException {