robtimus/sftp-fs

java.nio.file.NotDirectoryException if server is not returning . and ..

gadton opened this issue · 3 comments

Files.list( path ) is throwing a java.nio.file.NotDirectoryException if the server is not returning the entries . and ...
This is because of the check in SFTPFileSystem.newDirectoryStream(...).

Is there a standard (?) way of forcing the server to return the required entries?
Could this check be removed or added a config switch to deactivate it?

Example:

try (FileSystem fs = FileSystems.newFileSystem( URI.create( "sftp://myhost" ), sftpEnv ))
{
    final Path dir = fs.getPath( "Test1" );
    System.out.println( Files.isRegularFile( dir ) );
    System.out.println( Files.isDirectory( dir ) );
    System.out.println( Files.isReadable( dir ) );
    System.out.println( Files.isWritable( dir ) );
    System.out.println( Files.exists( dir ) );

    Files.list( dir );
}

isRegularFile is returning false, next four true, but Files.list( dir ) is throwing NotDirectoryException.

Thanks

Maybe an alternative to checking for a returned .: call Files.isDirectory(...) using the given path before calling the channel or the implementation of this method: SFTPPath.readAttributes(...)

I've just released a new version that should fix this issue. I've added a stat call (like with SFTPPath.readAttributes); a NotDirectoryException is now only thrown if that says it's not a directory.

Great job! Thank you for this really fast solution.