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: prevent crash when checking if a missing file exists #856 #858

Merged
merged 1 commit into from
Mar 16, 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 @@ -123,7 +123,7 @@ public static final class Builder {
private int blockSize = CloudStorageFileSystem.BLOCK_SIZE_DEFAULT;
private int maxChannelReopens = 0;
private @Nullable String userProject = null;
// This of this as "clear userProject if not RequesterPays"
// Think of this as "clear userProject if not RequesterPays"
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

opportunistic typo fix

private boolean useUserProjectOnlyForRequesterPaysBuckets = false;
private ImmutableList<Integer> retryableHttpCodes = ImmutableList.of(500, 502, 503);
private ImmutableList<Class<? extends Exception>> reopenableExceptions =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import com.google.cloud.storage.Blob;
import com.google.cloud.storage.BlobId;
import com.google.cloud.storage.Storage;
import com.google.common.base.Strings;
import com.google.common.collect.UnmodifiableIterator;
import java.io.File;
import java.net.URI;
Expand Down Expand Up @@ -113,7 +114,7 @@ boolean seemsLikeADirectoryAndUsePseudoDirectories(Storage storage) {
}
String userProject = fileSystem.config().userProject();
Page<Blob> list = null;
if (userProject != null) {
if (!Strings.isNullOrEmpty(userProject)) {
list =
storage.list(
this.bucket(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,18 @@ public void testAutodetectWhenNotRequesterPays() throws IOException {
"");
}

@Test
public void testFilesExistDoesntCrashWhenRequesterPays() throws IOException {
CloudStorageConfiguration config =
CloudStorageConfiguration.builder()
.autoDetectRequesterPays(true)
.userProject(project)
.build();
CloudStorageFileSystem testBucket =
CloudStorageFileSystem.forBucket(BUCKET, config, storageOptions);
Assert.assertFalse(Files.exists(testBucket.getPath("path")));
}

@Test
public void testAutoDetectNoUserProject() throws IOException {
CloudStorageFileSystem testBucket = getRequesterPaysBucket(false, "");
Expand Down