Skip to content
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

Files.list() returns empty if path has trailing slashes #207

Closed
n3v3rf411 opened this issue Oct 5, 2023 · 4 comments
Closed

Files.list() returns empty if path has trailing slashes #207

n3v3rf411 opened this issue Oct 5, 2023 · 4 comments
Labels
bug Something isn't working

Comments

@n3v3rf411
Copy link

getContainedObjectBatches is filtering on:

    .filter(s3Object -> s3Object.key().equals(prefix) || s3Object.key().startsWith(prefix + S3Path.PATH_SEPARATOR))

This fails when you are going to Files.list() a Path returned from a Files.list() response:

val path = Files
      .list(basePath)
      .filter(Files.isDirectory(_))
      .sorted((a, b) => b.compareTo(a))
      .filter(it => Files.exists(it.resolve(successFileName)))
      .findFirst()

Files.list(path.get) // This returns empty even if there are files in the "folder"
@markjschreiber
Copy link
Contributor

Apologies for the slow response,

I wonder if this s3Object.key().startsWith(prefix + S3Path.PATH_SEPARATOR) should maybe be s3Object.key().equals(prefix + S3Path.PATH_SEPARATOR))

It would need some testing, especially with walking a tree from a starting node.

@markjschreiber markjschreiber added the bug Something isn't working label Oct 17, 2023
@markjschreiber
Copy link
Contributor

The failure seems to occur when filtering on Files.exists()

@markjschreiber
Copy link
Contributor

The source of the problem seems to be that S3FileSystemProvider.checkAccess() calls HeadObject on S3. This only succeeds if the path points to an object. If the path is just a prefix (s3 Directory) then it will fail. A better solution might be to use client.listObjectsV2() and ensure that the path is included in the response.

@markjschreiber
Copy link
Contributor

This should now be fixed in main. Please re-open if there are still issues.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants