Skip to content

Commit 93c6a06

Browse files
committed
ignore __MACOSX files when unzipping
1 parent 8148676 commit 93c6a06

File tree

1 file changed

+19
-12
lines changed

1 file changed

+19
-12
lines changed

app/src/processing/app/Util.java

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -614,24 +614,31 @@ static private void packageListFromFolder(File dir, String sofar,
614614
}
615615

616616

617+
/**
618+
* Extract the contents of a .zip archive into a folder.
619+
* Ignores (does not extract) any __MACOSX files from macOS archives.
620+
*/
617621
static public void unzip(File zipFile, File dest) {
618622
try {
619623
FileInputStream fis = new FileInputStream(zipFile);
620624
CheckedInputStream checksum = new CheckedInputStream(fis, new Adler32());
621625
ZipInputStream zis = new ZipInputStream(new BufferedInputStream(checksum));
622-
ZipEntry next = null;
623-
while ((next = zis.getNextEntry()) != null) {
624-
File currentFile = new File(dest, next.getName());
625-
if (next.isDirectory()) {
626-
currentFile.mkdirs();
627-
} else {
628-
File parentDir = currentFile.getParentFile();
629-
// Sometimes the directory entries aren't already created
630-
if (!parentDir.exists()) {
631-
parentDir.mkdirs();
626+
ZipEntry entry = null;
627+
while ((entry = zis.getNextEntry()) != null) {
628+
final String name = entry.getName();
629+
if (!name.startsWith(("__MACOSX"))) {
630+
File currentFile = new File(dest, name);
631+
if (entry.isDirectory()) {
632+
currentFile.mkdirs();
633+
} else {
634+
File parentDir = currentFile.getParentFile();
635+
// Sometimes the directory entries aren't already created
636+
if (!parentDir.exists()) {
637+
parentDir.mkdirs();
638+
}
639+
currentFile.createNewFile();
640+
unzipEntry(zis, currentFile);
632641
}
633-
currentFile.createNewFile();
634-
unzipEntry(zis, currentFile);
635642
}
636643
}
637644
} catch (Exception e) {

0 commit comments

Comments
 (0)