Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix how board_gdrive() uses dribble components #782

Merged
merged 5 commits into from
Sep 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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