Skip to content

Commit

Permalink
Check nonnull response and response code when checking if bucket/obje…
Browse files Browse the repository at this point in the history
…ct/directory exist
  • Loading branch information
tdrwenski committed Apr 26, 2023
1 parent 43d21f9 commit bf0a581
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions cdm/s3/src/main/java/thredds/inventory/s3/MFileS3.java
Original file line number Diff line number Diff line change
Expand Up @@ -315,25 +315,25 @@ private boolean directoryExists() {
try {
final ListObjectsV2Response listObjects =
client.listObjectsV2(ListObjectsV2Request.builder().bucket(cdmS3Uri.getBucket()).prefix(key).build());
return !listObjects.contents().isEmpty();
return listObjects.sdkHttpResponse().isSuccessful() && !listObjects.contents().isEmpty();
} catch (NoSuchBucketException e) {
return false;
}
}

private boolean bucketExists() {
try {
getHeadBucketResponse();
return true;
final HeadBucketResponse response = getHeadBucketResponse();
return response != null && response.sdkHttpResponse().isSuccessful();
} catch (NoSuchBucketException e) {
return false;
}
}

private boolean objectExists() {
try {
headObjectResponse.get();
return true;
final HeadObjectResponse response = headObjectResponse.get();
return response != null && response.sdkHttpResponse().isSuccessful();
} catch (NoSuchKeyException e) {
return false;
}
Expand Down

0 comments on commit bf0a581

Please sign in to comment.