Skip to content

Commit dbfef37

Browse files
authored
FileSystemProvider::checkAccess fails on '/' with StorageException (#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 #1062 ☕️
1 parent 85c34ad commit dbfef37

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

java-storage-nio/google-cloud-nio/src/main/java/com/google/cloud/storage/contrib/nio/CloudStorageFileSystemProvider.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -728,6 +728,11 @@ public void checkAccess(Path path, AccessMode... modes) throws IOException {
728728
// Loop will terminate via an exception if all retries are exhausted
729729
while (true) {
730730
try {
731+
// Edge case is the root directory which triggers the storage.get to throw a
732+
// StorageException.
733+
if (cloudPath.normalize().equals(cloudPath.getRoot())) {
734+
return;
735+
}
731736
boolean nullId;
732737
if (isNullOrEmpty(userProject)) {
733738
nullId =

java-storage-nio/google-cloud-nio/src/test/java/com/google/cloud/storage/contrib/nio/it/ITGcsNio.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@
5353
import java.nio.channels.FileChannel;
5454
import java.nio.channels.ReadableByteChannel;
5555
import java.nio.channels.SeekableByteChannel;
56+
import java.nio.file.AccessMode;
5657
import java.nio.file.FileAlreadyExistsException;
5758
import java.nio.file.FileSystem;
5859
import java.nio.file.FileVisitResult;
@@ -63,6 +64,7 @@
6364
import java.nio.file.StandardCopyOption;
6465
import java.nio.file.StandardOpenOption;
6566
import java.nio.file.attribute.BasicFileAttributes;
67+
import java.nio.file.spi.FileSystemProvider;
6668
import java.util.ArrayList;
6769
import java.util.Arrays;
6870
import java.util.List;
@@ -1196,6 +1198,16 @@ public void testCopy_replaceFile_withOption_srcDoesNotExist() throws IOException
11961198
}
11971199
}
11981200

1201+
@Test
1202+
public void testCheckAccessRoot() throws Exception {
1203+
FileSystem fileSystem = getTestBucket();
1204+
Path path = fileSystem.getPath("/");
1205+
FileSystemProvider provider = fileSystem.provider();
1206+
1207+
// Against the real cloud storage this used to throw a StorageException.
1208+
provider.checkAccess(path, AccessMode.READ, AccessMode.WRITE);
1209+
}
1210+
11991211
private CloudStorageFileSystem getTestBucket() throws IOException {
12001212
// in typical usage we use the single-argument version of forBucket
12011213
// and rely on the user being logged into their project with the

0 commit comments

Comments
 (0)