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

Patch 142 #145

Merged
merged 8 commits into from
Oct 3, 2017
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
29 changes: 23 additions & 6 deletions R/drop_file_ops.R
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,6 @@ drop_delete <-
if (verbose) {
res
} else {
message(sprintf('%s was successfully deleted', res$metadata$path_display))
invisible(res)
}
} else {
Expand Down Expand Up @@ -281,14 +280,32 @@ drop_exists <- function(path = NULL, dtoken = get_dropbox_token()) {
if (!grepl('^/', path))
path <- paste0("/", path)
dir_name <- suppressMessages(dirname(path))
dir_listing <- drop_dir(path = dir_name, dtoken = dtoken)

if (path %in% dir_listing$path_display) {
TRUE
} else {
# In issue #142, this part below (the drop_dir call) fails when drop_dir is
# looking to see if a second level folder exists (when it doesn't.) One safe
# option is to only run drop_dir('/', recursive = TRUE) and then grep through
# that. Downside: It would take forever if this was a really large account.
#
# Other solution is to use purrr::safely to trap the error and return FALSE
# (TODO): Explore uninteded consequence of this.
safe_dir_check <-
purrr::safely(drop_get_metadata, otherwise = FALSE, quiet = TRUE)
dir_listing <- safe_dir_check(path = path, dtoken = dtoken)
# browser()
if (length(dir_listing$result) == 1) {
# This means that object does not exist on Dropbox
FALSE
} else {
# Root of path (dir_name), exists/
paths_only <- dir_listing$result$path_display

if (path %in% paths_only) {
TRUE
} else {
FALSE
}
}


}

#' Checks if an object is a file on Dropbox
Expand Down
2 changes: 1 addition & 1 deletion tests/testthat/test-02_rdrop2-upload.R
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ test_that("Test that basic file ops work correctly", {
server_row_count <- nrow(y)
# Make sure the downloaded csv has the same number of rows
expect_equal(row_count, server_row_count)
expect_message(drop_delete(file_name), "successfully deleted")
unlink(file_name)
drop_delete(file_name)
})

# Test upload of an image
Expand Down
8 changes: 8 additions & 0 deletions tests/testthat/test-07-drop_ops.R
Original file line number Diff line number Diff line change
Expand Up @@ -133,9 +133,17 @@ test_that("drop_exists works correctly", {
skip_on_cran()

folder_name <- traceless("drop_exists")
folder_name2 <- paste0(folder_name, "/", "sub_folder")
drop_create(folder_name)
# This should create a subfolder inside folder_name
drop_create(folder_name2)

# A check on a non existent sub folder should return FALSE
fake_nested_path <- paste0(traceless("foo"), "/", traceless("foo"), "/", traceless("foo"))
expect_false(drop_exists(fake_nested_path))

expect_true(drop_exists(folder_name))
expect_true(drop_exists(folder_name2))
expect_false(drop_exists(traceless("stuffnthings")))

# Now test files inside subfolders
Expand Down