[plexus-archiver] Add patch for extracting symbolic links

Mikolaj Izdebski mizdebsk at fedoraproject.org
Thu Sep 4 04:18:13 UTC 2014


commit 06ee4bbd462351b8e728e81c6a36bad8d4ac8893
Author: Mikolaj Izdebski <mizdebsk at redhat.com>
Date:   Thu Sep 4 06:09:04 2014 +0200

    Add patch for extracting symbolic links

 0001-Fix-PLXCOMP-113-and-PLXCOMP-64.patch |  197 +++++++++++++++++++++++++++++
 plexus-archiver.spec                      |   44 ++-----
 2 files changed, 207 insertions(+), 34 deletions(-)
---
diff --git a/0001-Fix-PLXCOMP-113-and-PLXCOMP-64.patch b/0001-Fix-PLXCOMP-113-and-PLXCOMP-64.patch
new file mode 100644
index 0000000..df15619
--- /dev/null
+++ b/0001-Fix-PLXCOMP-113-and-PLXCOMP-64.patch
@@ -0,0 +1,197 @@
+From cf249e1a6a167689b685bbb89650345d1ed42977 Mon Sep 17 00:00:00 2001
+From: Roland Grunberg <rgrunber at redhat.com>
+Date: Mon, 25 Aug 2014 10:45:11 -0400
+Subject: [PATCH] Fix PLXCOMP-113 and PLXCOMP-64.
+
+Zip and Tar Unarchivers should support POSIX symbolic links.
+---
+ .../org/codehaus/plexus/archiver/tar/TarEntry.java | 11 +++++
+ .../plexus/archiver/tar/TarUnArchiver.java         |  2 +-
+ .../plexus/archiver/zip/AbstractZipUnArchiver.java | 57 +++++++++++++++-------
+ .../org/codehaus/plexus/archiver/zip/ZipEntry.java |  9 ++++
+ 4 files changed, 61 insertions(+), 18 deletions(-)
+
+diff --git a/src/main/java/org/codehaus/plexus/archiver/tar/TarEntry.java b/src/main/java/org/codehaus/plexus/archiver/tar/TarEntry.java
+index 78156e4..8792ff7 100644
+--- a/src/main/java/org/codehaus/plexus/archiver/tar/TarEntry.java
++++ b/src/main/java/org/codehaus/plexus/archiver/tar/TarEntry.java
+@@ -636,6 +636,17 @@ public class TarEntry
+     }
+ 
+     /**
++     * Return whether or not this entry represents a symbolic link.
++     *
++     * @return True if this entry is a symbolic link.
++     * @since 2.4.5
++     */
++    public boolean isSymbolicLink()
++    {
++        return this.linkFlag == LF_SYMLINK;
++    }
++
++    /**
+      * If this entry represents a file, and the file is a directory, return
+      * an array of TarEntries for this entry's children.
+      *
+diff --git a/src/main/java/org/codehaus/plexus/archiver/tar/TarUnArchiver.java b/src/main/java/org/codehaus/plexus/archiver/tar/TarUnArchiver.java
+index 3933ce1..16d1cbf 100644
+--- a/src/main/java/org/codehaus/plexus/archiver/tar/TarUnArchiver.java
++++ b/src/main/java/org/codehaus/plexus/archiver/tar/TarUnArchiver.java
+@@ -91,7 +91,7 @@ public class TarUnArchiver
+             while ( ( te = tis.getNextEntry() ) != null )
+             {
+                 extractFile( getSourceFile(), getDestDirectory(), tis, te.getName(), te.getModTime(),
+-                             te.isDirectory(), te.getMode() != 0 ? te.getMode() : null);
++                             te.isDirectory(), te.getMode() != 0 ? te.getMode() : null, te.isSymbolicLink(), te.getLinkName());
+             }
+             getLogger().debug( "expand complete" );
+ 
+diff --git a/src/main/java/org/codehaus/plexus/archiver/zip/AbstractZipUnArchiver.java b/src/main/java/org/codehaus/plexus/archiver/zip/AbstractZipUnArchiver.java
+index fb8759e..0e4c54c 100644
+--- a/src/main/java/org/codehaus/plexus/archiver/zip/AbstractZipUnArchiver.java
++++ b/src/main/java/org/codehaus/plexus/archiver/zip/AbstractZipUnArchiver.java
+@@ -17,15 +17,21 @@ package org.codehaus.plexus.archiver.zip;
+  *  limitations under the License.
+  */
+ 
++import java.io.BufferedReader;
+ import java.io.File;
+ import java.io.FileNotFoundException;
+ import java.io.FileOutputStream;
+ import java.io.IOException;
+ import java.io.InputStream;
++import java.io.InputStreamReader;
+ import java.io.OutputStream;
+ import java.net.URL;
++import java.nio.file.Files;
++import java.nio.file.Path;
++import java.nio.file.Paths;
+ import java.util.Date;
+ import java.util.Enumeration;
++
+ import org.codehaus.plexus.archiver.AbstractUnArchiver;
+ import org.codehaus.plexus.archiver.ArchiveFilterException;
+ import org.codehaus.plexus.archiver.ArchiverException;
+@@ -97,7 +103,6 @@ public abstract class AbstractZipUnArchiver
+         {
+             return !zipEntry.isDirectory();
+         }
+-
+         public InputStream getContents()
+             throws IOException
+         {
+@@ -147,7 +152,7 @@ public abstract class AbstractZipUnArchiver
+                 }
+                 InputStream in = zf.getInputStream( ze );
+                 extractFileIfIncluded( getSourceFile(), getDestDirectory(), in, ze.getName(),
+-                                       new Date( ze.getTime() ), ze.isDirectory(), ze.getUnixMode()!= 0 ? ze.getUnixMode() : null );
++                                       new Date( ze.getTime() ), ze.isDirectory(), ze.getUnixMode()!= 0 ? ze.getUnixMode() : null, ze.isSymbolicLink(), null );
+                 in.close();
+             }
+ 
+@@ -175,14 +180,14 @@ public abstract class AbstractZipUnArchiver
+ 
+     private void extractFileIfIncluded( final File sourceFile, final File destDirectory, final InputStream inputStream,
+                                         final String name, final Date time, final boolean isDirectory,
+-                                        final Integer mode )
++                                        final Integer mode, boolean isSymlink, String linkName )
+         throws IOException, ArchiverException
+     {
+         try
+         {
+             if ( include( inputStream, name ) )
+             {
+-                extractFile( sourceFile, destDirectory, inputStream, name, time, isDirectory, mode );
++                extractFile( sourceFile, destDirectory, inputStream, name, time, isDirectory, mode, isSymlink, linkName );
+             }
+         }
+         catch ( final ArchiveFilterException e )
+@@ -193,7 +198,7 @@ public abstract class AbstractZipUnArchiver
+ 
+     protected void extractFile( final File srcF, final File dir, final InputStream compressedInputStream,
+                                 final String entryName, final Date entryDate, final boolean isDirectory,
+-                                final Integer mode )
++                                final Integer mode, boolean isSymlink, String linkName )
+         throws IOException, ArchiverException
+     {
+         final File f = FileUtils.resolveFile( dir, entryName );
+@@ -218,18 +223,36 @@ public abstract class AbstractZipUnArchiver
+             }
+             else
+             {
+-                OutputStream out = null;
+-                try
+-                {
+-                    out = new FileOutputStream( f );
+-
+-                    IOUtil.copy( compressedInputStream, out );
+-                }
+-                finally
+-                {
+-                    IOUtil.close( out );
++                if ( isSymlink ) {
++                    BufferedReader buff = null;
++                    Path path;
++                    if ( linkName != null ) {
++                        path = Paths.get( linkName );
++                    } else {
++                        try {
++                            buff = new BufferedReader( new InputStreamReader( compressedInputStream ) );
++                            String value = buff.readLine();
++                            path = Paths.get( value );
++                        }
++                        finally
++                        {
++                            IOUtil.close( buff );
++                        }
++                    }
++                    Files.createSymbolicLink( f.toPath(), path );
++                } else {
++                    OutputStream out = null;
++                    try {
++                        out = new FileOutputStream( f );
++
++                        IOUtil.copy( compressedInputStream, out );
++                    }
++                    finally
++                    {
++                        IOUtil.close( out );
++                    }
+                 }
+-            }
++			}
+ 
+             f.setLastModified( entryDate.getTime() );
+ 
+@@ -269,7 +292,7 @@ public abstract class AbstractZipUnArchiver
+                     final InputStream inputStream = zipFile.getInputStream( ze );
+                     extractFileIfIncluded( getSourceFile(), outputDirectory, inputStream,
+                                            ze.getName(), new Date( ze.getTime() ), ze.isDirectory(),
+-                                           ze.getUnixMode() != 0 ? ze.getUnixMode() : null );
++                                           ze.getUnixMode() != 0 ? ze.getUnixMode() : null, ze.isSymbolicLink(), null );
+                     inputStream.close();
+                 }
+             }
+diff --git a/src/main/java/org/codehaus/plexus/archiver/zip/ZipEntry.java b/src/main/java/org/codehaus/plexus/archiver/zip/ZipEntry.java
+index 6c00720..9ec7273 100644
+--- a/src/main/java/org/codehaus/plexus/archiver/zip/ZipEntry.java
++++ b/src/main/java/org/codehaus/plexus/archiver/zip/ZipEntry.java
+@@ -416,6 +416,15 @@ public class ZipEntry
+         return getName().endsWith( "/" );
+     }
+ 
++    /**
++     * @since 2.4.5
++     */
++    public boolean isSymbolicLink()
++    {
++        // From POSIX spec for <sys/stat.h>
++        return (getUnixMode() & 0170000) == 0120000;
++    }
++
+     protected void setName( String name )
+     {
+         this.name = name;
+-- 
+1.9.3
+
diff --git a/plexus-archiver.spec b/plexus-archiver.spec
index befb89e..d4a7269 100644
--- a/plexus-archiver.spec
+++ b/plexus-archiver.spec
@@ -1,44 +1,17 @@
-# Copyright (c) 2000-2005, JPackage Project
-# All rights reserved.
-#
-# Redistribution and use in source and binary forms, with or without
-# modification, are permitted provided that the following conditions
-# are met:
-#
-# 1. Redistributions of source code must retain the above copyright
-#    notice, this list of conditions and the following disclaimer.
-# 2. Redistributions in binary form must reproduce the above copyright
-#    notice, this list of conditions and the following disclaimer in the
-#    documentation and/or other materials provided with the
-#    distribution.
-# 3. Neither the name of the JPackage Project nor the names of its
-#    contributors may be used to endorse or promote products derived
-#    from this software without specific prior written permission.
-#
-# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
-# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
-# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
-# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
-# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
-# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
-# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
-# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
-# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-#
-
 Name:           plexus-archiver
 Version:        2.4.4
-Release:        3%{?dist}
+Release:        4%{?dist}
 Epoch:          0
 Summary:        Plexus Archiver Component
 License:        ASL 2.0
 URL:            http://plexus.codehaus.org/plexus-components/plexus-archiver/
+BuildArch:      noarch
+
 Source0:        https://github.com/sonatype/%{name}/archive/%{name}-%{version}.tar.gz
 
-
-BuildArch:      noarch
+# PLXCOMP-64 and PLXCOMP-113: Add support for extracting zip and tar symbolic links
+# Forwarded upstream: https://github.com/sonatype/plexus-archiver/pull/14
+Patch0:         0001-Fix-PLXCOMP-113-and-PLXCOMP-64.patch
 
 BuildRequires:  maven-local
 BuildRequires:  plexus-containers-container-default
@@ -46,7 +19,6 @@ BuildRequires:  plexus-io
 BuildRequires:  plexus-utils
 BuildRequires:  apache-commons-compress
 
-
 %description
 The Plexus project seeks to create end-to-end developer tools for
 writing applications. At the core is the container, which can be
@@ -65,6 +37,7 @@ Javadoc for %{name}.
 
 %prep
 %setup -q -n %{name}-%{name}-%{version}
+%patch0 -p1
 %mvn_file :%{name} plexus/archiver
 
 %build
@@ -80,6 +53,9 @@ Javadoc for %{name}.
 %doc LICENSE
 
 %changelog
+* Tue Sep  2 2014 Mikolaj Izdebski <mizdebsk at redhat.com> - 0:2.4.4-4
+- Add patch for extracting symbolic links
+
 * Sat Jun 07 2014 Fedora Release Engineering <rel-eng at lists.fedoraproject.org> - 0:2.4.4-3
 - Rebuilt for https://fedoraproject.org/wiki/Fedora_21_Mass_Rebuild
 


More information about the scm-commits mailing list