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

GCS NIO readAttributes returns CloudStorageObjectAttributes for directory like objects #3918

Closed
tomcham opened this issue Nov 7, 2018 · 3 comments
Assignees
Labels
priority: p2 Moderately-important priority. Fix may not be included in next release. type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns.

Comments

@tomcham
Copy link

tomcham commented Nov 7, 2018

Thanks for stopping by to let us know something could be better!

Please include as much information as possible:

Environment details

  • google-cloud-java version(s): google-cloud-nio:0.69.0-alpha

Steps to reproduce

  1. In the GCS UI within a bucket, press create folder button and create a folder called dir
  2. Upload a file within dir call this fileA

Code snippet

    FileSystem fs = ....
    Files.walkFileTree(fs.getPath("dir") new SimpleFileVisitor<Path>() {
      @Override
      public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
        System.out.println(file);
        return FileVisitResult.CONTINUE;
      }

Any additional information below

The GCS UI creates a 0 byte object called dir/ This causes readAttributes to return https://github.com/googleapis/google-cloud-java/blob/v0.69.0/google-cloud-clients/google-cloud-contrib/google-cloud-nio/src/main/java/com/google/cloud/storage/contrib/nio/CloudStorageFileSystemProvider.java#L765, which prevents further traversal of objects within that directory.

Does it make sense to do a check like https://github.com/googleapis/google-cloud-java/blob/v0.69.0/google-cloud-clients/google-cloud-contrib/google-cloud-nio/src/main/java/com/google/cloud/storage/contrib/nio/CloudStorageFileSystemProvider.java#L756 usePseudoDirectories is enabled and it is a 0 byte object?

I saw this related merged PR https://github.com/googleapis/google-cloud-java/pull/3775/files by @jean-philippe-martin

@chingor13 chingor13 added type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns. priority: p2 Moderately-important priority. Fix may not be included in next release. labels Nov 7, 2018
@jean-philippe-martin
Copy link

Yes, what the UI does is rather surprising. As discussed in this GitHub issue we end up with both a file and a directory that have the same name.

I didn't see your fix before writing mine, sorry. I think it makes sense for NIO to report the underlying truth, namely that both the file and the directory exist.

@jean-philippe-martin
Copy link

Reopen: there is some tool out there that now creates 11-byte files with a trailing slash to pretend directories exist, and this breaks the merged fix.

See this bug report for an example.

@jean-philippe-martin
Copy link

OK no need to reopen, let's use #5203 instead.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
priority: p2 Moderately-important priority. Fix may not be included in next release. type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns.
Projects
None yet
Development

No branches or pull requests

4 participants