Skip to content

Commit

Permalink
Improve upload messaging
Browse files Browse the repository at this point in the history
  • Loading branch information
aaronwolen committed Dec 1, 2019
1 parent 053fc55 commit 6a3a99e
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 12 deletions.
2 changes: 1 addition & 1 deletion R/osf_download.R
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ osf_download.osf_tbl_file <-
zip_file <- fs::path(tempdir(), x$name, ext = "zip")

# print a message because this can take a while on OSF's end
message(sprintf("Requesting folder '%s' from OSF...", x$name))
message(sprintf("Requesting folder '%s' from OSF", x$name))

.wb_download(
id = get_parent_id(x),
Expand Down
21 changes: 12 additions & 9 deletions R/osf_upload.R
Original file line number Diff line number Diff line change
Expand Up @@ -144,14 +144,17 @@ osf_upload.osf_tbl_file <-

.osf_upload <- function(dest, path, recurse, conflicts, progress, verbose) {

# be more verbose when uploading directories
any_dirs <- any(fs::is_dir(path))

# inventory of files to upload and/or remote directories to create
manifest <- map_rbind(.upload_manifest, path = path, recurse = recurse)

# retrieve remote destinations
manifest <- .ulm_add_remote_dests(manifest, dest, verbose)

# identify conflicting files at remote destinations
manifest <- .ulm_add_conflicting_files(manifest, verbose)
manifest <- .ulm_add_conflicting_files(manifest, verbose || any_dirs)
manifest$conflicted <- purrr::map_lgl(manifest$remote_file, Negate(is.null))

# list of osf_tbls to be returned
Expand Down Expand Up @@ -199,10 +202,10 @@ osf_upload.osf_tbl_file <-
)

if (!is.null(manifest$update)) {
message(sprintf(
"Attempting to update %i existing file(s) on OSF...",
nrow(manifest$update)
))
n <- nrow(manifest$update)
msg <- sprintf("Updating %i existing file(s) on OSF", n)
if (verbose || any_dirs) message(msg)

out$updated <- Map(.update_existing_file,
path = manifest$update$path,
dest = manifest$update$remote_file,
Expand All @@ -212,10 +215,10 @@ osf_upload.osf_tbl_file <-
}

if (!is.null(manifest$upload)) {
message(sprintf(
"Attempting to upload %i new file(s) to OSF...",
nrow(manifest$upload)
))
n <- nrow(manifest$upload)
msg <- sprintf("Uploading %i new file(s) to OSF", n)
if (verbose || any_dirs) message(msg)

out$uploaded <- Map(.upload_new_file,
path = manifest$upload$path,
dest = manifest$upload$remote_dest,
Expand Down
4 changes: 2 additions & 2 deletions R/utils-upload-manifest.R
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
# retrieve (or create) each unique remote directory
remote_dirs <- unique(manifest$remote_dir)
if (any(remote_dirs != ".")) {
message("Retrieving upload destinations from OSF...")
if (verbose) message("Retrieving upload destinations from OSF")
}

remote_dests <- Map(recurse_path,
Expand All @@ -66,7 +66,7 @@
#' @noRd
.ulm_add_conflicting_files <- function(manifest, verbose) {

message("Searching for conflicting files on OSF...")
if (verbose) message("Searching for conflicting files on OSF")

# list existing files within each remote destination
remote_dests <- manifest$remote_dest[!duplicated(manifest$remote_dir)]
Expand Down

0 comments on commit 6a3a99e

Please sign in to comment.