Skip to content

Commit

Permalink
Implement own version of unzip.
Browse files Browse the repository at this point in the history
Closes #540
  • Loading branch information
hadley committed Aug 13, 2014
1 parent 58d5248 commit 1b1732c
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 3 deletions.
3 changes: 3 additions & 0 deletions NEWS.md
Expand Up @@ -84,6 +84,9 @@
parameters `auth_user`, `branch`, `pull` and `password` have all been
removed.

* Implemented own version `utils::unzip()` that throws error if command
fails and doesn't print unneeded messages on non-Windows platforms (#540).

# devtools 1.5

Four new functions make it easier to add useful infrastructure to packages:
Expand Down
17 changes: 15 additions & 2 deletions R/decompress.r
Expand Up @@ -2,7 +2,7 @@ decompress <- function(src, target) {
stopifnot(file.exists(src))

if (grepl("\\.zip$", src)) {
unzip(src, exdir = target, unzip = getOption("unzip"))
my_unzip(src, target)
outdir <- getrootdir(as.vector(unzip(src, list = TRUE)$Name))

} else if (grepl("\\.tar$", src)) {
Expand Down Expand Up @@ -32,8 +32,21 @@ decompress <- function(src, target) {
# getdir("path/to/dir/") returns "path/to/dir"
getdir <- function(path) sub("/[^/]*$", "", path)

# Given a list of files, returns the root (the topmost folder)
# Given a list of files, returns the root (the topmost folder)
# getrootdir(c("path/to/file", "path/to/other/thing")) returns "path/to"
getrootdir <- function(file_list) {
getdir(file_list[which.min(nchar(gsub("[^/]", "", file_list)))])
}

my_unzip <- function(src, target, unzip = getOption("unzip")) {
if (unzip == "internal") {
unzip(src, exdir = target)
}

args <- paste(
"-oq", shQuote(src),
"-d", shQuote(target)
)

system_check(unzip, args, quiet = TRUE)
}
2 changes: 1 addition & 1 deletion R/install-local.r
Expand Up @@ -47,7 +47,7 @@ install_local_single <- function(path, subdir = NULL, before_install = NULL, ...
if (file.exists(config_path)) {
Sys.chmod(config_path, "777")
}

# Call before_install for bundles (if provided)
if (!is.null(bundle) && !is.null(before_install))
before_install(bundle, pkg_path)
Expand Down
2 changes: 2 additions & 0 deletions R/with.r
Expand Up @@ -47,6 +47,8 @@ is.named <- function(x) {
# env ------------------------------------------------------------------------

set_envvar <- function(envs, action = "replace") {
if (length(envs) == 0) return()

stopifnot(is.named(envs))
stopifnot(is.character(action), length(action) == 1)
action <- match.arg(action, c("replace", "prefix", "suffix"))
Expand Down

0 comments on commit 1b1732c

Please sign in to comment.