0

I am getting "Too many levels of symbolic links" I am using Java NIO2 :- This is run on Unix. Any thoughts would be of great help. Thanks.

Deep inside the code I am calling

Path currentFolder = Paths.get(currentFolder, date);

and at some point in flow - I am trying to get the currentfolder as in the below method..

public Path getNewFolder() {
        return currentFolder.resolve("test").resolve("new");
        //where "test" and "new" contains date in between the path. example currentFolder path: "/base/test/2014106/new"
}

But I getting below exception..

java.nio.file.FileSystemException: /base/test/2014106/new: Too many levels of symbolic links
  at sun.nio.fs.UnixException.translateToIOException(UnixException.java:91)
  at sun.nio.fs.UnixException.asIOException(UnixException.java:111)
  at sun.nio.fs.UnixDirectoryStream$UnixDirectoryIterator.readNextEntry(UnixDirectoryStream.java:171)
  at sun.nio.fs.UnixDirectoryStream$UnixDirectoryIterator.hasNext(UnixDirectoryStream.java:201)
  at java.nio.file.FileTreeWalker.walk(FileTreeWalker.java:198)
  at java.nio.file.FileTreeWalker.walk(FileTreeWalker.java:69)
  at java.nio.file.Files.walkFileTree(Files.java:2591)
  at java.nio.file.Files.walkFileTree(Files.java:2624) 
Shiv Gopal
  • 539
  • 2
  • 10
  • 21

2 Answers2

1

This is the kind of thing that typically happens when you have symlink loop.

For example, if you do ln -s . here, then the directory will have a subdirectory here pointing to its parent. This means you can recursive into it forever:

$ pwd
/home/me

$ ls -ld here
lrwxrwxrwx 1 me users 1 Apr 16 16:18 here -> .

$ cd here

$ pwd
/home/me/here

$ cd here/here/here/here/here/here/here

$ pwd
/home/me/here/here/here/here/here/here/here/here

Since your stack trace is truncated, it's hard to tell exactly what you should do about it. Options include:

  • Delete a symlink in the chain so it doesn't loop
  • Detect loops while iterating
  • Stop recursing at a certain depth
that other guy
  • 116,971
  • 11
  • 170
  • 194
0

Not using full paths to sym-linked directories or files can cause this error. Instead of using relative paths,

ln -s uploads /var/www/Folder/
ln -s ./uploads /var/www/Folder/

Use full paths to files your sym-linking.

ln -s /var/www/Folder2/uploads /var/www/Folder/
Greggory Wiley
  • 660
  • 6
  • 16