This is a not too old R-devel on Linux, it already fails in R 3.4.4, and on macOS as well. The tar file seems valid, external tar can untar it, so maybe an untar() bug. setwd(tempdir()) dir.create("pkg") cat("foobar\n", file = file.path("pkg", "NAMESPACE")) cat("this: that\n", file = file.path("pkg", "DESCRIPTION")) tar("pkg_1.0.tar.gz", "pkg", compression = "gzip", tar = "internal") unlink("pkg", recursive = TRUE) con <- file("pkg_1.0.tar.gz", open = "rb") ex <- tempfile() untar(con, files = "pkg/DESCRIPTION", exdir = ex) #> Error in untar2(tarfile, files, list, exdir, restore_times) : #> incomplete block on file
>>>>> G?bor Cs?rdi <csardi.gabor at gmail.com> >>>>> on Tue, 1 May 2018 12:05:32 +0000 writes:> This is a not too old R-devel on Linux, it already fails > in R 3.4.4, and on macOS as well. and fails in considerably older R versions, too. Basically untar() seems to fail on a connection, but works fine on a plain file name. This is a bug --> Thank you for the report, G?bor ! I'm investigating. Martin ----------- my version of your reprex : setwd(tempdir()) dir.create("pkg") cat("this: that\n", file = file.path("pkg", "DESCRIPTION")) tf <- "pkg_1.0.tar.gz" tar(tf, "pkg", compression = "gzip", tar = "internal") unlink("pkg", recursive = TRUE) ## MM: tar *file* is good stopifnot(identical(untar(tf, list=TRUE), "pkg/DESCRIPTION")) untar(tf, files = (f <- "pkg/DESCRIPTION")) # no problem stopifnot(file.exists(f)) unlink("pkg", recursive = TRUE) ## Now with a connection -- "nothing works": con <- file(tf, open = "rb"); try( untar(con, list = TRUE) ) ## -> Error con <- file(tf, open = "rb"); try( untar(con, files = "pkg/DESCRIPTION") ) ## The error message is the same in both cases: ' Error in untar2(tarfile, files, list, exdir, restore_times) : incomplete block on file '
>>>>> Martin Maechler <maechler at stat.math.ethz.ch> >>>>> on Tue, 1 May 2018 16:14:43 +0200 writes:>>>>> G?bor Cs?rdi <csardi.gabor at gmail.com> >>>>> on Tue, 1 May 2018 12:05:32 +0000 writes:>> This is a not too old R-devel on Linux, it already fails >> in R 3.4.4, and on macOS as well. > and fails in considerably older R versions, too. > Basically untar() seems to fail on a connection, but works > fine on a plain file name. Well, there's an easy workaround: If you want to use a connection (instead of a simple filename) with untar() and want to use compression (as in the example), you can currently do that easily when you ensure the connection is a "gzcon" one : ##=========> Workaround for now: ## Create : setwd(tempdir()) ; dir.create("pkg") cat("this: that\n", file = file.path("pkg", "DESCRIPTION")) tf <- "pkg_1.0.tar.gz" tar(tf, "pkg", compression = "gzip", tar = "internal") unlink("pkg", recursive = TRUE) ## As it is a compressed tar file, use it via a gzcon() connection, ## and both cases work fine: con <- gzcon(file(tf, open = "rb")) ; (f <- untar(con, list = TRUE)) ## ~~~~~ con <- gzcon(file(tf, open = "rb")) ; untar(con, files = f) stopifnot(identical(f, "pkg/DESCRIPTION"), file.exists(f)) unlink(c(tf,"pkg"), recursive = TRUE) # clean after me ------------ Of course, ideally untar() should do that for us and I'm testing a simple patch to do that. Martin