Skip to content

Commit f7f90ec

Browse files
mthmuldersplamentotev
authored andcommitted
Fix unjustified warning about casing for directory entries
1 parent ad3f2f3 commit f7f90ec

File tree

2 files changed

+23
-2
lines changed

2 files changed

+23
-2
lines changed

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

+6-1
Original file line numberDiff line numberDiff line change
@@ -405,8 +405,13 @@ protected boolean shouldExtractEntry( File targetDirectory, File targetFileName,
405405
return true;
406406
}
407407

408+
boolean entryIsDirectory = entryName.endsWith( "/" ); // directory entries always end with '/', regardless of the OS.
408409
String canonicalDestPath = targetFileName.getCanonicalPath();
409-
String relativeCanonicalDestPath = canonicalDestPath.replace( targetDirectory.getCanonicalPath() + File.separatorChar, "" );
410+
String suffix = (entryIsDirectory ? "/" : "");
411+
String relativeCanonicalDestPath = canonicalDestPath.replace(
412+
targetDirectory.getCanonicalPath() + File.separatorChar,
413+
"" )
414+
+ suffix;
410415
boolean fileOnDiskIsNewerThanEntry = targetFileName.lastModified() >= entryDate.getTime();
411416
boolean differentCasing = !entryName.equals( relativeCanonicalDestPath );
412417

src/test/java/org/codehaus/plexus/archiver/AbstractUnArchiverTest.java

+17-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,8 @@
3333

3434
import static org.hamcrest.CoreMatchers.hasItem;
3535
import static org.hamcrest.CoreMatchers.is;
36-
import static org.junit.Assert.assertThat;
36+
import static org.hamcrest.CoreMatchers.not;
37+
import static org.hamcrest.MatcherAssert.assertThat;
3738

3839
/**
3940
* Unit test for {@link AbstractUnArchiver}
@@ -184,6 +185,21 @@ public void shouldExtractWhenEntryInArchiveIsNewerThanFileOnDiskAndWarnAboutDiff
184185
assertThat( this.log.getWarns(), hasItem( new LogMessageMatcher( "names differ only by case" ) ) );
185186
}
186187

188+
@Test
189+
public void shouldNotWarnAboutDifferentCasingForDirectoryEntries() throws IOException
190+
{
191+
// given
192+
File file = temporaryFolder.newFolder();
193+
file.setLastModified( 0 );
194+
String entryname = file.getName() + '/'; // archive entries for directories end with a '/'
195+
Date entryDate = new Date();
196+
197+
// when & then
198+
this.abstractUnArchiver.setOverwrite( true );
199+
assertThat( this.abstractUnArchiver.shouldExtractEntry( temporaryFolder.getRoot(), file, entryname, entryDate ), is( true ) );
200+
assertThat( this.log.getWarns(), not( hasItem( new LogMessageMatcher( "names differ only by case" ) ) ) );
201+
}
202+
187203
static class LogMessageMatcher extends BaseMatcher<CapturingLog.Message> {
188204
private final StringContains delegateMatcher;
189205

0 commit comments

Comments
 (0)