Lyor G. ,
Thanks very much for this.

I’ve haven’t managed to spend as much time on it as I would like just yet, but 
cutting it down has helped already.
The item of code you mentioned does work as you said it does, and I can call it 
fine in most circumstances.
However, and I could be looking at this incorrectly, from what I have seen, 
only really the default filesystem really implements a tofile method (and may 
not include the posix attribute).  Any other filesystem I have seen never 
implements it.  Now I don’t know if that is due to the view of not needing one, 
or because it is a little backwards once something uses nio.


Either way, my feeling is that the IoUtils#getPermissionsFromFile method should 
try to use path and emulate the POSIX attributes as you do elsewhere.  I’ve 
mocked that and in my cut-down code, it appears to work nicely when a 
filesystem is how I just described it – though my code is only half baked – I 
didn’t manage to set the owner and group names – but it got me past errors.

On the other side of this, you are of course correct in that my cut-down code 
does appear to work as expected.  My original issue was probably not described 
especially well.  Once I saw the error, it appeared that I was holding on to 
the files I uploaded via SFTP.  I can confirm that with the edit to IoUtils, I 
can run some cutdown code and upload using the default filesystem on Windows, 
and also CryptoFS<https://github.com/cryptomator/cryptofs>.

So now I have potentially realised where I may be going wrong.

What I didn’t describe is that I was running this inside Tomcat.  Now apart 
from what I have described, I understand there most likely is no issue here, so 
feel free to ignore me!
However, if you are still intreagued, I am wondering if my issue is that I 
attempted to load the filesystems using a custom clasloader... so most likely 
created a pinned class-loader scenario which kept my files open in memory and 
hence could not be removed without the JVM shutting down (and therefore 
reported that the permissions on files were incorrect – or really not there – 
as the file was a bit of a ghost one).

Anyway, babble.  Do you think that could be a possibility?

I’m investigating this further now, but am wondering if I have gone the worng 
way in loading SSHD into Tomcat via a listener etc.
Are you aware of any examples which can load up filesystemproviders within a 
Tomcat environment?  I understand that SSHD does in fact make sftp available... 
but I’m not sure if that actually works within Tomcat – I’ll try to check.

Of course, I will welcome any ideas, but don’t worry as this has potentially 
moved on from the ‘SSHD’ specific side of things – apart from looking forward 
to comments on the IoUtils#getPermissionsFromFile part.

Many thanks for your time on this and what you and the rest of the devs have 
done for these projects.
I’m slowly building up confidence to then attempt contributing something more 
properly after using many of these projects so far!

Regards,
Adam.


From: Lyor Goldstein<mailto:lgoldst...@apache.org>
Sent: 03 December 2018 18:39
To: dev@mina.apache.org<mailto:dev@mina.apache.org>
Subject: Re: SSHD - java.nio.file usage - possible issue

Hi Adam,

I have not been able to figure out is the exact issue you are encountering,
but if you can diagnose it and perhaps provide some test code that
reproduces it, we will certainly try and see how to make it work.

That being said, a few remarks on this issue:

>> have been implementing various nio filesystems

If indeed the file that SSHD is trying to query about its permissions is on
some proprietary implementation, then this needs to be debugged by the
specific file system in order to see if it "mis-behaves" somehow (see more
below).

>> I can’t tell if there is an issue here or not, however, it may be one
restricted to Windows

I can say with a very high degree of certainty that the code works on
standard Windows file systems without any problems - I personally tested
this code on Windows 7, 8 and 10 without any issues - both FAT and NT.

>> uses a file object if the views don’t contain the POSIX attribute

The code attempts to emulate POSIX permissions by using File instead of
Path if it detects the Windows file system. However, if the file resides on
some special proprietary/custom file system, there may be problems.

Which brings me back to the original suggestion - try and debug the issue.
Should be fairly easy to set up a test code with a *main* that simply
accepts some file path and then invokes
org.apache.sshd.common.util.io.IoUtils.java#getPermissions. Simply try this
code with various locations - some that reside on "suspicious" file systems
and try to diagnose the issue.

While we might not be able to fix it for you, we might be able to add some
hooks into the code that you can use as a workaround for your specific
issue (and hopefully others that may encounter similar problems). Once you
have more concrete data - and perhaps an idea as to the hooks/workarounds
you need, please open an SSHD issue on our JIRA site (
https://issues.apache.org/jira) - we will certainly try and see how we can
help.

Lyor G.

Reply via email to