Skip to content

Commit b272c12

Browse files
committed
Add support for symbolic links in ZIP file resource collections
1 parent 356473d commit b272c12

File tree

3 files changed

+58
-1
lines changed

3 files changed

+58
-1
lines changed

src/main/java/org/codehaus/plexus/archiver/zip/PlexusArchiverZipFileResourceCollection.java

+3-1
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,9 @@ public PlexusIoResource next()
5757
{
5858
final ZipArchiveEntry entry = (ZipArchiveEntry) en.nextElement();
5959

60-
return new ZipResource( zipFile, entry, getStreamTransformer() );
60+
return !entry.isUnixSymlink()
61+
? new ZipResource( zipFile, entry, getStreamTransformer() )
62+
: new ZipSymlinkResource( zipFile, entry, getStreamTransformer() );
6163
}
6264

6365
public void remove()
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
package org.codehaus.plexus.archiver.zip;
2+
3+
import java.io.IOException;
4+
5+
import org.apache.commons.compress.archivers.zip.ZipArchiveEntry;
6+
import org.apache.commons.compress.archivers.zip.ZipFile;
7+
import org.codehaus.plexus.components.io.functions.InputStreamTransformer;
8+
import org.codehaus.plexus.components.io.functions.SymlinkDestinationSupplier;
9+
10+
/**
11+
* A {@link ZipResource} that represents symbolic link.
12+
*/
13+
public class ZipSymlinkResource
14+
extends ZipResource
15+
implements SymlinkDestinationSupplier
16+
{
17+
private final String symlinkDestination;
18+
19+
public ZipSymlinkResource(ZipFile zipFile, ZipArchiveEntry entry, InputStreamTransformer streamTransformer)
20+
{
21+
super(zipFile, entry, streamTransformer);
22+
try {
23+
symlinkDestination = zipFile.getUnixSymlink(entry);
24+
} catch (IOException e) {
25+
throw new RuntimeException(e);
26+
}
27+
}
28+
29+
@Override
30+
public String getSymlinkDestination() throws IOException
31+
{
32+
return symlinkDestination;
33+
}
34+
35+
@Override
36+
public boolean isSymbolicLink()
37+
{
38+
return true;
39+
}
40+
41+
}

src/test/java/org/codehaus/plexus/archiver/zip/ZipArchiverTest.java

+14
Original file line numberDiff line numberDiff line change
@@ -533,6 +533,20 @@ public void testSymlinkFileSet()
533533
assertTrue( fa.isSymbolicLink() );
534534
}
535535

536+
public void testSymlinkArchivedFileSet()
537+
throws Exception
538+
{
539+
final File zipFile = getTestFile( "src/test/resources/symlinks/symlinks.zip" );
540+
final File zipFile2 = getTestFile( "target/output/pasymlinks-archivedFileset.zip" );
541+
final ZipArchiver zipArchiver = getZipArchiver( zipFile2 );
542+
zipArchiver.addArchivedFileSet( zipFile );
543+
zipArchiver.createArchive();
544+
545+
final ZipFile cmp1 = new ZipFile( zipFile );
546+
final ZipFile cmp2 = new ZipFile( zipFile2 );
547+
ArchiveFileComparator.assertEquals( cmp1, cmp2, "" );
548+
}
549+
536550
/*
537551
*/
538552

0 commit comments

Comments
 (0)