Skip to content

Normalize file separators before warning about equal archive entries #249

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -426,7 +426,7 @@ protected boolean shouldExtractEntry( File targetDirectory, File targetFileName,
"" )
+ suffix;
boolean fileOnDiskIsOlderThanEntry = targetFileName.lastModified() < entryDate.getTime();
boolean differentCasing = !entryName.equals( relativeCanonicalDestPath );
boolean differentCasing = !normalizedFileSeparator( entryName ).equals( normalizedFileSeparator( relativeCanonicalDestPath ) );

// Warn for case (4) and (5) if the file system is case-insensitive
if ( differentCasing )
Expand All @@ -440,5 +440,8 @@ protected boolean shouldExtractEntry( File targetDirectory, File targetFileName,
// Override the existing file if isOverwrite() is true or if the file on disk is older than the one in the archive
return isOverwrite() || fileOnDiskIsOlderThanEntry;
}


private String normalizedFileSeparator(String pathOrEntry) {
return pathOrEntry.replace("/", File.separator);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -182,4 +182,21 @@ public void shouldNotWarnAboutDifferentCasingForDirectoryEntries( @TempDir File
assertTrue( this.abstractUnArchiver.shouldExtractEntry( temporaryFolder, file, entryname, entryDate ) );
assertEquals( 0, this.abstractUnArchiver.casingMessageEmitted.get() );
}

@Test
public void shouldExtractWhenCasingDifferOnlyInEntryNamePath( @TempDir File temporaryFolder)
throws IOException
{
// given
String entryName = "directory/whatever.txt";
File file = new File( temporaryFolder, entryName ); // does not create the file!
file.mkdirs();
file.createNewFile();
Date entryDate = new Date(System.currentTimeMillis() + 5000);

// when & then
abstractUnArchiver.setOverwrite( true );
assertTrue( abstractUnArchiver.shouldExtractEntry( temporaryFolder, file, entryName, entryDate ) );
assertEquals(0, abstractUnArchiver.casingMessageEmitted.get());
}
}