Skip to content

Commit

Permalink
Fix unjustified warning about casing for directory entries
Browse files Browse the repository at this point in the history
  • Loading branch information
mthmulders committed Jan 27, 2021
1 parent ad3f2f3 commit a503307
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
Expand Up @@ -405,8 +405,13 @@ protected boolean shouldExtractEntry( File targetDirectory, File targetFileName,
return true;
}

boolean entryIsDirectory = entryName.endsWith( "/" ); // directory entries always end with '/', regardless of the OS.
String canonicalDestPath = targetFileName.getCanonicalPath();
String relativeCanonicalDestPath = canonicalDestPath.replace( targetDirectory.getCanonicalPath() + File.separatorChar, "" );
String suffix = (entryIsDirectory ? "/" : "");
String relativeCanonicalDestPath = canonicalDestPath.replace(
targetDirectory.getCanonicalPath() + File.separatorChar,
"" )
+ suffix;
boolean fileOnDiskIsNewerThanEntry = targetFileName.lastModified() >= entryDate.getTime();
boolean differentCasing = !entryName.equals( relativeCanonicalDestPath );

Expand Down
Expand Up @@ -33,7 +33,8 @@

import static org.hamcrest.CoreMatchers.hasItem;
import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertThat;
import static org.hamcrest.CoreMatchers.not;
import static org.hamcrest.MatcherAssert.assertThat;

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

@Test
public void shouldNotWarnAboutDifferentCasingForDirectoryEntries() throws IOException
{
// given
File file = temporaryFolder.newFolder();
file.setLastModified( 0 );
String entryname = file.getName() + '/'; // archive entries for directories end with a '/'
Date entryDate = new Date();

// when & then
this.abstractUnArchiver.setOverwrite( true );
assertThat( this.abstractUnArchiver.shouldExtractEntry( temporaryFolder.getRoot(), file, entryname, entryDate ), is( true ) );
assertThat( this.log.getWarns(), not( hasItem( new LogMessageMatcher( "names differ only by case" ) ) ) );
}

static class LogMessageMatcher extends BaseMatcher<CapturingLog.Message> {
private final StringContains delegateMatcher;

Expand Down

0 comments on commit a503307

Please sign in to comment.