diff --git a/R/RcppExports.R b/R/RcppExports.R index 8efd9f9..0f0fa1a 100644 --- a/R/RcppExports.R +++ b/R/RcppExports.R @@ -28,3 +28,7 @@ incant <- function(path, magic_db = "system") { .Call('wand_incant', PACKAGE = 'wand', path, magic_db) } +lib_version <- function() { + .Call('wand_lib_version', PACKAGE = 'wand') +} + diff --git a/R/zzz.r b/R/zzz.r index 5d477fa..4d12342 100644 --- a/R/zzz.r +++ b/R/zzz.r @@ -26,8 +26,10 @@ magic_wand_file <- function(force=FALSE) { if (!dir.exists(cache)) dir.create(cache, showWarnings=FALSE) if (!dir.exists(cache)) return("system") + if (lib_version() >= 528) vers <- "new" else vers <- "old" + if (!file.exists(file.path(rappdirs::user_cache_dir("wandr"), "magic.mgc"))) { - suppressWarnings(unzip(system.file("magic.mgc.zip", package="wand"), + suppressWarnings(unzip(system.file("db", vers, "magic.mgc.zip", package="wand"), exdir=cache, overwrite=force)) } diff --git a/inst/magic.mgc.zip b/inst/db/new/magic.mgc.zip similarity index 100% rename from inst/magic.mgc.zip rename to inst/db/new/magic.mgc.zip diff --git a/inst/db/old/magic.mgc.zip b/inst/db/old/magic.mgc.zip new file mode 100644 index 0000000..7add8a4 Binary files /dev/null and b/inst/db/old/magic.mgc.zip differ diff --git a/man/incant.Rd b/man/incant.Rd index f7a4a83..1868be8 100644 --- a/man/incant.Rd +++ b/man/incant.Rd @@ -22,6 +22,10 @@ a \code{tibble} / \code{data.frame} of file magic attributes. \description{ Retrieve 'magic' attributes from files and directories } +\note{ +Various fields might not be available depending on the version + of \code{libmagic} you have installed. +} \examples{ library(magrittr) library(dplyr) diff --git a/man/magic_wand_file.Rd b/man/magic_wand_file.Rd index 19798ec..608e3de 100644 --- a/man/magic_wand_file.Rd +++ b/man/magic_wand_file.Rd @@ -20,8 +20,6 @@ perform the decompression unless \code{force} is \code{TRUE} or the cache directory has been cleared. } \examples{ -library(magrittr) -library(dplyr) system.file("img", package="filemagic") \%>\% list.files(full.names=TRUE) \%>\% diff --git a/src/RcppExports.cpp b/src/RcppExports.cpp index 3e952c1..3327aa4 100644 --- a/src/RcppExports.cpp +++ b/src/RcppExports.cpp @@ -17,3 +17,13 @@ BEGIN_RCPP return __result; END_RCPP } +// lib_version +int lib_version(); +RcppExport SEXP wand_lib_version() { +BEGIN_RCPP + Rcpp::RObject __result; + Rcpp::RNGScope __rngScope; + __result = Rcpp::wrap(lib_version()); + return __result; +END_RCPP +} diff --git a/src/wand.cpp b/src/wand.cpp index 2485f5e..5c68e42 100644 --- a/src/wand.cpp +++ b/src/wand.cpp @@ -145,3 +145,6 @@ DataFrame incant(CharacterVector path, std::string magic_db="system") { return(df); } + +// [[Rcpp::export]] +int lib_version() { return(magic_version()); }