[ 
https://issues.apache.org/jira/browse/SSHD-1130?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17287767#comment-17287767
 ] 

Logan commented on SSHD-1130:
-----------------------------

My suggestion is purely on uniformity so that both ways of iterating through 
directory listing are consistent (throwing right of kind of exceptions) and 
developers using the API don't tie their implementation based on API 
implementation as the latter can change. You are best the judge on how to 
address this issue.

> Sftp directory listing with permission denied error
> ---------------------------------------------------
>
>                 Key: SSHD-1130
>                 URL: https://issues.apache.org/jira/browse/SSHD-1130
>             Project: MINA SSHD
>          Issue Type: Improvement
>    Affects Versions: 2.1.0, 2.6.0
>            Reporter: Logan
>            Priority: Major
>
> Iterating a directory with not enough permissions using {{DirectoryStream}} 
> throws {{SftpException}} wrapped as {{RuntimeException}} on the 
> {{iterator.next()}}, While this is perfectly valid with Iterator interface 
> standard, to really determine if the issue is with permissions we have look 
> at the cause of {{RuntimeException}}.
>  
> {code:java}
> try (DirectoryStream<Path> ds = Files.newDirectoryStream(remoteDir)) {
>    for (Path remoteFile : ds) { ..}
> } catch (RuntimeException ex) { 
>     Throwable cause = ex.getCause();  
>     if (cause != null && cause instanceof SftpException) { 
>        System.err.println("sftp error..probably permissions issue: " + 
> ex.getMessage());
>     } else {
>        System.err.println("Unknown error: " + ex.getMessage()); 
>     }
> }
> {code}
>  
> On the flip side using {{SftpClient}} and {{SftpDirEntryIterator}}, an 
> {{SftpException}} is throw in the constructor of {{SftpDirEntryIterator}}.  
> This makes easy to determine that cause of the error for invalid permissions. 
>  So wondering if the implementation of {{SftpDirectoryStream}} can be 
> improved throw {{SftpException}} in the constructor?
>  
> {code:java}
> try (SftpDirEntryIterator pathIterator = new SftpDirEntryIterator(sftpClient, 
> remotePath)) {
>    while (pathIterator.hasNext()) {
>    DirEntry dirEntry = pathIterator.next();
>    ...
>  }
>  } catch (SftpException ex) {}
> {code}
>  



--
This message was sent by Atlassian Jira
(v8.3.4#803005)

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscr...@mina.apache.org
For additional commands, e-mail: dev-h...@mina.apache.org

Reply via email to