utils::unzip ignores overwrite argument, effectively

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

utils::unzip ignores overwrite argument, effectively

Gábor Csárdi
It does give a warning, but then it overwrites the files, anyway.
Reproducible example below.

This is R 3.4.3, but it does not seem to be fixed in R-devel:
https://github.com/wch/r-source/blob/4a9ca3e5ac6b19d7faa7c9290374f7604bf0ef64/src/main/dounzip.c#L171-L174

FYI,
Gábor

dir.create(tmp <- tempfile())
setwd(tmp)

cat("old1\n", file = "file1")
cat("old2\n", file = "file2")

utils::zip("files.zip", c("file1", "file2"))
#>   adding: file1 (stored 0%)
#>   adding: file2 (stored 0%)

unlink("file2")
cat("new1\n", file = "file1")
readLines("file1")
#> [1] "new1"

utils::unzip("files.zip", overwrite = FALSE)
#> Warning message:
#> In utils::unzip("files.zip", overwrite = FALSE) :
#>    not overwriting file './file1

readLines("file1")
#> [1] "old1"

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel
Reply | Threaded
Open this post in threaded view
|

Re: utils::unzip ignores overwrite argument, effectively

Tomas Kalibera
Thanks, fixed in R-devel.
Tomas

On 12/20/2017 02:38 PM, Gábor Csárdi wrote:

> It does give a warning, but then it overwrites the files, anyway.
> Reproducible example below.
>
> This is R 3.4.3, but it does not seem to be fixed in R-devel:
> https://github.com/wch/r-source/blob/4a9ca3e5ac6b19d7faa7c9290374f7604bf0ef64/src/main/dounzip.c#L171-L174
>
> FYI,
> Gábor
>
> dir.create(tmp <- tempfile())
> setwd(tmp)
>
> cat("old1\n", file = "file1")
> cat("old2\n", file = "file2")
>
> utils::zip("files.zip", c("file1", "file2"))
> #>   adding: file1 (stored 0%)
> #>   adding: file2 (stored 0%)
>
> unlink("file2")
> cat("new1\n", file = "file1")
> readLines("file1")
> #> [1] "new1"
>
> utils::unzip("files.zip", overwrite = FALSE)
> #> Warning message:
> #> In utils::unzip("files.zip", overwrite = FALSE) :
> #>    not overwriting file './file1
>
> readLines("file1")
> #> [1] "old1"
>
> ______________________________________________
> [hidden email] mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel