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

fix: FileSystemProvider::checkAccess fails on '/' with StorageException #1065

Merged
merged 1 commit into from
Dec 7, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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