Skip to content

Commit

Permalink
FileSystemProvider::checkAccess fails on '/' with StorageException (g…
Browse files Browse the repository at this point in the history
…oogleapis#1065)

Thank you for opening a Pull Request! Before submitting your PR, there are a few things you can do to make sure it goes smoothly:
- [x] Make sure to open an issue: https://togithub.com/googleapis/java-storage-nio/issues/1062
- [x] Ensure the tests and linter pass
- [x] Code coverage does not decrease (if any source code was changed)
- [x] Appropriate docs were updated (if necessary)

Fixes googleapis#1062 ☕️
  • Loading branch information
nielsbasjes committed Dec 7, 2022
1 parent a6e55e7 commit d287cf5
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
Expand Up @@ -728,6 +728,11 @@ public void checkAccess(Path path, AccessMode... modes) throws IOException {
// Loop will terminate via an exception if all retries are exhausted
while (true) {
try {
// Edge case is the root directory which triggers the storage.get to throw a
// StorageException.
if (cloudPath.normalize().equals(cloudPath.getRoot())) {
return;
}
boolean nullId;
if (isNullOrEmpty(userProject)) {
nullId =
Expand Down
Expand Up @@ -53,6 +53,7 @@
import java.nio.channels.FileChannel;
import java.nio.channels.ReadableByteChannel;
import java.nio.channels.SeekableByteChannel;
import java.nio.file.AccessMode;
import java.nio.file.FileAlreadyExistsException;
import java.nio.file.FileSystem;
import java.nio.file.FileVisitResult;
Expand All @@ -63,6 +64,7 @@
import java.nio.file.StandardCopyOption;
import java.nio.file.StandardOpenOption;
import java.nio.file.attribute.BasicFileAttributes;
import java.nio.file.spi.FileSystemProvider;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
Expand Down Expand Up @@ -1196,6 +1198,16 @@ public void testCopy_replaceFile_withOption_srcDoesNotExist() throws IOException
}
}

@Test
public void testCheckAccessRoot() throws Exception {
FileSystem fileSystem = getTestBucket();
Path path = fileSystem.getPath("/");
FileSystemProvider provider = fileSystem.provider();

// Against the real cloud storage this used to throw a StorageException.
provider.checkAccess(path, AccessMode.READ, AccessMode.WRITE);
}

private CloudStorageFileSystem getTestBucket() throws IOException {
// in typical usage we use the single-argument version of forBucket
// and rely on the user being logged into their project with the
Expand Down

0 comments on commit d287cf5

Please sign in to comment.