Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion core/src/main/java/io/roastedroot/zerofs/FileTree.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package io.roastedroot.zerofs;

import java.io.IOException;
import java.nio.file.FileSystemException;
import java.nio.file.LinkOption;
import java.nio.file.NoSuchFileException;
import java.util.Iterator;
Expand Down Expand Up @@ -166,7 +167,7 @@ private DirectoryEntry lookUpLast(
private DirectoryEntry followSymbolicLink(File dir, SymbolicLink link, int linkDepth)
throws IOException {
if (linkDepth >= MAX_SYMBOLIC_LINK_DEPTH) {
throw new IOException("too many levels of symbolic links");
throw new FileSystemException(null, null, "Too many levels of symbolic links");
}

return lookUp(dir, link.target(), Options.FOLLOW_LINKS, linkDepth + 1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertInstanceOf;
import static org.junit.jupiter.api.Assertions.assertNotEquals;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.Assertions.fail;

Expand Down Expand Up @@ -1270,19 +1271,16 @@ public void testSymbolicLinks_symlinkCycle() throws IOException {
Files.createSymbolicLink(path("/foo/bar"), path("baz"));
Files.createSymbolicLink(path("/foo/baz"), path("bar"));

try {
Files.createFile(path("/foo/bar/file"));
fail();
} catch (IOException expected) {
assertTrue(expected.getMessage().contains("symbolic link"));
}
FileSystemException expected =
assertThrows(
FileSystemException.class, () -> Files.createFile(path("/foo/bar/file")));
assertEquals("Too many levels of symbolic links", expected.getReason());

try {
Files.write(path("/foo/bar"), preFilledBytes(10));
fail();
} catch (IOException expected) {
assertTrue(expected.getMessage().contains("symbolic link"));
}
expected =
assertThrows(
FileSystemException.class,
() -> Files.write(path("/foo/bar"), preFilledBytes(10)));
assertEquals("Too many levels of symbolic links", expected.getReason());
}

@Test
Expand Down
Loading