Skip to content

Commit 623c2a6

Browse files
committed
PLXCOMP-232. Unpacking .tar.gz fails
1 parent 5033cd0 commit 623c2a6

File tree

3 files changed

+77
-64
lines changed

3 files changed

+77
-64
lines changed

src/main/java/org/codehaus/plexus/archiver/AbstractUnArchiver.java

Lines changed: 58 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,17 @@
1717
* limitations under the License.
1818
*/
1919

20+
import org.codehaus.plexus.archiver.util.ArchiveEntryUtils;
2021
import org.codehaus.plexus.archiver.util.FilterSupport;
2122
import org.codehaus.plexus.components.io.fileselectors.FileSelector;
2223
import org.codehaus.plexus.components.io.resources.PlexusIoResource;
2324
import org.codehaus.plexus.logging.AbstractLogEnabled;
25+
import org.codehaus.plexus.util.FileUtils;
26+
import org.codehaus.plexus.util.IOUtil;
2427

25-
import java.io.File;
26-
import java.io.IOException;
27-
import java.io.InputStream;
28+
import java.io.*;
2829
import java.util.ArrayList;
30+
import java.util.Date;
2931
import java.util.Iterator;
3032
import java.util.List;
3133

@@ -287,4 +289,57 @@ public void setIgnorePermissions( final boolean ignorePermissions )
287289
this.ignorePermissions = ignorePermissions;
288290
}
289291

292+
protected void extractFile( final File srcF, final File dir, final InputStream compressedInputStream,
293+
final String entryName, final Date entryDate, final boolean isDirectory,
294+
final Integer mode )
295+
throws IOException, ArchiverException
296+
{
297+
final File f = FileUtils.resolveFile(dir, entryName);
298+
299+
try
300+
{
301+
if ( !isOverwrite() && f.exists() && ( f.lastModified() >= entryDate.getTime() ) )
302+
{
303+
return;
304+
}
305+
306+
// create intermediary directories - sometimes zip don't add them
307+
final File dirF = f.getParentFile();
308+
if ( dirF != null )
309+
{
310+
dirF.mkdirs();
311+
}
312+
313+
if ( isDirectory )
314+
{
315+
f.mkdirs();
316+
}
317+
else
318+
{
319+
OutputStream out = null;
320+
try
321+
{
322+
out = new FileOutputStream( f );
323+
324+
IOUtil.copy(compressedInputStream, out);
325+
}
326+
finally
327+
{
328+
IOUtil.close( out );
329+
}
330+
}
331+
332+
f.setLastModified( entryDate.getTime() );
333+
334+
if ( !isIgnorePermissions() && mode != null && !isDirectory)
335+
{
336+
ArchiveEntryUtils.chmod(f, mode, getLogger(), isUseJvmChmod());
337+
}
338+
}
339+
catch ( final FileNotFoundException ex )
340+
{
341+
getLogger().warn( "Unable to expand to file " + f.getPath() );
342+
}
343+
}
344+
290345
}

src/main/java/org/codehaus/plexus/archiver/tar/TarUnArchiver.java

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@
1818
*/
1919

2020
import org.apache.commons.compress.compressors.bzip2.BZip2CompressorInputStream;
21+
import org.codehaus.plexus.archiver.AbstractUnArchiver;
2122
import org.codehaus.plexus.archiver.ArchiverException;
2223
import org.codehaus.plexus.archiver.util.EnumeratedAttribute;
23-
import org.codehaus.plexus.archiver.zip.AbstractZipUnArchiver;
2424
import org.codehaus.plexus.util.IOUtil;
2525

2626
import java.io.BufferedInputStream;
@@ -35,7 +35,7 @@
3535
* @version $Revision$ $Date$
3636
*/
3737
public class TarUnArchiver
38-
extends AbstractZipUnArchiver
38+
extends AbstractUnArchiver
3939
{
4040
public TarUnArchiver()
4141
{
@@ -78,20 +78,30 @@ public void setEncoding( String encoding )
7878

7979
protected void execute()
8080
throws ArchiverException
81+
{
82+
execute(getSourceFile(), getDestDirectory());
83+
}
84+
85+
protected void execute( String path, File outputDirectory )
86+
{
87+
execute( new File(path), getDestDirectory());
88+
}
89+
90+
protected void execute( File sourceFile, File outputDirectory )
8191
{
8292
TarInputStream tis = null;
8393
try
8494
{
85-
getLogger().info( "Expanding: " + getSourceFile() + " into " + getDestDirectory() );
86-
tis = new TarInputStream( compression.decompress( getSourceFile(),
87-
new BufferedInputStream(
88-
new FileInputStream( getSourceFile() ) ) ) );
95+
getLogger().info( "Expanding: " + sourceFile + " into " + outputDirectory );
96+
tis = new TarInputStream( compression.decompress( sourceFile,
97+
new BufferedInputStream(
98+
new FileInputStream( sourceFile ) ) ) );
8999
TarEntry te;
90100

91101
while ( ( te = tis.getNextEntry() ) != null )
92102
{
93-
extractFile( getSourceFile(), getDestDirectory(), tis, te.getName(), te.getModTime(),
94-
te.isDirectory(), te.getMode() != 0 ? te.getMode() : null);
103+
extractFile( sourceFile, outputDirectory, tis, te.getName(), te.getModTime(),
104+
te.isDirectory(), te.getMode() != 0 ? te.getMode() : null);
95105
}
96106
getLogger().debug( "expand complete" );
97107

@@ -197,4 +207,5 @@ else if ( BZIP2.equals( value ) )
197207
return istream;
198208
}
199209
}
210+
200211
}

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

Lines changed: 0 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -191,59 +191,6 @@ private void extractFileIfIncluded( final File sourceFile, final File destDirect
191191
}
192192
}
193193

194-
protected void extractFile( final File srcF, final File dir, final InputStream compressedInputStream,
195-
final String entryName, final Date entryDate, final boolean isDirectory,
196-
final Integer mode )
197-
throws IOException, ArchiverException
198-
{
199-
final File f = FileUtils.resolveFile( dir, entryName );
200-
201-
try
202-
{
203-
if ( !isOverwrite() && f.exists() && ( f.lastModified() >= entryDate.getTime() ) )
204-
{
205-
return;
206-
}
207-
208-
// create intermediary directories - sometimes zip don't add them
209-
final File dirF = f.getParentFile();
210-
if ( dirF != null )
211-
{
212-
dirF.mkdirs();
213-
}
214-
215-
if ( isDirectory )
216-
{
217-
f.mkdirs();
218-
}
219-
else
220-
{
221-
OutputStream out = null;
222-
try
223-
{
224-
out = new FileOutputStream( f );
225-
226-
IOUtil.copy( compressedInputStream, out );
227-
}
228-
finally
229-
{
230-
IOUtil.close( out );
231-
}
232-
}
233-
234-
f.setLastModified( entryDate.getTime() );
235-
236-
if ( !isIgnorePermissions() && mode != null && !isDirectory)
237-
{
238-
ArchiveEntryUtils.chmod( f, mode, getLogger(), isUseJvmChmod() );
239-
}
240-
}
241-
catch ( final FileNotFoundException ex )
242-
{
243-
getLogger().warn( "Unable to expand to file " + f.getPath() );
244-
}
245-
}
246-
247194
protected void execute( final String path, final File outputDirectory )
248195
throws ArchiverException
249196
{

0 commit comments

Comments
 (0)