Skip to content

Commit 8ba3bf8

Browse files
committed
Handle symlinks in extractArchive()
1 parent 0e0ac58 commit 8ba3bf8

File tree

2 files changed

+28
-6
lines changed

2 files changed

+28
-6
lines changed

opengrok-indexer/pom.xml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ information: Portions Copyright [yyyy] [name of copyright owner]
1919
CDDL HEADER END
2020
2121
Copyright (c) 2010, 2018, Oracle and/or its affiliates. All rights reserved.
22-
Portions Copyright (c) 2017-2018, Chris Fraire <[email protected]>.
22+
Portions Copyright (c) 2017-2019, Chris Fraire <[email protected]>.
2323
2424
-->
2525
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
@@ -51,6 +51,11 @@ Portions Copyright (c) 2017-2018, Chris Fraire <[email protected]>.
5151
<artifactId>commons-lang3</artifactId>
5252
<version>${apache-commons-lang3.version}</version>
5353
</dependency>
54+
<dependency>
55+
<groupId>org.apache.commons</groupId>
56+
<artifactId>commons-compress</artifactId>
57+
<version>1.19</version>
58+
</dependency>
5459
<dependency>
5560
<groupId>org.apache.lucene</groupId>
5661
<artifactId>lucene-core</artifactId>

opengrok-indexer/src/test/java/org/opengrok/indexer/util/FileUtilities.java

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020
/*
2121
* Copyright (c) 2008, 2018, Oracle and/or its affiliates. All rights reserved.
22+
* Portions Copyright (c) 2019, Chris Fraire <[email protected]>.
2223
*/
2324
package org.opengrok.indexer.util;
2425

@@ -27,10 +28,12 @@
2728
import java.io.IOException;
2829
import java.io.InputStream;
2930
import java.io.OutputStream;
31+
import java.nio.file.Files;
3032
import java.util.Enumeration;
3133
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;
3437
import org.opengrok.indexer.configuration.RuntimeEnvironment;
3538
import 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

Comments
 (0)