diff --git a/R/utils.R b/R/utils.R index 111133b..a1b6164 100644 --- a/R/utils.R +++ b/R/utils.R @@ -42,28 +42,38 @@ sep <- function() { #' @export tp_fp_fetch <- function() { - if (Sys.info()["sysname"] == "Windows") { - # no self container for Windows, need to install it manually - 0.0 + + # get repo info + repo_info <- gh::gh("GET /repos/treeppl/treeppl/releases") + # Check for Linux + if (Sys.info()["sysname"] == "Linux" | Sys.info()["sysname"] == "Windows") { + # assets[[2]] because releases are in alphabetical order (1 = Mac, 2 = Linux) + asset <- repo_info[[1]]$assets[[2]] + folder_name <- "treeppl-linux" } else { - # get repo info - repo_info <- gh::gh("GET /repos/treeppl/treeppl/releases") - # Check for Linux - if (Sys.info()["sysname"] == "Linux") { - # assets[[2]] because releases are in alphabetical order (1 = Mac, 2 = Linux) - asset <- repo_info[[1]]$assets[[2]] - folder_name <- "treeppl-linux" - } else { - asset <- repo_info[[1]]$assets[[1]] - folder_name <- "treeppl-mac" - } + asset <- repo_info[[1]]$assets[[1]] + folder_name <- "treeppl-mac" + } - # online hash - online_hash <- asset$digest - # local hash - file_name <- list.files(path = system.file(folder_name, package = "treepplr"), full.names = TRUE) - # download file if file_name is empty - if (length(file_name) == 0) { + # online hash + online_hash <- asset$digest + # local hash + file_name <- list.files(path = system.file(folder_name, package = "treepplr"), full.names = TRUE) + # download file if file_name is empty + if (length(file_name) == 0) { + # download + fn <- paste(system.file(folder_name, package = "treepplr"), asset$name, sep = "/") + curl::curl_download( + asset$browser_download_url, + destfile = fn, + quiet = FALSE + ) + } else { + local_hash <- paste0("sha256:", cli::hash_file_sha256(file_name)) + # compare local and online hash and download the file if they differ + if (!identical(local_hash, online_hash)) { + # remove old file + file.remove(file_name) # download fn <- paste(system.file(folder_name, package = "treepplr"), asset$name, sep = "/") curl::curl_download( @@ -71,20 +81,6 @@ tp_fp_fetch <- function() { destfile = fn, quiet = FALSE ) - } else { - local_hash <- paste0("sha256:", cli::hash_file_sha256(file_name)) - # compare local and online hash and download the file if they differ - if (!identical(local_hash, online_hash)) { - # remove old file - file.remove(file_name) - # download - fn <- paste(system.file(folder_name, package = "treepplr"), asset$name, sep = "/") - curl::curl_download( - asset$browser_download_url, - destfile = fn, - quiet = FALSE - ) - } } } repo_info[[1]]$tag_name @@ -93,10 +89,7 @@ tp_fp_fetch <- function() { # Platform-dependent treeppl self contain installation installing_treeppl <- function() { tag <- tp_fp_fetch() - if (Sys.info()['sysname'] == "Windows") { - # No self container for Windows, need to install it manually - "tpplc" - } else if(Sys.info()['sysname'] == "Linux") { + if(Sys.info()['sysname'] == "Linux" | Sys.info()['sysname'] == "Windows") { path <- system.file("treeppl-linux", package = "treepplr") file_name <- paste0("treeppl-",substring(tag, 2)) } else {#Mac OS have a lot of different name