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
getChildren needs ending slash but won't accept one #22
Comments
The problem actually is caused by S3FileObject not determining if the parent is a child directory of ROOT or ROOT itself. In the case the parent is ROOT then the NameScope should be NameScope.FILE_SYSTEM otherwise it is NameScope.CHILD. I updated the S3FileObject and created a unit test for listChildrenRoot , see the patch below. diff --git a/src/main/java/com/intridea/io/vfs/provider/s3/S3FileObject.java b/src/main/java/com/intridea/io/vfs/provider/s3/S3FileObject.java index 4f20f53..a77bbff 100644 --- a/src/main/java/com/intridea/io/vfs/provider/s3/S3FileObject.java +++ b/src/main/java/com/intridea/io/vfs/provider/s3/S3FileObject.java @@ -293,8 +293,8 @@ for (String commonPrefix : commonPrefixes) { // strip path from name (leave only base name) final String stripPath = commonPrefix.substring(path.length()); - FileObject childObject = resolveFile(stripPath, NameScope.CHILD); - if (childObject instanceof S3FileObject) { + FileObject childObject = resolveFile(stripPath, stripPath.equals("/")?NameScope.FILE_SYSTEM:NameScope.CHILD); + if (childObject instanceof S3FileObject && !stripPath.equals("/")) { S3FileObject s3FileObject = (S3FileObject) childObject; resolvedChildren.add(s3FileObject); } diff --git a/src/test/java/com/intridea/io/vfs/provider/s3/S3ProviderTest.java b/src/test/java/com/intridea/io/vfs/provider/s3/S3ProviderTest.java index 7bc7c47..54aa4e0 100644 --- a/src/test/java/com/intridea/io/vfs/provider/s3/S3ProviderTest.java +++ b/src/test/java/com/intridea/io/vfs/provider/s3/S3ProviderTest.java @@ -325,6 +325,13 @@ FileObject[] children = baseDir.getChildren(); assertEquals(children.length, 5); } + + @Test(dependsOnMethods={"createFileOk", "createDirOk","uploadBigFile"}) + public void listChildrenRoot() throws FileSystemException { + FileObject root = fsManager.resolveFile("s3://" + bucketName + "/"); + FileObject[] children = root.getChildren(); + assertEquals(children.length, 2); + } @Test(dependsOnMethods={"createDirOk"}) public void findFiles() throws FileSystemException { |
I have a Scala/sbt test project at https://github.com/mslinn/vfs-s3Test. The tests show a few issues:
|
@mslinn to be fair I was not able to reproduce your issue. Maybe you took old code or 2.1.x branch, please update to latest version and let me know does it fix everything or not. And I don't see any problems with including code from @cuzz22000 into list of tests. I did a little refactoring for it so here you go - 133a484 |
AWS CLI will not list the contents of a directory unless the path ends in a slash:
Seems the Java library works the same way, but vfs-s3 removes the trailing slash so
getChildren()
does not return the expected value:Output is:
Should I not use
getChildren()
because there is a better way of listing an S3 directory?Here is my project with both Scala and Java code that demonstrates this problem.
The text was updated successfully, but these errors were encountered: