8291911: java/io/File/GetXSpace.java fails with "53687091200 != 161051996160"
Reviewed-by: rriggs
This commit is contained in:
parent
95b84050fc
commit
749335d34a
test/jdk
@ -507,7 +507,6 @@ java/lang/instrument/RetransformBigClass.sh 8065756 generic-
|
||||
|
||||
java/io/pathNames/GeneralWin32.java 8180264 windows-all
|
||||
java/io/File/createTempFile/SpecialTempFile.java 8274122 windows11
|
||||
java/io/File/GetXSpace.java 8291911 windows-all
|
||||
|
||||
############################################################################
|
||||
|
||||
|
@ -57,7 +57,7 @@ public class GetXSpace {
|
||||
new DenyRead() };
|
||||
|
||||
// FileSystem Total Used Available Use% MountedOn
|
||||
private static final Pattern DF_PATTERN = 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;
|
||||
@ -103,29 +103,52 @@ public class GetXSpace {
|
||||
private static final long KSIZE = 1024;
|
||||
private final String name;
|
||||
private final long total;
|
||||
private final long free;
|
||||
private final long used;
|
||||
private final long available;
|
||||
|
||||
Space(String total, String free, String name) {
|
||||
Space(String name, String total, String used, String available) {
|
||||
this.name = name;
|
||||
try {
|
||||
this.total = Long.parseLong(total) * KSIZE;
|
||||
this.free = Long.parseLong(free) * KSIZE;
|
||||
this.used = Long.parseLong(used) * KSIZE;
|
||||
this.available = Long.parseLong(available) * KSIZE;
|
||||
} catch (NumberFormatException x) {
|
||||
throw new RuntimeException("the regex should have caught this", x);
|
||||
}
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
String name() { return name; }
|
||||
long total() { return total; }
|
||||
long free() { return free; }
|
||||
long used() { return used; }
|
||||
long available() { return available; }
|
||||
long free() { return total - used; }
|
||||
boolean woomFree(long freeSpace) {
|
||||
return ((freeSpace >= (free / 10)) && (freeSpace <= (free * 10)));
|
||||
return ((freeSpace >= (available / 10)) &&
|
||||
(freeSpace <= (available * 10)));
|
||||
}
|
||||
public String toString() {
|
||||
return String.format("%s (%d/%d)", name, free, total);
|
||||
return String.format("%s (%d/%d/%d)", name, total, used, available);
|
||||
}
|
||||
}
|
||||
|
||||
private static void diskFree() throws IOException {
|
||||
ArrayList<Space> al = new ArrayList<>();
|
||||
|
||||
String cmd = "fsutil volume diskFree C:\\";
|
||||
StringBuilder sb = new StringBuilder();
|
||||
Process p = Runtime.getRuntime().exec(cmd);
|
||||
try (BufferedReader in = p.inputReader()) {
|
||||
String s;
|
||||
int i = 0;
|
||||
while ((s = in.readLine()) != null) {
|
||||
// skip header
|
||||
if (i++ == 0) continue;
|
||||
sb.append(s).append("\n");
|
||||
}
|
||||
}
|
||||
out.println(sb);
|
||||
}
|
||||
|
||||
private static ArrayList<Space> space(String f) throws IOException {
|
||||
ArrayList<Space> al = new ArrayList<>();
|
||||
|
||||
@ -152,9 +175,9 @@ public class GetXSpace {
|
||||
String name = f;
|
||||
if (name == null) {
|
||||
// cygwin's df lists windows path as FileSystem (1st group)
|
||||
name = Platform.isWindows() ? m.group(1) : m.group(4);
|
||||
name = Platform.isWindows() ? m.group(1) : m.group(5);
|
||||
}
|
||||
al.add(new Space(m.group(2), m.group(3), name));
|
||||
al.add(new Space(name, m.group(2), m.group(3), m.group(4)));
|
||||
}
|
||||
j = m.end();
|
||||
} else {
|
||||
@ -167,7 +190,7 @@ public class GetXSpace {
|
||||
if (al.size() == 0) {
|
||||
// df did not produce output
|
||||
String name = (f == null ? "" : f);
|
||||
al.add(new Space("0", "0", name));
|
||||
al.add(new Space(name, "0", "0", "0"));
|
||||
}
|
||||
return al;
|
||||
}
|
||||
@ -209,8 +232,8 @@ public class GetXSpace {
|
||||
long us = f.getUsableSpace();
|
||||
|
||||
out.format("%s:%n", s.name());
|
||||
String fmt = " %-4s total= %12d free = %12d usable = %12d%n";
|
||||
out.format(fmt, "df", s.total(), 0, s.free());
|
||||
String fmt = " %-4s total = %12d free = %12d usable = %12d%n";
|
||||
out.format(fmt, "df", s.total(), s.free(), s.available());
|
||||
out.format(fmt, "getX", ts, fs, us);
|
||||
|
||||
// If the file system can dynamically change size, this check will fail.
|
||||
@ -236,9 +259,22 @@ public class GetXSpace {
|
||||
// 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 (!Platform.isOSX() || blockSize != 512 || numBlocks % 2 == 0
|
||||
|| ts - s.total() != 512) {
|
||||
fail(s.name(), s.total(), "!=", ts);
|
||||
if (!Platform.isOSX() || blockSize != 512 || numBlocks % 2 == 0 ||
|
||||
ts - s.total() != 512) {
|
||||
if (Platform.isWindows()) {
|
||||
//
|
||||
// In Cygwin, 'df' has been observed to account for quotas
|
||||
// when reporting the total disk size, but the total size
|
||||
// reported by GetDiskFreeSpaceExW() has been observed not
|
||||
// to account for the quota in which case the latter value
|
||||
// should be larger.
|
||||
//
|
||||
if (s.total() > ts) {
|
||||
fail(s.name() + " total space", s.total(), ">", ts);
|
||||
}
|
||||
} else {
|
||||
fail(s.name() + " total space", s.total(), "!=", ts);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
pass();
|
||||
@ -247,7 +283,7 @@ public class GetXSpace {
|
||||
// unix df returns statvfs.f_bavail
|
||||
long tsp = (!Platform.isWindows() ? us : fs);
|
||||
if (!s.woomFree(tsp)) {
|
||||
fail(s.name(), s.free(), "??", tsp);
|
||||
fail(s.name(), s.available(), "??", tsp);
|
||||
} else {
|
||||
pass();
|
||||
}
|
||||
@ -380,6 +416,9 @@ public class GetXSpace {
|
||||
ArrayList<Space> l;
|
||||
try {
|
||||
l = space(null);
|
||||
if (Platform.isWindows()) {
|
||||
diskFree();
|
||||
}
|
||||
} catch (IOException x) {
|
||||
throw new RuntimeException("can't get file system information", x);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user