< prev index next >
test/jdk/java/io/File/GetXSpace.java
Print this page
@@ -33,10 +33,11 @@
import java.io.BufferedReader;
import java.io.File;
import java.io.FilePermission;
import java.io.InputStreamReader;
import java.io.IOException;
+import java.nio.file.Files;
import java.security.Permission;
import java.util.ArrayList;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
@@ -45,13 +46,16 @@
public class GetXSpace {
private static SecurityManager [] sma = { null, new Allow(), new DenyFSA(),
new DenyRead() };
- private static final String osName = System.getProperty("os.name");
+ private static final String OS_NAME = System.getProperty("os.name");
+ private static final boolean IS_MAC = OS_NAME.startsWith("Mac");
+ private static final boolean IS_WIN = OS_NAME.startsWith("Windows");
+
// FileSystem Total Used Available Use% MountedOn
- private static final Pattern dfPattern = Pattern.compile("([^\\s]+)\\s+(\\d+)\\s+\\d+\\s+(\\d+)\\s+\\d+%\\s+([^\\s].*)\n");
+ private static final Pattern DF_PATTERN = Pattern.compile("([^\\s]+)\\s+(\\d+)\\s+\\d+\\s+(\\d+)\\s+\\d+%\\s+([^\\s].*)\n");
private static int fail = 0;
private static int pass = 0;
private static Throwable first;
@@ -127,20 +131,20 @@
sb.append(s).append("\n");
}
}
out.println(sb);
- Matcher m = dfPattern.matcher(sb);
+ Matcher m = DF_PATTERN.matcher(sb);
int j = 0;
while (j < sb.length()) {
if (m.find(j)) {
// swap can change while this test is running
if (!m.group(1).equals("swap")) {
String name = f;
if (name == null) {
// cygwin's df lists windows path as FileSystem (1st group)
- name = osName.startsWith("Windows") ? m.group(1) : m.group(4);
+ name = IS_WIN ? m.group(1) : m.group(4);
}
al.add(new Space(m.group(2), m.group(3), name));;
}
j = m.end() + 1;
} else {
@@ -199,17 +203,29 @@
out.format(fmt, "df", s.total(), 0, s.free());
out.format(fmt, "getX", ts, fs, us);
// if the file system can dynamically change size, this check will fail
if (ts != s.total()) {
+ long bs = 1;
+ try {
+ bs = Files.getFileStore(f.toPath()).getBlockSize();
+ } catch (IOException e) {
+ throw new RuntimeException(e);
+ }
+ // On macOS, the number of 1024 byte blocks might be incorrectly
+ // calculated by 'df' using integer division by 2 of the number of
+ // 512 byte blocks, resulting in a size smaller than the actual
+ // value when the number of blocks is odd.
+ if (!IS_MAC || bs != 512 || ts - s.total() != 512) {
fail(s.name(), s.total(), "!=", ts);
+ }
} else {
pass();
}
// unix df returns statvfs.f_bavail
- long tsp = (!osName.startsWith("Windows") ? us : fs);
+ long tsp = (!IS_WIN ? us : fs);
if (!s.woomFree(tsp)) {
fail(s.name(), s.free(), "??", tsp);
} else {
pass();
}
< prev index next >