Skip to content
This repository has been archived by the owner on Jan 5, 2023. It is now read-only.

Commit

Permalink
Fix issue 28
Browse files Browse the repository at this point in the history
  • Loading branch information
RobinL committed Jul 9, 2018
1 parent f8fcdad commit 2d14af5
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 10 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: s3tools
Title: Tools to help explore s3
Version: 0.0.3
Version: 0.0.4
Authors@R: c(person("Will", "Bowditch", email = "william.bowditch@digital.justice.gov.uk", role = c("aut")),person("Robin", "Linacre", email = "Robin.Linacre@digital.justice.gov.uk", role = c("aut", "cre")))
Description: Tools to help explore Amazon s3
Depends: R (>= 3.3.2)
Expand Down
22 changes: 13 additions & 9 deletions R/aws_helper_functions.R
Original file line number Diff line number Diff line change
Expand Up @@ -11,27 +11,31 @@
#'
list_files_in_buckets <- function(bucket_filter=NULL, prefix=NULL, path_only=FALSE) {

s3tools::get_credentials()

if (is.null(bucket_filter)) {
stop("You must provide one or more buckets e.g. accessible_files_df('alpha-everyone') This function will list their contents")
}

ab <- accessible_buckets()

if (!(is.null(bucket_filter))) {
ab <- ab[ab %in% bucket_filter]
has_access <- function(bucket_name) {
result <- tryCatch(aws.s3::get_bucket_df(bucket_name, 'longprefix'), error = function(c) {"Cannot list bucket"})
if (typeof(result) == 'character') {
return (FALSE)
} else
return (TRUE)
}

no_access <- bucket_filter[!(bucket_filter %in% ab)]
bucket_access_bool <- sapply(bucket_filter, has_access)

if (length(no_access) > 0) {
no_access_str <- paste(no_access, collapse = ", ")
if (!(all(bucket_access_bool))) {
no_access_str <- paste(bucket_filter[!(bucket_access_bool)], collapse = ", ")
stop(paste("You asked to list some buckets you don't have access to: ", no_access_str))
}

if (is.null(prefix)) {
af <- do.call(rbind, lapply(ab, aws.s3::get_bucket_df))
af <- do.call(rbind, lapply(bucket_filter, aws.s3::get_bucket_df))
} else {
af <- do.call(rbind, lapply(ab, aws.s3::get_bucket_df, prefix=prefix))
af <- do.call(rbind, lapply(bucket_filter, aws.s3::get_bucket_df, prefix=prefix))
}

if (nrow(af)==0) {
Expand Down

0 comments on commit 2d14af5

Please sign in to comment.