Skip to content
Closed
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
69 changes: 31 additions & 38 deletions R/utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -42,49 +42,45 @@ 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(
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(
asset$browser_download_url,
destfile = fn,
quiet = FALSE
)
}
}
}
repo_info[[1]]$tag_name
Expand All @@ -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
Expand Down