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

download_hydat() fails to update local hydat copy #180

Closed
gdelaplante opened this issue Aug 31, 2022 · 1 comment · Fixed by #184
Closed

download_hydat() fails to update local hydat copy #180

gdelaplante opened this issue Aug 31, 2022 · 1 comment · Fixed by #184

Comments

@gdelaplante
Copy link
Contributor

gdelaplante commented Aug 31, 2022

Working with a dated local version of hydat and version 0.5.6 of tidyhydat downloaded from CRAN OR from GitHub:

library(tidyhydat)

hy_version()
#Yields 2022-04-18 16:49:45 on my system

download_hydat(ask=FALSE)
#(Printed output)
# ✔ Downloading HYDAT to C:\Users\gtdelapl\AppData\Local\tidyhydat\tidyhydat
# • Downloading HYDAT.sqlite3 to C:\Users\gtdelapl\AppData\Local/tidyhydat/tidyhydat
# • Downloading version of HYDAT created on 2022-07-21
# |=============================================================================================================================================| 100%
# • Extracting HYDAT
# Error in file.rename(list.files(dl_hydat_here, pattern = "\\.sqlite3$",  : 
#                                   'from' and 'to' are of different lengths`

hy_version()
#Again yields 2022-04-18 16:49:45, but should return 2022-07-21

#Check again after downloading from ropensci/tidyhydat main branch:
remotes::install_github("ropensci/tidyhydat")
library(tidyhydat)
hy_version()
download_hydat(ask=FALSE)
#(Printed output)
# • Downloading HYDAT.sqlite3 to C:\Users\gtdelapl\AppData\Local/tidyhydat/tidyhydat
# • Downloading version of HYDAT created on 2022-07-21
# |=============================================================================================================================================| 100%
# • Extracting HYDAT
# Error in file.rename(list.files(dl_hydat_here, pattern = "\\.sqlite3$",  : 
#                                   'from' and 'to' are of different lengths

Downloading works if starting with an empty download directory (...Local/tidyhydat/tidyhydat) but fails again once Hydat.sqlite3 is created again:

#after deleting both files present in /tidyhydat folder:
download_hydat(ask=FALSE)
# • Extracting HYDAT
# ★ HYDAT successfully downloaded

hy_version()
#Yields 2022-07-21, correct.
#Looking in tidyhydat\tidyhydat folder shows only one file, Hydat.sqlite3.

#Downloading again yields the problem as before:
download_hydat(ask=FALSE)
# ✔ Downloading HYDAT to C:\Users\gtdelapl\AppData\Local\tidyhydat\tidyhydat
# • Downloading HYDAT.sqlite3 to C:\Users\gtdelapl\AppData\Local/tidyhydat/tidyhydat
# ✖ The existing local version of hydat, published on 2022-07-21, is the most recent version available.
# |=============================================================================================================================================| 100%
# • Extracting HYDAT
# Error in file.rename(list.files(dl_hydat_here, pattern = "\\.sqlite3$",  : 
#                                   'from' and 'to' are of different lengths

After failure, two files appear in the download directory where there should be one:

  • Hydat.sqlite3
  • Hydat_sqlite3_20220721.sqlite3

The issue evidently stems from lines 112:116 of download.R:

 # rename to consistent name
  file.rename(
    list.files(dl_hydat_here, pattern = "\\.sqlite3$", full.names = TRUE),
    hydat_path
  )

'from' is of length 2 (owing to the two files with .sqlite3 extension) while 'to' is of length one.
This stems from the line above, utils::unzip(tmp, exdir = dl_hydat_here, overwrite = TRUE)), which creates a second file (the new database).

If I get time I'll fix the issue and submit a pull request in the next day or two!

@boshek
Copy link
Collaborator

boshek commented Aug 31, 2022

Yeah I can see the issue. I think a good fix would be to simply ensure that the directory is empty before downloading and then spit out a good error message that you need to move or delete the existing file.

Prior to this we always simply overwrote the previous HYDAT. I think this is still right and that we don't want to preserve old versions of HYDAT on someone's computer but I was to raise that here as well.

To unblock you can of course simply empty the directory in hy_dir() and then run download_hydat() again.

boshek added a commit that referenced this issue Sep 20, 2022
…atabase. (#181)

* Fix file.rename issue with download_hydat, rejig messages and user prompts.

* database file size is fetched from the URL and shown in the user prompt.

* Update R/download.R

Co-authored-by: Sam Albers <[email protected]>

* Update R/download.R

Co-authored-by: Sam Albers <[email protected]>

Co-authored-by: Sam Albers <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants