提交 6f1e97a8 编写于 作者: A alanb

8014855: TEST_BUG: java/nio/file/Files/StreamTest.java fails when sym links not supported

Reviewed-by: alanb
Contributed-by: henry.jen@oracle.com
上级 0d2830e5
...@@ -476,15 +476,25 @@ public class StreamTest { ...@@ -476,15 +476,25 @@ public class StreamTest {
} }
public void testSecurityException() throws IOException { public void testSecurityException() throws IOException {
Path triggerFile = testFolder.resolve(Paths.get("dir", "SecurityException")); Path empty = testFolder.resolve("empty");
Files.createFile(triggerFile); Path triggerFile = Files.createFile(empty.resolve("SecurityException"));
Path sampleFile = testFolder.resolve(Paths.get("dir", "sample")); Path sampleFile = Files.createDirectories(empty.resolve("sample"));
Files.createFile(sampleFile);
Path triggerDir = testFolder.resolve(Paths.get("dir2", "SecurityException")); Path dir2 = testFolder.resolve("dir2");
Files.createDirectories(triggerDir); Path triggerDir = Files.createDirectories(dir2.resolve("SecurityException"));
Files.createFile(triggerDir.resolve("fileInSE")); Files.createFile(triggerDir.resolve("fileInSE"));
Path sample = testFolder.resolve(Paths.get("dir2", "file")); Path sample = Files.createFile(dir2.resolve("file"));
Files.createFile(sample);
Path triggerLink = null;
Path linkTriggerDir = null;
Path linkTriggerFile = null;
if (supportsLinks) {
Path dir = testFolder.resolve("dir");
triggerLink = Files.createSymbolicLink(dir.resolve("SecurityException"), empty);
linkTriggerDir = Files.createSymbolicLink(dir.resolve("lnDirSE"), triggerDir);
linkTriggerFile = Files.createSymbolicLink(dir.resolve("lnFileSE"), triggerFile);
}
FaultyFileSystem.FaultyFSProvider fsp = FaultyFileSystem.FaultyFSProvider.getInstance(); FaultyFileSystem.FaultyFSProvider fsp = FaultyFileSystem.FaultyFSProvider.getInstance();
FaultyFileSystem fs = (FaultyFileSystem) fsp.newFileSystem(testFolder, null); FaultyFileSystem fs = (FaultyFileSystem) fsp.newFileSystem(testFolder, null);
...@@ -492,10 +502,10 @@ public class StreamTest { ...@@ -492,10 +502,10 @@ public class StreamTest {
fsp.setFaultyMode(false); fsp.setFaultyMode(false);
Path fakeRoot = fs.getRoot(); Path fakeRoot = fs.getRoot();
// validate setting // validate setting
try (CloseableStream<Path> s = Files.list(fakeRoot.resolve("dir"))) { try (CloseableStream<Path> s = Files.list(fakeRoot.resolve("empty"))) {
String[] result = s.map(path -> path.getFileName().toString()) String[] result = s.map(path -> path.getFileName().toString())
.toArray(String[]::new); .toArray(String[]::new);
assertEqualsNoOrder(result, new String[] { "d1","f1", "lnDir2", "SecurityException", "sample" }); assertEqualsNoOrder(result, new String[] { "SecurityException", "sample" });
} }
try (CloseableStream<Path> s = Files.walk(fakeRoot.resolve("dir2"))) { try (CloseableStream<Path> s = Files.walk(fakeRoot.resolve("dir2"))) {
...@@ -504,13 +514,21 @@ public class StreamTest { ...@@ -504,13 +514,21 @@ public class StreamTest {
assertEqualsNoOrder(result, new String[] { "dir2", "SecurityException", "fileInSE", "file" }); assertEqualsNoOrder(result, new String[] { "dir2", "SecurityException", "fileInSE", "file" });
} }
if (supportsLinks) {
try (CloseableStream<Path> s = Files.list(fakeRoot.resolve("dir"))) {
String[] result = s.map(path -> path.getFileName().toString())
.toArray(String[]::new);
assertEqualsNoOrder(result, new String[] { "d1", "f1", "lnDir2", "SecurityException", "lnDirSE", "lnFileSE" });
}
}
// execute test // execute test
fsp.setFaultyMode(true); fsp.setFaultyMode(true);
// ignore file cause SecurityException // ignore file cause SecurityException
try (CloseableStream<Path> s = Files.walk(fakeRoot.resolve("dir"))) { try (CloseableStream<Path> s = Files.walk(fakeRoot.resolve("empty"))) {
String[] result = s.map(path -> path.getFileName().toString()) String[] result = s.map(path -> path.getFileName().toString())
.toArray(String[]::new); .toArray(String[]::new);
assertEqualsNoOrder(result, new String[] { "dir", "d1","f1", "lnDir2", "sample" }); assertEqualsNoOrder(result, new String[] { "empty", "sample" });
} }
// skip folder cause SecurityException // skip folder cause SecurityException
try (CloseableStream<Path> s = Files.walk(fakeRoot.resolve("dir2"))) { try (CloseableStream<Path> s = Files.walk(fakeRoot.resolve("dir2"))) {
...@@ -519,11 +537,29 @@ public class StreamTest { ...@@ -519,11 +537,29 @@ public class StreamTest {
assertEqualsNoOrder(result, new String[] { "dir2", "file" }); assertEqualsNoOrder(result, new String[] { "dir2", "file" });
} }
if (supportsLinks) {
// not following links
try (CloseableStream<Path> s = Files.walk(fakeRoot.resolve("dir"))) {
String[] result = s.map(path -> path.getFileName().toString())
.toArray(String[]::new);
assertEqualsNoOrder(result, new String[] { "dir", "d1", "f1", "lnDir2", "lnDirSE", "lnFileSE" });
}
// following links
try (CloseableStream<Path> s = Files.walk(fakeRoot.resolve("dir"), FileVisitOption.FOLLOW_LINKS)) {
String[] result = s.map(path -> path.getFileName().toString())
.toArray(String[]::new);
// ?? Should fileInSE show up?
// With FaultyFS, it does as no exception thrown for link to "SecurityException" with read on "lnXxxSE"
assertEqualsNoOrder(result, new String[] { "dir", "d1", "f1", "lnDir2", "file", "lnDirSE", "lnFileSE", "fileInSE" });
}
}
// list instead of walk // list instead of walk
try (CloseableStream<Path> s = Files.list(fakeRoot.resolve("dir"))) { try (CloseableStream<Path> s = Files.list(fakeRoot.resolve("empty"))) {
String[] result = s.map(path -> path.getFileName().toString()) String[] result = s.map(path -> path.getFileName().toString())
.toArray(String[]::new); .toArray(String[]::new);
assertEqualsNoOrder(result, new String[] { "d1","f1", "lnDir2", "sample" }); assertEqualsNoOrder(result, new String[] { "sample" });
} }
try (CloseableStream<Path> s = Files.list(fakeRoot.resolve("dir2"))) { try (CloseableStream<Path> s = Files.list(fakeRoot.resolve("dir2"))) {
String[] result = s.map(path -> path.getFileName().toString()) String[] result = s.map(path -> path.getFileName().toString())
...@@ -578,6 +614,11 @@ public class StreamTest { ...@@ -578,6 +614,11 @@ public class StreamTest {
if (fs != null) { if (fs != null) {
fs.close(); fs.close();
} }
if (supportsLinks) {
Files.delete(triggerLink);
Files.delete(linkTriggerDir);
Files.delete(linkTriggerFile);
}
Files.delete(triggerFile); Files.delete(triggerFile);
Files.delete(sampleFile); Files.delete(sampleFile);
Files.delete(sample); Files.delete(sample);
...@@ -589,7 +630,6 @@ public class StreamTest { ...@@ -589,7 +630,6 @@ public class StreamTest {
try (CloseableStream<String> s = Files.lines(testFolder.resolve("notExist"), Charset.forName("UTF-8"))) { try (CloseableStream<String> s = Files.lines(testFolder.resolve("notExist"), Charset.forName("UTF-8"))) {
s.forEach(l -> fail("File is not even exist!")); s.forEach(l -> fail("File is not even exist!"));
} catch (IOException ioe) { } catch (IOException ioe) {
ioe.printStackTrace(System.err);
assertTrue(ioe instanceof NoSuchFileException); assertTrue(ioe instanceof NoSuchFileException);
} }
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册