-
Notifications
You must be signed in to change notification settings - Fork 348
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix download with pattern issue in rooted filesystem #88
Fix download with pattern issue in rooted filesystem #88
Conversation
public void testScpVirtualOnDirWithPattern() throws Exception { | ||
Path remoteDir = Files.createTempDirectory("remote"); | ||
sshd.setFileSystemFactory(new VirtualFileSystemFactory(remoteDir)); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please use getTempTargetRelativeFile
(method inherited from JUnitTestSupport
) - it makes sure that the file(s) reside under target
folder which is cleaned when mvn clean
is invoked. Your code leaves "orphan" directories and files in the user's /tmp
folder.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm cleaning that at the end of the test. But this is more cleaner.
@Test | ||
public void testScpVirtualOnDirWithPattern() throws Exception { | ||
Path remoteDir = Files.createTempDirectory("remote"); | ||
sshd.setFileSystemFactory(new VirtualFileSystemFactory(remoteDir)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please note that sshd
is a shared instance - therefore you need to restore it to its original state:
@Test
public void testScpVirtualOnDirWithPattern() throws Exception {
try {
...
sshd.setFileSystemFactory(...test factory...);
...
} finally {
sshd.setFileSystemFactory(fileSystemFactory); // the one created in the test constructor
}
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is being taken care in Before
block which gets executed before each test.
@Before
public void setUp() throws Exception {
sshd.setFileSystemFactory(fileSystemFactory);
}
Iterable<String> included = opener.getMatchingFilesToSend(session, basedir, pattern); | ||
Path basePath = resolveLocalPath(basedir); | ||
Iterable<String> included = opener.getMatchingFilesToSend(session, basePath.toFile().getAbsolutePath(), pattern); | ||
|
||
for (String path : included) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please don't use toFile
- if you want the absolute path then use basePath.toAbsolutePath().toString()
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
basePath.toAbsolutePath().toString()
won't give absolute path of the file when the underlying filesystem is virtual filesystem. I couldn't find any other cleaner way other than toFile
I assume you have run the unit test before the patch and saw that if fails.... |
BWT, if you rename the issue |
I have tried your code with the fixes and the unit test fails:
|
Right now, download with pattern doesn't work when the underlying filesystem is virtual filesystem. Also, the tests were masking the behaviour by providing working location as rooted filesystem path. This patch fixes the issue, by providing absolute path to retrieve files matching the pattern.
3dd2f78
to
f4883f2
Compare
Anything specific I need to do to run tests? It passes for me.
|
No - but have you tried using the relative-temp-file path ? |
I believe I found a better way - see https://github.com/lgoldstein/mina-sshd/tree/SSHD-893 (based on your code). Can you review it and let me know if this is what you meant + run some tests on it ? |
See also #89 |
Sure. Let me check. |
@lgoldstein #89 covers the fix. Shall I close this PR? |
Yes, please close it and we'll discuss #89 |
Right now, download with pattern doesn't work when the underlying
filesystem is virtual filesystem. Also, the tests were masking the
behaviour by providing working location as rooted filesystem path.
This patch fixes the issue, by providing absolute path to retrieve files
matching the pattern.
cc @lgoldstein @thefourtheye @sramki