Skip to content

Commit 73a7c58

Browse files
committed
The condition !file.exists(file_path) !! isTRUE(force_download) will always be TRUE whenever the previous if clause (which terminates with a return()) is false, so it should be useless
1 parent 95c9d85 commit 73a7c58

File tree

1 file changed

+61
-62
lines changed

1 file changed

+61
-62
lines changed

R/download.R

Lines changed: 61 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -103,77 +103,76 @@ oe_download = function(
103103
return(file_path)
104104
}
105105

106-
if (!file.exists(file_path) || isTRUE(force_download)) {
107-
continue = 1L
108-
if (
109-
interactive() &&
110-
!is.null(file_size) &&
111-
!is.na(file_size) &&
112-
file_size >= max_file_size
113-
) { # nocov start
114-
oe_message(
115-
"You are trying to download a file from ", file_url, ". ",
116-
"This is a large file (", round(file_size / 1048576), " MB)!",
117-
quiet = FALSE,
118-
.subclass = "oe_download_LargeFile"
119-
)
120-
continue = utils::menu(
121-
choices = c("Yes", "No"),
122-
title = "Are you sure that you want to download it?"
123-
)
124-
125-
# It think it's always useful to see the progress bar for large files
126-
quiet = FALSE
127-
} # nocov end
128-
129-
if (continue != 1L) {
130-
oe_stop(
131-
.subclass = "oe_download_AbortedByUser",
132-
message = "Aborted by user"
133-
)
134-
}
135106

107+
continue = 1L
108+
if (
109+
interactive() &&
110+
!is.null(file_size) &&
111+
!is.na(file_size) &&
112+
file_size >= max_file_size
113+
) { # nocov start
136114
oe_message(
137-
"Downloading the OSM extract:",
138-
quiet = quiet,
139-
.subclass = "oe_download_StartDownloading"
115+
"You are trying to download a file from ", file_url, ". ",
116+
"This is a large file (", round(file_size / 1048576), " MB)!",
117+
quiet = FALSE,
118+
.subclass = "oe_download_LargeFile"
140119
)
141-
142-
resp = tryCatch(
143-
expr = {
144-
httr::GET(
145-
url = file_url,
146-
if (isFALSE(quiet)) httr::progress(),
147-
# if (isFALSE(quiet)) httr::verbose(),
148-
httr::write_disk(file_path, overwrite = TRUE),
149-
httr::timeout(max(300L, getOption("timeout")))
150-
)
151-
},
152-
error = function(e) {
153-
oe_stop(
154-
.subclass = "oe_download_DownloadAborted",
155-
message = paste0(
156-
"The download operation was aborted. ",
157-
"If this was not intentional, you may want to increase the timeout for internet operations ",
158-
"to a value >= 300 by using options(timeout = ...) before re-running this function. ",
159-
"We also suggest you to remove the partially downloaded file by running the ",
160-
"following code (possibly in a new R session): ",
161-
# NB: Don't add a full stop since that makes copying code really annoying
162-
"file.remove(", dQuote(file_path, q = FALSE), ")"
163-
)
164-
)
165-
}
120+
continue = utils::menu(
121+
choices = c("Yes", "No"),
122+
title = "Are you sure that you want to download it?"
166123
)
167124

168-
httr::stop_for_status(resp, "download data from the provider")
125+
# It think it's always useful to see the progress bar for large files
126+
quiet = FALSE
127+
} # nocov end
169128

170-
oe_message(
171-
"File downloaded!",
172-
quiet = quiet,
173-
.subclass = "oe_download_FileDownloaded"
129+
if (continue != 1L) {
130+
oe_stop(
131+
.subclass = "oe_download_AbortedByUser",
132+
message = "Aborted by user"
174133
)
175134
}
176135

136+
oe_message(
137+
"Downloading the OSM extract:",
138+
quiet = quiet,
139+
.subclass = "oe_download_StartDownloading"
140+
)
141+
142+
resp = tryCatch(
143+
expr = {
144+
httr::GET(
145+
url = file_url,
146+
if (isFALSE(quiet)) httr::progress(),
147+
# if (isFALSE(quiet)) httr::verbose(),
148+
httr::write_disk(file_path, overwrite = TRUE),
149+
httr::timeout(max(300L, getOption("timeout")))
150+
)
151+
},
152+
error = function(e) {
153+
oe_stop(
154+
.subclass = "oe_download_DownloadAborted",
155+
message = paste0(
156+
"The download operation was aborted. ",
157+
"If this was not intentional, you may want to increase the timeout for internet operations ",
158+
"to a value >= 300 by using options(timeout = ...) before re-running this function. ",
159+
"We also suggest you to remove the partially downloaded file by running the ",
160+
"following code (possibly in a new R session): ",
161+
# NB: Don't add a full stop since that makes copying code really annoying
162+
"file.remove(", dQuote(file_path, q = FALSE), ")"
163+
)
164+
)
165+
}
166+
)
167+
168+
httr::stop_for_status(resp, "download data from the provider")
169+
170+
oe_message(
171+
"File downloaded!",
172+
quiet = quiet,
173+
.subclass = "oe_download_FileDownloaded"
174+
)
175+
177176
file_path
178177
}
179178

0 commit comments

Comments
 (0)