You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
* Refactor tidy_unzip()
Fixes#1961, closes#1962.
Analyzing the above gave me a new/different understanding of common ZIP file organization structures. I think I've got a better heuristic for setting `exdir`.
* Add NEWS bullet
usethis has an unexported function `tidy_unzip()`, which is used under the hood in `use_course()` and `use_zip()`.
18
+
It is a wrapper around `utils::unzip()` that uses some heuristics to choose a good value for `exdir`, which is the "the directory to extract files to."
19
+
Why do we do this?
20
+
Because it's really easy to _not_ get the desired result when unpacking a ZIP archive.
21
+
22
+
Common aggravations:
23
+
24
+
* Instead of the unpacked files being corraled within a folder, they explode as "loose parts" into the current working directory. Too little nesting.
25
+
* The unpacked files are contained in a folder, but that folder itself is contained inside another folder. Too much nesting.
26
+
27
+
`tidy_unzip()` tries to get the nesting just right.
28
+
29
+
Why doesn't unzipping "just work"?
30
+
Because the people who make `.zip` files make lots of different choices when they actually create the archive and these details aren't baked in, i.e. a successful roundtrip isn't automatic.
31
+
It usually requires some peeking inside the archive and adjusting the unpack options.
32
+
33
+
This README documents specific `.zip` situations that we anticipate.
34
+
35
+
## Explicit parent folder
36
+
37
+
Consider the foo folder:
18
38
19
39
```{bash}
20
40
tree foo
21
41
```
22
42
23
-
### Not Loose Parts, a.k.a. GitHub style
43
+
Zip it up like so:
44
+
45
+
```{bash, eval = FALSE}
46
+
zip -r foo-explicit-parent.zip foo/
47
+
```
48
+
49
+
This is the type of ZIP file that we get from GitHub via links of the forms <https://github.com/r-lib/usethis/archive/main.zip> and <http://github.com/r-lib/usethis/zipball/main/>.
50
+
51
+
Inspect it in the shell:
52
+
53
+
```{bash}
54
+
unzip -Z1 foo-explicit-parent.zip
55
+
```
56
+
57
+
Or from R:
58
+
59
+
```{r}
60
+
foo_files <- unzip("foo-explicit-parent.zip", list = TRUE)
Note that the folder `foo/` is explicitly included and all of the files are contained in it (in this case, just one file).
68
+
69
+
## Implicit parent folder
70
+
71
+
Consider the foo folder:
72
+
73
+
```{bash}
74
+
tree foo
75
+
```
24
76
25
-
This is the structure of ZIP files yielded by GitHub via links of the forms <https://github.com/r-lib/usethis/archive/master.zip> and <http://github.com/r-lib/usethis/zipball/master/>.
77
+
Zip it up like so:
26
78
27
79
```{bash, eval = FALSE}
28
-
zip -r foo-not-loose.zip foo/
80
+
zip -r foo-implicit-parent.zip foo/*
29
81
```
30
82
31
-
Notice that everything is packaged below one top-level directory.
83
+
Note the use of `foo/*`, as opposed to `foo` or `foo/`.
84
+
This type of ZIP file was reported in <https://github.com/r-lib/usethis/issues/1961>.
85
+
The example given there is <https://agdatacommons.nal.usda.gov/ndownloader/files/44576230>.
86
+
87
+
Inspect our small example in the shell:
88
+
89
+
```{bash}
90
+
unzip -Z1 foo-implicit-parent.zip
91
+
```
92
+
93
+
Or from R:
32
94
33
95
```{r}
34
-
foo_not_loose_files <- unzip("foo-not-loose.zip", list = TRUE)
96
+
foo_files <- unzip("foo-implicit-parent.zip", list = TRUE)
All the files are packaged in the ZIP archive as "loose parts", i.e. there is no explicit or implicit top-level directory.
155
+
156
+
## No parent, the DropBox Variation
62
157
63
158
This is the structure of ZIP files yielded by DropBox via links of this form <https://www.dropbox.com/sh/12345abcde/6789wxyz?dl=1>. I can't figure out how to even do this with zip locally, so I had to create an example on DropBox and download it. Jim Hester reports it is possible with `archive::archive_write_files()`.
0 commit comments