From 92891d4abf1875a79a7fa3d60fce4f37df13463b Mon Sep 17 00:00:00 2001 From: Ben Raymond Date: Mon, 23 Sep 2024 10:54:04 +1000 Subject: [PATCH] fix error checking bucket existence v0.16.3 --- DESCRIPTION | 2 +- R/aws_s3.R | 10 ++++++---- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index 8af8677..f666289 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,7 +1,7 @@ Package: bowerbird Type: Package Title: Keep a Collection of Sparkly Data Resources -Version: 0.16.2 +Version: 0.16.3 Authors@R: c(person("Ben", "Raymond", email = "ben.raymond@aad.gov.au", role = c("aut", "cre")), person("Michael", "Sumner", role = "aut"), person("Miles", "McBain", email = "miles.mcbain@gmail.com", role = c("rev", "ctb")), diff --git a/R/aws_s3.R b/R/aws_s3.R index c7373f2..1c6f6f1 100644 --- a/R/aws_s3.R +++ b/R/aws_s3.R @@ -190,10 +190,12 @@ aws_list_objects <- function(s3_args, create = FALSE) { chk <- aws_fun(aws.s3::bucketlist, s3_args[setdiff(names(s3_args), "bucket")]) ##chk <- tryCatch(aws_fun(aws.s3::bucket_exists, s3_args), error = function(e) stop("no can do")) ## bucket_exists returns 404 error if the bucket does not exist, 403 error if it exists but is inaccessible to these credentials? - if ((nrow(chk) < 1 || !s3_args$bucket %in% chk$Bucket) && isTRUE(create)) { - chk <- tryCatch(aws_fun(aws.s3::put_bucket, s3_args), error = function(e) stop("Could not create bucket. ", conditionMessage(e))) - } else { - stop("bucket does not exist") + if ((nrow(chk) < 1 || !s3_args$bucket %in% chk$Bucket)) { + if (isTRUE(create)) { + chk <- tryCatch(aws_fun(aws.s3::put_bucket, s3_args), error = function(e) stop("Could not create bucket. ", conditionMessage(e))) + } else { + stop("bucket does not exist") + } } ## get bucket contents tryCatch({