8326897: (fs) The utility TestUtil.supportsLinks is wrongly used to check for hard link support

Reviewed-by: gli, alanb
This commit is contained in:
Brian Burkhalter 2024-02-29 16:47:14 +00:00
parent db0e2b8faf
commit bbfda6599a
18 changed files with 112 additions and 91 deletions

@ -1,5 +1,5 @@
/*
* Copyright (c) 2008, 2011, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2008, 2024, 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
@ -37,7 +37,7 @@ import java.io.IOException;
import java.util.*;
public class SecureDS {
static boolean supportsLinks;
static boolean supportsSymbolicLinks;
public static void main(String[] args) throws IOException {
Path dir = TestUtil.createTemporaryDirectory();
@ -52,7 +52,7 @@ public class SecureDS {
return;
}
supportsLinks = TestUtil.supportsLinks(dir);
supportsSymbolicLinks = TestUtil.supportsSymbolicLinks(dir);
// run tests
doBasicTests(dir);
@ -76,11 +76,11 @@ public class SecureDS {
createDirectory(dir1.resolve(dirEntry));
// myfilelink -> myfile
Path link1Entry = Paths.get("myfilelink");
if (supportsLinks)
if (supportsSymbolicLinks)
createSymbolicLink(dir1.resolve(link1Entry), fileEntry);
// mydirlink -> mydir
Path link2Entry = Paths.get("mydirlink");
if (supportsLinks)
if (supportsSymbolicLinks)
createSymbolicLink(dir1.resolve(link2Entry), dirEntry);
// open directory and then move it so that it is no longer accessible
@ -92,7 +92,7 @@ public class SecureDS {
// Test: iterate over all entries
int count = 0;
for (Path entry: stream) { count++; }
assertTrue(count == (supportsLinks ? 4 : 2));
assertTrue(count == (supportsSymbolicLinks ? 4 : 2));
// Test: getFileAttributeView to access directory's attributes
assertTrue(stream
@ -117,7 +117,7 @@ public class SecureDS {
.getFileAttributeView(dirEntry, BasicFileAttributeView.class, NOFOLLOW_LINKS)
.readAttributes()
.isDirectory());
if (supportsLinks) {
if (supportsSymbolicLinks) {
assertTrue(stream
.getFileAttributeView(link1Entry, BasicFileAttributeView.class)
.readAttributes()
@ -139,7 +139,7 @@ public class SecureDS {
// Test: newByteChannel
Set<StandardOpenOption> opts = Collections.emptySet();
stream.newByteChannel(fileEntry, opts).close();
if (supportsLinks) {
if (supportsSymbolicLinks) {
stream.newByteChannel(link1Entry, opts).close();
try {
Set<OpenOption> mixed = new HashSet<>();
@ -153,7 +153,7 @@ public class SecureDS {
// Test: newDirectoryStream
stream.newDirectoryStream(dirEntry).close();
stream.newDirectoryStream(dirEntry, LinkOption.NOFOLLOW_LINKS).close();
if (supportsLinks) {
if (supportsSymbolicLinks) {
stream.newDirectoryStream(link2Entry).close();
try {
stream.newDirectoryStream(link2Entry, LinkOption.NOFOLLOW_LINKS)
@ -163,7 +163,7 @@ public class SecureDS {
}
// Test: delete
if (supportsLinks) {
if (supportsSymbolicLinks) {
stream.deleteFile(link1Entry);
stream.deleteFile(link2Entry);
}
@ -186,7 +186,7 @@ public class SecureDS {
Path dirEntry = Paths.get("mydir");
createDirectory(dir1.resolve(dirEntry));
Path linkEntry = Paths.get("mylink");
if (supportsLinks)
if (supportsSymbolicLinks)
createSymbolicLink(dir1.resolve(linkEntry), Paths.get("missing"));
// target name
@ -211,7 +211,7 @@ public class SecureDS {
stream2.deleteDirectory(target);
// Test: move dir1/mylink -> dir2/newfile
if (supportsLinks) {
if (supportsSymbolicLinks) {
stream1.move(linkEntry, stream2, target);
assertTrue(isSymbolicLink(dir2.resolve(target)));
stream2.deleteFile(target);

@ -1,5 +1,5 @@
/*
* Copyright (c) 2009, 2022, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2009, 2024, 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
@ -251,7 +251,7 @@ public class CheckPermissions {
delete(target);
}
if (TestUtil.supportsLinks(testdir)) {
if (TestUtil.supportsSymbolicLinks(testdir)) {
Path link = testdir.resolve("link1234");
createSymbolicLink(link, file);
try {
@ -297,7 +297,7 @@ public class CheckPermissions {
// -- createSymbolicLink --
if (TestUtil.supportsLinks(testdir)) {
if (TestUtil.supportsSymbolicLinks(testdir)) {
prepare();
Path link = testdir.resolve("link1234");
createSymbolicLink(link, file);
@ -311,7 +311,7 @@ public class CheckPermissions {
// -- createLink --
if (TestUtil.supportsLinks(testdir)) {
if (TestUtil.supportsHardLinks(testdir)) {
prepare();
Path link = testdir.resolve("entry234");
createLink(link, file);

@ -1,5 +1,5 @@
/*
* Copyright (c) 2008, 2023, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2008, 2024, 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
@ -70,8 +70,8 @@ public class CopyAndMove {
FileStore fileStore1 = getFileStore(dir1);
printDirInfo("dir1", dir1, fileStore1);
testPosixAttributes = fileStore1.supportsFileAttributeView("posix");
testCopyFileToFile(dir1, dir1, TestUtil.supportsLinks(dir1));
testMove(dir1, dir1, TestUtil.supportsLinks(dir1));
testCopyFileToFile(dir1, dir1, TestUtil.supportsSymbolicLinks(dir1));
testMove(dir1, dir1, TestUtil.supportsSymbolicLinks(dir1));
// Use test.dir to define second directory if possible as it might
// be a different volume/file system and so improve test coverage.
@ -87,8 +87,8 @@ public class CopyAndMove {
try {
testPosixAttributes =
fileStore2.supportsFileAttributeView("posix");
testCopyFileToFile(dir2, dir2, TestUtil.supportsLinks(dir2));
testMove(dir2, dir2, TestUtil.supportsLinks(dir2));
testCopyFileToFile(dir2, dir2, TestUtil.supportsSymbolicLinks(dir2));
testMove(dir2, dir2, TestUtil.supportsSymbolicLinks(dir2));
} finally {
TestUtil.removeAll(dir2);
}
@ -101,7 +101,7 @@ public class CopyAndMove {
dir2 = TestUtil.createTemporaryDirectory(testDir);
}
boolean testSymbolicLinks =
TestUtil.supportsLinks(dir1) && TestUtil.supportsLinks(dir2);
TestUtil.supportsSymbolicLinks(dir1) && TestUtil.supportsSymbolicLinks(dir2);
testPosixAttributes = fileStore1.supportsFileAttributeView("posix") &&
fileStore2.supportsFileAttributeView("posix");
testCopyFileToFile(dir1, dir2, testSymbolicLinks);
@ -309,7 +309,7 @@ public class CopyAndMove {
/**
* Tests all possible ways to invoke move
*/
static void testMove(Path dir1, Path dir2, boolean supportsLinks)
static void testMove(Path dir1, Path dir2, boolean supportsSymbolicLinks)
throws IOException
{
Path source, target, entry;
@ -531,7 +531,7 @@ public class CopyAndMove {
/**
* Test: Move symbolic link to file, target does not exist
*/
if (supportsLinks) {
if (supportsSymbolicLinks) {
Path tmp = createSourceFile(dir1);
source = dir1.resolve("link");
createSymbolicLink(source, tmp);
@ -544,7 +544,7 @@ public class CopyAndMove {
/**
* Test: Move symbolic link to directory, target does not exist
*/
if (supportsLinks) {
if (supportsSymbolicLinks) {
source = dir1.resolve("link");
createSymbolicLink(source, dir2);
target = getTargetFile(dir2);
@ -555,7 +555,7 @@ public class CopyAndMove {
/**
* Test: Move broken symbolic link, target does not exists
*/
if (supportsLinks) {
if (supportsSymbolicLinks) {
Path tmp = Paths.get("doesnotexist");
source = dir1.resolve("link");
createSymbolicLink(source, tmp);
@ -567,7 +567,7 @@ public class CopyAndMove {
/**
* Test: Move symbolic link, target exists
*/
if (supportsLinks) {
if (supportsSymbolicLinks) {
source = dir1.resolve("link");
createSymbolicLink(source, dir2);
target = getTargetFile(dir2);
@ -584,7 +584,7 @@ public class CopyAndMove {
/**
* Test: Move regular file, target exists
*/
if (supportsLinks) {
if (supportsSymbolicLinks) {
source = dir1.resolve("link");
createSymbolicLink(source, dir2);
target = getTargetFile(dir2);
@ -596,7 +596,7 @@ public class CopyAndMove {
/**
* Test: move symbolic link, target exists and is empty directory
*/
if (supportsLinks) {
if (supportsSymbolicLinks) {
source = dir1.resolve("link");
createSymbolicLink(source, dir2);
target = getTargetFile(dir2);
@ -608,7 +608,7 @@ public class CopyAndMove {
/**
* Test: symbolic link, target exists and is non-empty directory
*/
if (supportsLinks) {
if (supportsSymbolicLinks) {
source = dir1.resolve("link");
createSymbolicLink(source, dir2);
target = getTargetFile(dir2);
@ -628,7 +628,7 @@ public class CopyAndMove {
/**
* Test atomic move of symbolic link (same file store)
*/
if (supportsLinks) {
if (supportsSymbolicLinks) {
source = dir1.resolve("link");
createSymbolicLink(source, dir1);
target = getTargetFile(dir2);
@ -743,7 +743,7 @@ public class CopyAndMove {
/**
* Tests all possible ways to invoke copy to copy a file to a file
*/
static void testCopyFileToFile(Path dir1, Path dir2, boolean supportsLinks)
static void testCopyFileToFile(Path dir1, Path dir2, boolean supportsSymbolicLinks)
throws IOException
{
Path source, target, link, entry;
@ -947,7 +947,7 @@ public class CopyAndMove {
/**
* Test: Follow link
*/
if (supportsLinks) {
if (supportsSymbolicLinks) {
source = createSourceFile(dir1);
link = dir1.resolve("link");
createSymbolicLink(link, source.getFileName());
@ -960,7 +960,7 @@ public class CopyAndMove {
/**
* Test: Copy link (to file)
*/
if (supportsLinks) {
if (supportsSymbolicLinks) {
source = createSourceFile(dir1);
link = dir1.resolve("link");
createSymbolicLink(link, source);
@ -973,7 +973,7 @@ public class CopyAndMove {
/**
* Test: Copy link (to directory)
*/
if (supportsLinks) {
if (supportsSymbolicLinks) {
source = dir1.resolve("mydir");
createDirectory(source);
link = dir1.resolve("link");
@ -987,7 +987,7 @@ public class CopyAndMove {
/**
* Test: Copy broken link
*/
if (supportsLinks) {
if (supportsSymbolicLinks) {
assertTrue(notExists(source));
link = dir1.resolve("link");
createSymbolicLink(link, source);
@ -999,7 +999,7 @@ public class CopyAndMove {
/**
* Test: Copy link to UNC (Windows only)
*/
if (supportsLinks && Platform.isWindows()) {
if (supportsSymbolicLinks && Platform.isWindows()) {
Path unc = Paths.get("\\\\rialto\\share\\file");
link = dir1.resolve("link");
createSymbolicLink(link, unc);
@ -1066,7 +1066,7 @@ public class CopyAndMove {
}
Path tmpdir = createTempDirectory("blah");
try {
if (TestUtil.supportsLinks(tmpdir)) {
if (TestUtil.supportsSymbolicLinks(tmpdir)) {
Path link = createSymbolicLink(tmpdir.resolve("link"),
tmpdir.resolve("target"));
try {

@ -1,5 +1,5 @@
/*
* Copyright (c) 2023, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2023, 2024, 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
@ -114,7 +114,7 @@ public class CopyInterference {
new CopyOption[] {REPLACE_EXISTING});
list.add(args);
if (TestUtil.supportsLinks(dir)) {
if (TestUtil.supportsSymbolicLinks(dir)) {
// symbolic link, followed
Path link = dir.resolve("link");
Files.createSymbolicLink(link, sourceFile);

@ -1,5 +1,5 @@
/*
* Copyright (c) 2022, 2023, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2022, 2024, 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
@ -46,7 +46,7 @@ public class CreateDirectories {
public void testSymlinkDir() throws Exception {
// create a temp dir as the "root" in which we will run our tests.
final Path top = TestUtil.createTemporaryDirectory();
if (!TestUtil.supportsLinks(top)) {
if (!TestUtil.supportsSymbolicLinks(top)) {
System.out.println("Skipping tests since symbolic links isn't " +
"supported under directory "+ top);
throw new SkipException("Symbolic links not supported");

@ -1,5 +1,5 @@
/*
* Copyright (c) 2008, 2017, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2008, 2024, 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
@ -82,7 +82,7 @@ public class DeleteOnClose {
Path dir = Files.createTempDirectory("blah");
try {
// check that DELETE_ON_CLOSE fails when file is a sym link
if (TestUtil.supportsLinks(dir)) {
if (TestUtil.supportsSymbolicLinks(dir)) {
file = dir.resolve("foo");
Files.createFile(file);
Path link = dir.resolve("link");

@ -1,5 +1,5 @@
/*
* Copyright (c) 2008, 2022, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2008, 2024, 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
@ -156,7 +156,7 @@ public class Misc {
/**
* Test: Symbolic links
*/
if (TestUtil.supportsLinks(tmpdir)) {
if (TestUtil.supportsSymbolicLinks(tmpdir)) {
createSymbolicLink(thatFile, thisFile);
try {
assertTrue(isSameFile(thisFile, thatFile));
@ -198,7 +198,7 @@ public class Misc {
assertTrue(!isDirectory(file, NOFOLLOW_LINKS));
assertTrue(!isSymbolicLink(file));
if (TestUtil.supportsLinks(tmpdir)) {
if (TestUtil.supportsSymbolicLinks(tmpdir)) {
Path link = tmpdir.resolve("link");
createSymbolicLink(link, tmpdir);
@ -222,6 +222,10 @@ public class Misc {
} finally {
delete(link);
}
}
if (TestUtil.supportsHardLinks(tmpdir)) {
Path link = tmpdir.resolve("hardlink");
createLink(link, file);
try {
@ -234,7 +238,6 @@ public class Misc {
delete(link);
}
}
} finally {
delete(file);
}
@ -273,7 +276,7 @@ public class Misc {
}
// sym link exists
if (TestUtil.supportsLinks(tmpdir)) {
if (TestUtil.supportsSymbolicLinks(tmpdir)) {
Path link = tmpdir.resolve("link");
createSymbolicLink(link, file);

@ -1,5 +1,5 @@
/*
* Copyright (c) 2008, 2016, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2008, 2024, 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
@ -39,12 +39,12 @@ import java.util.*;
public class SBC {
static boolean supportsLinks;
static boolean supportsSymbolicLinks;
public static void main(String[] args) throws Exception {
Path dir = TestUtil.createTemporaryDirectory();
try {
supportsLinks = TestUtil.supportsLinks(dir);
supportsSymbolicLinks = TestUtil.supportsSymbolicLinks(dir);
// open options
createTests(dir);
@ -84,7 +84,7 @@ public class SBC {
Files.newByteChannel(file, CREATE, WRITE).close();
// create file where existing file is a sym link
if (supportsLinks) {
if (supportsSymbolicLinks) {
Path link = Files.createSymbolicLink(dir.resolve("link"), file);
try {
// file already exists
@ -121,7 +121,7 @@ public class SBC {
} catch (FileAlreadyExistsException x) { }
// create should fail
if (supportsLinks) {
if (supportsSymbolicLinks) {
Path link = dir.resolve("link");
Path target = dir.resolve("thisDoesNotExist");
Files.createSymbolicLink(link, target);
@ -224,7 +224,7 @@ public class SBC {
// test NOFOLLOW_LINKS option
static void noFollowLinksTests(Path dir) throws Exception {
if (!supportsLinks)
if (!supportsSymbolicLinks)
return;
Path file = Files.createFile(dir.resolve("foo"));
try {

@ -1,5 +1,5 @@
/*
* Copyright (c) 2014, 2017, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2014, 2024, 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
@ -87,7 +87,7 @@ public class SetLastModifiedTime {
@Test
public void testSymbolicLink() throws Exception {
if (TestUtil.supportsLinks(testDir)) {
if (TestUtil.supportsSymbolicLinks(testDir)) {
Path target = Files.createFile(testDir.resolve("target"));
Path link = testDir.resolve("link");
Files.createSymbolicLink(link, target);

@ -1,5 +1,5 @@
/*
* Copyright (c) 2013, 2015, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2013, 2024, 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
@ -72,7 +72,7 @@ public class StreamTest {
* - linkFile(./file)
*/
static Path testFolder;
static boolean supportsLinks;
static boolean supportsSymbolicLinks;
static Path[] level1;
static Path[] all;
static Path[] all_folowLinks;
@ -80,7 +80,7 @@ public class StreamTest {
@BeforeClass
void setupTestFolder() throws IOException {
testFolder = TestUtil.createTemporaryDirectory();
supportsLinks = TestUtil.supportsLinks(testFolder);
supportsSymbolicLinks = TestUtil.supportsSymbolicLinks(testFolder);
TreeSet<Path> set = new TreeSet<>();
// Level 1
@ -96,7 +96,7 @@ public class StreamTest {
set.add(file);
set.add(dir);
set.add(dir2);
if (supportsLinks) {
if (supportsSymbolicLinks) {
Path tmp = testFolder.resolve("linkDir");
Files.createSymbolicLink(tmp, dir);
set.add(tmp);
@ -113,7 +113,7 @@ public class StreamTest {
tmp = dir.resolve("f1");
Files.createFile(tmp);
set.add(tmp);
if (supportsLinks) {
if (supportsSymbolicLinks) {
tmp = dir.resolve("lnDir2");
Files.createSymbolicLink(tmp, dir2);
set.add(tmp);
@ -123,7 +123,7 @@ public class StreamTest {
all = set.toArray(new Path[0]);
// Follow links
if (supportsLinks) {
if (supportsSymbolicLinks) {
tmp = testFolder.resolve("linkDir");
set.add(tmp.resolve("d1"));
set.add(tmp.resolve("f1"));
@ -212,7 +212,7 @@ public class StreamTest {
}
public void testWalkFollowLinkLoop() {
if (!supportsLinks) {
if (!supportsSymbolicLinks) {
return;
}
@ -513,7 +513,7 @@ public class StreamTest {
Path triggerLink = null;
Path linkTriggerDir = null;
Path linkTriggerFile = null;
if (supportsLinks) {
if (supportsSymbolicLinks) {
Path dir = testFolder.resolve("dir");
triggerLink = Files.createSymbolicLink(dir.resolve("SecurityException"), empty);
linkTriggerDir = Files.createSymbolicLink(dir.resolve("lnDirSE"), triggerDir);
@ -539,7 +539,7 @@ public class StreamTest {
assertEqualsNoOrder(result, new String[] { "dir2", "SecurityException", "fileInSE", "file" });
}
if (supportsLinks) {
if (supportsSymbolicLinks) {
try (Stream<Path> s = Files.list(fakeRoot.resolve("dir"))) {
String[] result = s.map(path -> path.getFileName().toString())
.toArray(String[]::new);
@ -562,7 +562,7 @@ public class StreamTest {
assertEqualsNoOrder(result, new String[] { "dir2", "file" });
}
if (supportsLinks) {
if (supportsSymbolicLinks) {
// not following links
try (Stream<Path> s = Files.walk(fakeRoot.resolve("dir"))) {
String[] result = s.map(path -> path.getFileName().toString())
@ -639,7 +639,7 @@ public class StreamTest {
if (fs != null) {
fs.close();
}
if (supportsLinks) {
if (supportsSymbolicLinks) {
Files.delete(triggerLink);
Files.delete(linkTriggerDir);
Files.delete(linkTriggerFile);

@ -1,5 +1,6 @@
/*
* Copyright (c) 2020 Microsoft Corporation. All rights reserved.
* Copyright (c) 2024, 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
@ -276,7 +277,7 @@ public class SubstDrive {
*/
@Test
public void testGetResolvedSymlinkAttribute() throws IOException {
if (!TestUtil.supportsLinks(TEST_TEMP_DIRECTORY)) {
if (!TestUtil.supportsSymbolicLinks(TEST_TEMP_DIRECTORY)) {
return;
}
@ -308,7 +309,7 @@ public class SubstDrive {
*/
@Test
public void testSubstWithSymlinkedDirectory() throws IOException {
if (!TestUtil.supportsLinks(TEST_TEMP_DIRECTORY)) {
if (!TestUtil.supportsSymbolicLinks(TEST_TEMP_DIRECTORY)) {
return;
}
@ -350,7 +351,7 @@ public class SubstDrive {
*/
@Test
public void testMoveAndCopyFilesToSymlinkedDrive() throws IOException {
if (!TestUtil.supportsLinks(TEST_TEMP_DIRECTORY)) {
if (!TestUtil.supportsSymbolicLinks(TEST_TEMP_DIRECTORY)) {
return;
}

@ -1,5 +1,5 @@
/*
* Copyright (c) 2019, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2019, 2024, 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
@ -41,7 +41,7 @@ import java.nio.file.attribute.FileTime;
public class SymlinkTime {
public static void main(String[] args) throws IOException {
Path dir = TestUtil.createTemporaryDirectory();
if (!TestUtil.supportsLinks(dir)) {
if (!TestUtil.supportsSymbolicLinks(dir)) {
System.out.println("Links not supported: skipping test");
return;
}

@ -1,5 +1,5 @@
/*
* Copyright (c) 2008, 2013, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2008, 2024, 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
@ -34,7 +34,7 @@ public class CreateFileTree {
private static final Random rand = new Random();
private static boolean supportsLinks(Path dir) {
private static boolean supportsSymbolicLinks(Path dir) {
Path link = dir.resolve("testlink");
Path target = dir.resolve("testtarget");
try {
@ -77,7 +77,7 @@ public class CreateFileTree {
}
// create a few sym links in the file tree so as to create cycles
if (supportsLinks(top)) {
if (supportsSymbolicLinks(top)) {
int links = 1 + rand.nextInt(5);
for (int i=0; i<links; i++) {
int x = rand.nextInt(dirs.size());

@ -1,5 +1,5 @@
/*
* Copyright (c) 2023, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2023, 2024, 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
@ -58,13 +58,13 @@ public class ToRealPath {
SUBDIR = Files.createDirectory(DIR.resolve("subdir"));
FILE = Files.createFile(DIR.resolve("foo"));
LINK = DIR.resolve("link");
SUPPORTS_LINKS = TestUtil.supportsLinks(DIR);
SUPPORTS_LINKS = TestUtil.supportsSymbolicLinks(DIR);
} catch (IOException e) {
throw new UncheckedIOException(e);
}
};
public boolean supportsLinks() {
public boolean supportsSymbolicLinks() {
return SUPPORTS_LINKS;
}
@ -87,7 +87,7 @@ public class ToRealPath {
() -> doesNotExist.toRealPath(NOFOLLOW_LINKS));
}
@EnabledIf("supportsLinks")
@EnabledIf("supportsSymbolicLinks")
@Test
public void shouldResolveLinks() throws IOException {
Path resolvedFile = FILE;
@ -110,7 +110,7 @@ public class ToRealPath {
}
@Test
@EnabledIf("supportsLinks")
@EnabledIf("supportsSymbolicLinks")
public void shouldNotResolveLinks() throws IOException {
Files.createSymbolicLink(LINK, FILE.toAbsolutePath());
assertEquals(LINK.toRealPath(NOFOLLOW_LINKS).getFileName(),
@ -143,7 +143,7 @@ public class ToRealPath {
}
@Test
@EnabledIf("supportsLinks")
@EnabledIf("supportsSymbolicLinks")
public void noCollapseDots1() throws IOException {
Path subPath = DIR.resolve(Path.of("dir", "subdir"));
Path sub = Files.createDirectories(subPath);
@ -163,7 +163,7 @@ public class ToRealPath {
}
@Test
@EnabledIf("supportsLinks")
@EnabledIf("supportsSymbolicLinks")
public void noCollapseDots2() throws IOException {
Path subPath = DIR.resolve(Path.of("dir", "subdir"));
Path sub = Files.createDirectories(subPath);

@ -1,5 +1,5 @@
/*
* Copyright (c) 2008, 2011, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2008, 2024, 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
@ -102,7 +102,7 @@ public class TestUtil {
/**
* Returns true if symbolic links are supported
*/
static boolean supportsLinks(Path dir) {
static boolean supportsSymbolicLinks(Path dir) {
Path link = dir.resolve("testlink");
Path target = dir.resolve("testtarget");
try {
@ -115,4 +115,21 @@ public class TestUtil {
return false;
}
}
/**
* Returns true if hard links are supported
*/
static boolean supportsHardLinks(Path dir) {
Path link = dir.resolve("testlink");
Path target = dir.resolve("testtarget");
try {
Files.createLink(link, target);
Files.delete(link);
return true;
} catch (UnsupportedOperationException x) {
return false;
} catch (IOException x) {
return false;
}
}
}

@ -1,5 +1,5 @@
/*
* Copyright (c) 2008, 2011, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2008, 2024, 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
@ -79,7 +79,7 @@ public class Basic {
testAttributes(Files.getFileAttributeView(file, DosFileAttributeView.class));
// Following tests use a symbolic link so skip if not supported
if (!TestUtil.supportsLinks(dir))
if (!TestUtil.supportsSymbolicLinks(dir))
return;
Path link = dir.resolve("link");

@ -1,5 +1,5 @@
/*
* Copyright (c) 2008, 2023, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2008, 2024, 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
@ -167,7 +167,7 @@ public class Basic {
Files.delete(file);
}
if (TestUtil.supportsLinks(dir)) {
if (TestUtil.supportsSymbolicLinks(dir)) {
// create link (to file that doesn't exist) and test reading of
// permissions
Path link = dir.resolve("link");

@ -1,5 +1,5 @@
/*
* Copyright (c) 2008, 2021, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2008, 2024, 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
@ -299,7 +299,7 @@ public class Basic {
}
// test access to user defined attributes of sym link
if (TestUtil.supportsLinks(dir)) {
if (TestUtil.supportsSymbolicLinks(dir)) {
Path target = dir.resolve("doesnotexist");
Path link = dir.resolve("link");
Files.createSymbolicLink(link, target);