8349092: File.getFreeSpace violates specification if quotas are in effect (win)

Reviewed-by: naoto
This commit is contained in:
Brian Burkhalter 2025-02-06 19:11:35 +00:00
parent 0181030bdc
commit 1a74ee64eb
2 changed files with 16 additions and 3 deletions

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2001, 2024, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2001, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -584,6 +584,13 @@ final class WinNTFileSystem extends FileSystem {
@Override
public long getSpace(File f, int t) {
if (f.exists()) {
// the value for the number of bytes of free space returned by the
// native layer is not used here as it represents the number of free
// bytes not considering quotas, whereas the value returned for the
// number of usable bytes does respect quotas, and it is required
// that free space <= total space
if (t == SPACE_FREE)
t = SPACE_USABLE;
return getSpace0(f, t);
}
return 0;

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2005, 2024, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2005, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -23,7 +23,7 @@
/**
* @test
* @bug 4057701 6286712 6364377 8181919
* @bug 4057701 6286712 6364377 8181919 8349092
* @requires (os.family == "linux" | os.family == "mac" |
* os.family == "windows")
* @summary Basic functionality of File.get-X-Space methods.
@ -176,6 +176,12 @@ public class GetXSpace {
long fs = f.getFreeSpace();
long us = f.getUsableSpace();
// Verify inequalities us <= fs <= ts (JDK-8349092)
if (fs > ts)
throw new RuntimeException(f + " free space " + fs + " > total space " + ts);
if (us > fs)
throw new RuntimeException(f + " usable space " + fs + " > free space " + ts);
out.format("%s (%d):%n", s.name(), s.size());
String fmt = " %-4s total = %12d free = %12d usable = %12d%n";
String method = Platform.isWindows() & isCDDrive(s.name()) ? "getCDDriveSpace" : "getSpace0";