Skip to content

Commit 8cf84bd

Browse files
detulesimonpcouch
andauthored
utils: prefer shlib when looking through unixodbc installations (#921)
* utils: prefer shlib when looking through unixodbc installations * code-review: combine common usage pattern * tests: Skip new test on windows * tests: remove new test --------- Co-authored-by: Simon P. Couch <[email protected]>
1 parent 258b74a commit 8cf84bd

File tree

1 file changed

+20
-19
lines changed

1 file changed

+20
-19
lines changed

R/utils.R

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -349,7 +349,7 @@ configure_simba <- function(driver_config,
349349
call = call
350350
)
351351
}
352-
configure_unixodbc_simba(unixodbc_install[1], simba_config[1], action, call)
352+
configure_unixodbc_simba(unixodbc_install, simba_config[1], action, call)
353353
}
354354

355355
locate_install_unixodbc <- function() {
@@ -375,38 +375,39 @@ locate_install_unixodbc <- function() {
375375
"/opt/R/x86_64/lib"
376376
)
377377

378-
list.files(
379-
common_dirs,
380-
pattern = libodbcinst_filename(),
381-
full.names = TRUE
382-
)
378+
return(libodbcinst_file(common_dirs))
383379
}
384380

385381
system_safely <- function(x) {
386382
tryCatch(
387383
{
388384
unixodbc_prefix <- system(x, intern = TRUE, ignore.stderr = TRUE)
389-
candidates <- list.files(unixodbc_prefix,
390-
pattern = libodbcinst_filename(), full.names = TRUE)
391-
if (!length(candidates)) {
392-
stop("Unable to locate unixodbc using odbc_config")
393-
}
394-
return(candidates[1])
385+
return(libodbcinst_file(unixodbc_prefix))
395386
},
396387
error = function(e) {},
397388
warning = function(w) {}
398389
)
399390
character()
400391
}
401392

402-
# Returns a pattern to be used with
403-
# list.files( ..., pattern = ... ).
404-
libodbcinst_filename <- function() {
405-
if (is_macos()) {
406-
"libodbcinst.dylib|libodbcinst.a"
407-
} else {
408-
"libodbcinst.so|libodbcinst.a"
393+
# Search for an instance of the unixodbc lib in
394+
# the directories passed in the `dirs` argument.
395+
# Preference is given to shared libraries.
396+
libodbcinst_file <- function(dirs) {
397+
if (is_windows()) {
398+
return(character())
399+
}
400+
# Order matters, we prefer shlib (#919)
401+
file_names <- ifelse(is_macos(), "libodbcinst.dylib", "libodbcinst.so")
402+
file_names <- c(file_names, "libodbcinst.a")
403+
for (file_name in file_names) {
404+
candidates <- list.files(dirs,
405+
pattern = file_name, full.names = TRUE)
406+
if (length(candidates)) {
407+
return(candidates[1])
408+
}
409409
}
410+
return(character())
410411
}
411412

412413
error_install_unixodbc <- function(call) {

0 commit comments

Comments
 (0)