8272369: java/io/File/GetXSpace.java failed with "RuntimeException: java.nio.file.NoSuchFileException: /run/user/0"

Reviewed-by: alanb
This commit is contained in:
Brian Burkhalter 2021-08-17 17:07:03 +00:00
parent a199ebc017
commit a68b5b9c1d

@ -1,5 +1,5 @@
/*
* Copyright (c) 2005, 2020, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2005, 2021, 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
@ -27,6 +27,8 @@
* @requires (os.family == "linux" | os.family == "mac" |
* os.family == "windows")
* @summary Basic functionality of File.get-X-Space methods.
* @library .. /test/lib
* @build jdk.test.lib.Platform
* @run main/othervm -Djava.security.manager=allow GetXSpace
*/
@ -37,11 +39,14 @@ import java.io.InputStreamReader;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.FileStore;
import java.nio.file.NoSuchFileException;
import java.nio.file.Path;
import java.security.Permission;
import java.util.ArrayList;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import jdk.test.lib.Platform;
import jdk.test.lib.Platform;
import static java.lang.System.err;
import static java.lang.System.out;
@ -51,10 +56,6 @@ public class GetXSpace {
private static SecurityManager [] sma = { null, new Allow(), new DenyFSA(),
new DenyRead() };
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 DF_PATTERN = Pattern.compile("([^\\s]+)\\s+(\\d+)\\s+\\d+\\s+(\\d+)\\s+\\d+%\\s+([^\\s].*)\n");
@ -151,7 +152,7 @@ public class GetXSpace {
String name = f;
if (name == null) {
// cygwin's df lists windows path as FileSystem (1st group)
name = IS_WIN ? m.group(1) : m.group(4);
name = Platform.isWindows() ? m.group(1) : m.group(4);
}
al.add(new Space(m.group(2), m.group(3), name));;
}
@ -220,6 +221,12 @@ public class GetXSpace {
FileStore fileStore = Files.getFileStore(f.toPath());
blockSize = fileStore.getBlockSize();
numBlocks = fileStore.getTotalSpace()/blockSize;
} catch (NoSuchFileException nsfe) {
// On Linux, ignore the NSFE if the path is one of the
// /run/user/$UID mounts created by pam_systemd(8) as it
// might be deleted during the test
if (!Platform.isLinux() || s.name().indexOf("/run/user") == -1)
throw new RuntimeException(nsfe);
} catch (IOException e) {
throw new RuntimeException(e);
}
@ -229,7 +236,7 @@ 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 (!IS_MAC || blockSize != 512 || numBlocks % 2 == 0
if (!Platform.isOSX() || blockSize != 512 || numBlocks % 2 == 0
|| ts - s.total() != 512) {
fail(s.name(), s.total(), "!=", ts);
}
@ -238,7 +245,7 @@ public class GetXSpace {
}
// unix df returns statvfs.f_bavail
long tsp = (!IS_WIN ? us : fs);
long tsp = (!Platform.isWindows() ? us : fs);
if (!s.woomFree(tsp)) {
fail(s.name(), s.free(), "??", tsp);
} else {