From 338802fae318d110c5515ef223630456fe707f9f Mon Sep 17 00:00:00 2001 From: Julia Silge Date: Wed, 6 Sep 2023 15:03:34 -0600 Subject: [PATCH 1/5] Fix how `board_gdrive()` uses dribble components --- R/board_gdrive.R | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/R/board_gdrive.R b/R/board_gdrive.R index bb470070..6bbd93be 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,31 @@ 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() } 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)) } @@ -185,12 +196,6 @@ gdrive_file_exists <- function(board, name) { name %in% all_names$name } -gdrive_delete_dir <- function(board, dir) { - path <- fs::path(board$dribble$path, dir) - googledrive::drive_trash(path) - invisible() -} - gdrive_download <- function(board, key) { path <- fs::path(board$cache, key) if (!fs::file_exists(path)) { From 441b80ce54e308ef2db4499290a617a6b4d4d0c9 Mon Sep 17 00:00:00 2001 From: Julia Silge Date: Wed, 6 Sep 2023 15:11:26 -0600 Subject: [PATCH 2/5] Update NEWS --- NEWS.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 From b1199e30efe8d6df6354d27d2e93435d8b05f5d5 Mon Sep 17 00:00:00 2001 From: Julia Silge Date: Wed, 6 Sep 2023 15:11:36 -0600 Subject: [PATCH 3/5] Oops, not returning here --- R/board_gdrive.R | 1 - 1 file changed, 1 deletion(-) diff --git a/R/board_gdrive.R b/R/board_gdrive.R index 6bbd93be..e00974e4 100644 --- a/R/board_gdrive.R +++ b/R/board_gdrive.R @@ -77,7 +77,6 @@ pin_delete.pins_board_gdrive <- function(board, names, ...) { dribble <- googledrive::drive_ls(board$dribble) dribble <- dribble[dribble$name == name,] googledrive::drive_trash(dribble) - invisible() } invisible(board) } From d724f8b5127c64c8a1b426927ba41b6dde028c72 Mon Sep 17 00:00:00 2001 From: Julia Silge Date: Thu, 7 Sep 2023 13:35:30 -0600 Subject: [PATCH 4/5] Only search Google Drive using a dribble (no path) --- R/board_gdrive.R | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/R/board_gdrive.R b/R/board_gdrive.R index e00974e4..b049e223 100644 --- a/R/board_gdrive.R +++ b/R/board_gdrive.R @@ -189,10 +189,14 @@ 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 + name %in% dribble$name } gdrive_download <- function(board, key) { From 05209834f5d47458098110805ef07eab74cfdd5c Mon Sep 17 00:00:00 2001 From: Julia Silge Date: Fri, 8 Sep 2023 11:42:28 -0600 Subject: [PATCH 5/5] Update `gdrive_download()` to use dribble (not path) --- R/board_gdrive.R | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/R/board_gdrive.R b/R/board_gdrive.R index b049e223..539d1dc0 100644 --- a/R/board_gdrive.R +++ b/R/board_gdrive.R @@ -202,7 +202,10 @@ gdrive_file_exists <- function(board, 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