[ 
https://issues.apache.org/jira/browse/SSHD-1130?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Logan updated SSHD-1130:
------------------------
    Description: 
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}
 

  was:
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}
 


> 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