Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix symbolic links not properly encoded in ZIP archives #73

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import java.io.InputStream;
import java.io.OutputStream;
import java.io.SequenceInputStream;
import java.nio.ByteBuffer;
import java.nio.charset.Charset;
import java.util.Hashtable;
import java.util.Stack;
Expand Down Expand Up @@ -502,8 +503,7 @@ protected void zipFile( InputStreamSupplier in, ConcurrentJarCreator zOut, Strin
InputStream payload;
if ( ze.isUnixSymlink() )
{
ZipEncoding enc = ZipEncodingHelper.getZipEncoding( getEncoding() );
final byte[] bytes = enc.encode( symlinkDestination ).array();
final byte[] bytes = encodeArchiveEntry( symlinkDestination, getEncoding() );
payload = new ByteArrayInputStream( bytes );
zOut.addArchiveEntry( ze, createInputStreamSupplier( payload ), true );
}
Expand Down Expand Up @@ -644,14 +644,24 @@ protected void zipDir( PlexusIoResource dir, ConcurrentJarCreator zOut, String v
else
{
String symlinkDestination = ( (SymlinkDestinationSupplier) dir ).getSymlinkDestination();
ZipEncoding enc = ZipEncodingHelper.getZipEncoding( encodingToUse );
final byte[] bytes = enc.encode( symlinkDestination ).array();
final byte[] bytes = encodeArchiveEntry( symlinkDestination, encodingToUse );
ze.setMethod( ZipArchiveEntry.DEFLATED );
zOut.addArchiveEntry( ze, createInputStreamSupplier( new ByteArrayInputStream( bytes ) ), true );
}
}
}

private byte[] encodeArchiveEntry( String payload, String encoding )
throws IOException
{
ZipEncoding enc = ZipEncodingHelper.getZipEncoding( encoding );
ByteBuffer encodedPayloadByteBuffer = enc.encode( payload );
byte[] encodedPayloadBytes = new byte[encodedPayloadByteBuffer.limit()];
encodedPayloadByteBuffer.get( encodedPayloadBytes );

return encodedPayloadBytes;
}

protected InputStreamSupplier createInputStreamSupplier( final InputStream inputStream )
{
return new InputStreamSupplier()
Expand Down