Repository: mina-sshd Updated Branches: refs/heads/master 39392f594 -> 0cb36d988
[SSHD-802] Listing directories using a RootedFileSystem returns non rooted paths Project: http://git-wip-us.apache.org/repos/asf/mina-sshd/repo Commit: http://git-wip-us.apache.org/repos/asf/mina-sshd/commit/0cb36d98 Tree: http://git-wip-us.apache.org/repos/asf/mina-sshd/tree/0cb36d98 Diff: http://git-wip-us.apache.org/repos/asf/mina-sshd/diff/0cb36d98 Branch: refs/heads/master Commit: 0cb36d988e94c8fb916898d91a30ec5f548d6d68 Parents: 39392f5 Author: Guillaume Nodet <gno...@apache.org> Authored: Tue Feb 6 17:04:07 2018 +0100 Committer: Guillaume Nodet <gno...@apache.org> Committed: Tue Feb 6 17:04:14 2018 +0100 ---------------------------------------------------------------------- .../file/root/RootedFileSystemProvider.java | 29 +++++++++++++++++++- .../file/root/RootedFileSystemProviderTest.java | 13 +++++++++ 2 files changed, 41 insertions(+), 1 deletion(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/0cb36d98/sshd-core/src/main/java/org/apache/sshd/common/file/root/RootedFileSystemProvider.java ---------------------------------------------------------------------- diff --git a/sshd-core/src/main/java/org/apache/sshd/common/file/root/RootedFileSystemProvider.java b/sshd-core/src/main/java/org/apache/sshd/common/file/root/RootedFileSystemProvider.java index ee1fa2e..1866346 100644 --- a/sshd-core/src/main/java/org/apache/sshd/common/file/root/RootedFileSystemProvider.java +++ b/sshd-core/src/main/java/org/apache/sshd/common/file/root/RootedFileSystemProvider.java @@ -44,6 +44,7 @@ import java.nio.file.attribute.BasicFileAttributes; import java.nio.file.attribute.FileAttribute; import java.nio.file.attribute.FileAttributeView; import java.nio.file.spi.FileSystemProvider; +import java.util.Iterator; import java.util.HashMap; import java.util.Map; import java.util.Objects; @@ -192,7 +193,33 @@ public class RootedFileSystemProvider extends FileSystemProvider { public DirectoryStream<Path> newDirectoryStream(Path dir, DirectoryStream.Filter<? super Path> filter) throws IOException { Path r = unroot(dir); FileSystemProvider p = provider(r); - return p.newDirectoryStream(r, filter); + return root(((RootedPath) dir).getFileSystem(), p.newDirectoryStream(r, filter)); + } + + protected DirectoryStream<Path> root(RootedFileSystem rfs, DirectoryStream<Path> ds) { + return new DirectoryStream<Path>() { + @Override + public Iterator<Path> iterator() { + return root(rfs, ds.iterator()); + } + @Override + public void close() throws IOException { + ds.close(); + } + }; + } + + protected Iterator<Path> root(RootedFileSystem rfs, Iterator<Path> iter) { + return new Iterator<Path>() { + @Override + public boolean hasNext() { + return iter.hasNext(); + } + @Override + public Path next() { + return root(rfs, iter.next()); + } + }; } @Override http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/0cb36d98/sshd-core/src/test/java/org/apache/sshd/common/file/root/RootedFileSystemProviderTest.java ---------------------------------------------------------------------- diff --git a/sshd-core/src/test/java/org/apache/sshd/common/file/root/RootedFileSystemProviderTest.java b/sshd-core/src/test/java/org/apache/sshd/common/file/root/RootedFileSystemProviderTest.java index e63db36..4d750ff 100644 --- a/sshd-core/src/test/java/org/apache/sshd/common/file/root/RootedFileSystemProviderTest.java +++ b/sshd-core/src/test/java/org/apache/sshd/common/file/root/RootedFileSystemProviderTest.java @@ -226,6 +226,19 @@ public class RootedFileSystemProviderTest extends AssertableFile { } } + @Test + public void testResolveRoot() throws IOException { + Path root = fileSystem.getRootDirectories().iterator().next(); + Path dir = root.resolve("tsd"); + FileHelper.createDirectory(dir); + Path f1 = FileHelper.createFile(dir.resolve("test.txt")); + Path f2 = Files.newDirectoryStream(dir).iterator().next(); + assertTrue("Unrooted path found", f2 instanceof RootedPath); + assertEquals(f1, f2); + FileHelper.deleteFile(f1); + FileHelper.deleteDirectory(dir); + } + /* Private helper */ /**