Skip to content

Commit

Permalink
Fix how board_gdrive() uses dribble components (#782)
Browse files Browse the repository at this point in the history
* 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)
  • Loading branch information
juliasilge authored Sep 8, 2023
1 parent e70b02e commit bb49622
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 15 deletions.
2 changes: 1 addition & 1 deletion NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
39 changes: 25 additions & 14 deletions R/board_gdrive.R
Original file line number Diff line number Diff line change
Expand Up @@ -66,28 +66,38 @@ 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
}

#' @export
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))
}

Expand Down Expand Up @@ -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
Expand Down

0 comments on commit bb49622

Please sign in to comment.