1919
2020/*
2121 * Copyright (c) 2008, 2018, Oracle and/or its affiliates. All rights reserved.
22+ * Portions Copyright (c) 2019, Chris Fraire <cfraire@me.com>.
2223 */
2324package org .opengrok .indexer .util ;
2425
2728import java .io .IOException ;
2829import java .io .InputStream ;
2930import java .io .OutputStream ;
31+ import java .nio .file .Files ;
3032import java .util .Enumeration ;
3133import java .util .List ;
32- import java .util .zip .ZipEntry ;
33- import java .util .zip .ZipFile ;
34+
35+ import org .apache .commons .compress .archivers .zip .ZipArchiveEntry ;
36+ import org .apache .commons .compress .archivers .zip .ZipFile ;
3437import org .opengrok .indexer .configuration .RuntimeEnvironment ;
3538import org .opengrok .indexer .index .IgnoredNames ;
3639
@@ -46,12 +49,26 @@ public class FileUtilities {
4649 public static void extractArchive (File sourceBundle , File root ) throws IOException {
4750 ZipFile zipfile = new ZipFile (sourceBundle );
4851
49- Enumeration <? extends ZipEntry > e = zipfile .entries ();
52+ Enumeration <ZipArchiveEntry > e = zipfile .getEntries ();
5053
5154 while (e .hasMoreElements ()) {
52- ZipEntry ze = e .nextElement ();
55+ ZipArchiveEntry ze = e .nextElement ();
5356 File file = new File (root , ze .getName ());
54- if (ze .isDirectory ()) {
57+ if (ze .isUnixSymlink ()) {
58+ File target = new File (file .getParent (), zipfile .getUnixSymlink (ze ));
59+ /*
60+ * A weirdness is that an object may already have been exploded
61+ * before the symlink entry is reached in the ZipFile. So
62+ * unlink any existing entry to avoid an exception on creating
63+ * the symlink.
64+ */
65+ if (file .isDirectory ()) {
66+ removeDirs (file );
67+ } else if (file .exists ()) {
68+ file .delete ();
69+ }
70+ Files .createSymbolicLink (file .toPath (), target .toPath ());
71+ } else if (ze .isDirectory ()) {
5572 file .mkdirs ();
5673 } else {
5774 try (InputStream in = zipfile .getInputStream (ze ); OutputStream out = new FileOutputStream (file )) {
0 commit comments