From bb49622afae1df4c11497f61b3ee08faf2dc7c6d Mon Sep 17 00:00:00 2001 From: Julia Silge Date: Fri, 8 Sep 2023 14:13:06 -0600 Subject: [PATCH] Fix how `board_gdrive()` uses dribble components (#782) * Fix how `board_gdrive()` uses dribble components * Update NEWS * Oops, not returning here * Only search Google Drive using a dribble (no path) * Update `gdrive_download()` to use dribble (not path) --- NEWS.md | 2 +- R/board_gdrive.R | 39 +++++++++++++++++++++++++-------------- 2 files changed, 26 insertions(+), 15 deletions(-) diff --git a/NEWS.md b/NEWS.md index 40f851ff..4f3d6b74 100644 --- a/NEWS.md +++ b/NEWS.md @@ -7,7 +7,7 @@ * Added `board_deparse` for `board_url()` (#774). -* Fixed how `board_gdrive()` makes version directories (#780, @gorkang). +* Fixed how `board_gdrive()` handles dribble objects (#780, @gorkang and #782). # pins 1.2.1 diff --git a/R/board_gdrive.R b/R/board_gdrive.R index bb470070..539d1dc0 100644 --- a/R/board_gdrive.R +++ b/R/board_gdrive.R @@ -66,7 +66,7 @@ pin_list.pins_board_gdrive <- function(board, ...) { #' @export pin_exists.pins_board_gdrive <- function(board, name, ...) { - all_names <- googledrive::drive_ls(board$dribble$name)$name + all_names <- googledrive::drive_ls(board$dribble)$name name %in% all_names } @@ -74,20 +74,30 @@ pin_exists.pins_board_gdrive <- function(board, name, ...) { pin_delete.pins_board_gdrive <- function(board, names, ...) { for (name in names) { check_pin_exists(board, name) - gdrive_delete_dir(board, name) + dribble <- googledrive::drive_ls(board$dribble) + dribble <- dribble[dribble$name == name,] + googledrive::drive_trash(dribble) } invisible(board) } #' @export pin_version_delete.pins_board_gdrive <- function(board, name, version, ...) { - gdrive_delete_dir(board, fs::path(name, version)) + check_pin_exists(board, name) + pin_dribble <- googledrive::drive_ls(board$dribble) + pin_dribble <- pin_dribble[pin_dribble$name == name,] + version_dribble <- googledrive::drive_ls(pin_dribble) + version_dribble <- version_dribble[version_dribble$name == version,] + googledrive::drive_trash(version_dribble) + invisible() } #' @export pin_versions.pins_board_gdrive <- function(board, name, ...) { check_pin_exists(board, name) - path <- fs::path(board$dribble$path, name) + dribble <- googledrive::drive_ls(board$dribble) + dribble <- dribble[dribble$name == name,] + path <- googledrive::as_dribble(dribble) version_from_path(sort(googledrive::drive_ls(path)$name)) } @@ -179,22 +189,23 @@ possibly_drive_ls <- function(...) { } gdrive_file_exists <- function(board, name) { - path <- fs::path(board$dribble$name, fs::path_dir(name)) + dribble <- googledrive::drive_ls(board$dribble) + path_components <- purrr::pluck(fs::path_split(fs::path_dir(name)), 1) + for (path_component in path_components) { + dribble <- dribble[dribble$name == path_component,] + dribble <- possibly_drive_ls(dribble) + } name <- fs::path_file(name) - all_names <- possibly_drive_ls(path) - name %in% all_names$name -} - -gdrive_delete_dir <- function(board, dir) { - path <- fs::path(board$dribble$path, dir) - googledrive::drive_trash(path) - invisible() + name %in% dribble$name } gdrive_download <- function(board, key) { path <- fs::path(board$cache, key) if (!fs::file_exists(path)) { - googledrive::drive_download(key, path) + dribble <- googledrive::as_dribble(fs::path_dir(key)) + dribble <- googledrive::drive_ls(dribble) + dribble <- dribble[dribble$name == fs::path_file(key),] + googledrive::drive_download(dribble, path) fs::file_chmod(path, "u=r") } path