19
19
20
20
/*
21
21
* Copyright (c) 2008, 2018, Oracle and/or its affiliates. All rights reserved.
22
+ * Portions Copyright (c) 2019, Chris Fraire <[email protected] >.
22
23
*/
23
24
package org .opengrok .indexer .util ;
24
25
27
28
import java .io .IOException ;
28
29
import java .io .InputStream ;
29
30
import java .io .OutputStream ;
31
+ import java .nio .file .Files ;
30
32
import java .util .Enumeration ;
31
33
import 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 ;
34
37
import org .opengrok .indexer .configuration .RuntimeEnvironment ;
35
38
import org .opengrok .indexer .index .IgnoredNames ;
36
39
@@ -46,12 +49,26 @@ public class FileUtilities {
46
49
public static void extractArchive (File sourceBundle , File root ) throws IOException {
47
50
ZipFile zipfile = new ZipFile (sourceBundle );
48
51
49
- Enumeration <? extends ZipEntry > e = zipfile .entries ();
52
+ Enumeration <ZipArchiveEntry > e = zipfile .getEntries ();
50
53
51
54
while (e .hasMoreElements ()) {
52
- ZipEntry ze = e .nextElement ();
55
+ ZipArchiveEntry ze = e .nextElement ();
53
56
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 ()) {
55
72
file .mkdirs ();
56
73
} else {
57
74
try (InputStream in = zipfile .getInputStream (ze ); OutputStream out = new FileOutputStream (file )) {
0 commit comments