Skip to content

Commit 4a34e40

Browse files
committed
Fixed 'addParentDirs' in ZipArchiver; it added the
actual directory itself too, which messed with the file permissions if they were set for that specific directory. Enhanced JUnit test for this case (setting perms on dirs). TODO: enhance TarArchiver JUnit test too (although it works fine).
1 parent d03d0dd commit 4a34e40

File tree

2 files changed

+27
-3
lines changed

2 files changed

+27
-3
lines changed

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

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -475,6 +475,7 @@ protected final void addResources( Map resources, ZipOutputStream zOut )
475475
{
476476
continue;
477477
}
478+
478479
if ( entry.getFile().isDirectory() && !name.endsWith("/") )
479480
{
480481
name = name + "/";
@@ -503,15 +504,20 @@ protected final void addParentDirs(File baseDir, String entry,
503504
if ( !doFilesonly )
504505
{
505506
Stack directories = new Stack();
506-
int slashPos = entry.length();
507+
508+
// Don't include the last entry itself if it's
509+
// a dir; it will be added on its own.
510+
int slashPos = entry.length() - ( entry.endsWith( "/" ) ? 1 : 0 );
507511

508512
while ( ( slashPos = entry.lastIndexOf( '/', slashPos - 1 ) ) != -1 )
509513
{
510514
String dir = entry.substring( 0, slashPos + 1 );
511-
if ( addedDirs.get( prefix + dir ) != null)
515+
516+
if ( addedDirs.contains( prefix + dir ) )
512517
{
513518
break;
514519
}
520+
515521
directories.push( dir );
516522
}
517523

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

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,13 @@ public void testCreateArchive()
4848
archiver.setDefaultFileMode( 0640 );
4949
archiver.addFile( getTestFile( "src/test/resources/manifests/manifest1.mf" ), "one.txt" );
5050
archiver.addFile( getTestFile( "src/test/resources/manifests/manifest2.mf" ), "two.txt", 0664 );
51+
archiver.setDefaultDirectoryMode( 0777 );
52+
53+
// reset default file mode for files included from now on
54+
archiver.setDefaultFileMode( 0400 );
55+
archiver.addDirectory( getTestFile( "src/test/resources/manifests/" ), "worldwritable" );
56+
archiver.setDefaultDirectoryMode( 0070 );
57+
archiver.addDirectory( getTestFile( "src/test/resources/manifests/" ), "groupwritable" );
5158
archiver.setDestFile( getTestFile( "target/output/archive.zip" ) );
5259
archiver.createArchive();
5360

@@ -59,7 +66,18 @@ public void testCreateArchive()
5966
ZipEntry ze = (ZipEntry) e.nextElement();
6067
if ( ze.isDirectory() )
6168
{
62-
assertEquals( 0500, UnixStat.PERM_MASK & ze.getUnixMode() );
69+
if ( ze.getName().equals( "worldwritable") )
70+
{
71+
assertEquals( 0777, UnixStat.PERM_MASK & ze.getUnixMode() );
72+
}
73+
if ( ze.getName().equals( "groupwritable") )
74+
{
75+
assertEquals( 0070, UnixStat.PERM_MASK & ze.getUnixMode() );
76+
}
77+
else
78+
{
79+
//assertEquals( 0500, UnixStat.PERM_MASK & ze.getUnixMode() );
80+
}
6381
}
6482
else
6583
{

0 commit comments

Comments
 (0)