Skip to content
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

[MDEP-651] Warn on duplicate archive entries #128

Conversation

mthmulders
Copy link
Contributor

If there's an file system entry for the archive entry currently being extracted, a warning is
logged. If overwrite is false, extraction is aborted.

@rfscholte checked with @viqueen, as this PR superseedes #112, but it's less strict - this one will not fail the build.

If there's an file system entry for the archive entry, a warning is
logged. If overwrite is false, extraction is aborted.
String message = String.format( "Archive entry %s and existing file %s names differ only by case."
+ " This may cause issues on case insensitive file systems.", entryName, canonicalDestPath );
getLogger().warn( message );
if ( !isOverwrite() ) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would expect ( f.lastModified() >= entryDate.getTime() ) here to stay.

entryname  | entrydate | filename   | filedate | behavior
readme.txt | 1970      | readme.txt | 2020     | never overwrite
readme.txt | 2020      | readme.txt | 1970     | only overwrite when isOverWrite()
README.txt | 1970      | readme.txt | 2020     | warn + never overwrite
README.txt | 2020      | readme.txt | 1970     | warn + only overwrite when isOverWrite()

I can extend this table when required

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done. Also added tests that verify the warning is logged.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You mentioned #3 is incorrect: why warn if there is no override? Did you change that?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, I did not change that - I strictly followed the example table.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@plamentotev and/or @michael-o, any thoughts on rule number 3? Would it make sense to log the warning when we're not going to overwrite anyway?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the end it looks like we have 2 tastes:

  • make case-sensitive OS users aware the jar will overwrite a file on case-insensitive OS systems.
  • warn case-insensitive OS users that is overwriting a file with a different name.

I can imagine that if develop teams are all using case-sensitive OS, the warning doesn't add value.
For that reason I agree that we could go for the second taste.
And if it is an issue, we could always add a parameter to enforce equal OS independent results, but I consider that issue too rare for now.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@rfscholte How do you want to guarantee the second taste? There are a number of factors to determine case-sensitivity.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AFAIK the JRE takes care of that: new File("readme.txt").exists() should return true even it is actually "README.txt"

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, you are right, of course. Complete forgot that.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AFAIK the JRE takes care of that: new File("readme.txt").exists() should return true even it is actually "README.txt"

Double-checked that last Friday, can confirm for Windows, macOS and Linux.

Copy link
Member

@michael-o michael-o left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Regarding tests. Please note that ZIP has a second (or two-second, I don't remember) precision. This can lead to funny tests result.

@mthmulders
Copy link
Contributor Author

Regarding tests. Please note that ZIP has a second (or two-second, I don't remember) precision. This can lead to funny tests result.

I can imagine! In the tests, there are no "real" ZIP files - the tests just invoke this shouldExtractEntry method. A test with a real ZIP file would only work on a particular filesystem, so I figured that such tests would add more obscurity instead of clarity.

@mthmulders
Copy link
Contributor Author

If I understand correctly, we have reached consensus on what should in case of (possible) casing conflicts, and on the implementation. If you agree, I'd appreciate if this pull request could be merged - unless some action is required from my side.

@rfscholte rfscholte merged commit efd980d into codehaus-plexus:master Oct 12, 2020
akurtakov added a commit to akurtakov/tycho that referenced this pull request Feb 2, 2022
Dummy pom.xml file is needed for invoker to start but it overrides it
with content of zip file.
Due to codehaus-plexus/plexus-archiver#128
archiver never overrides it as it has newer mdate than what's in
archive. Delete manually before extracting.
akurtakov added a commit to eclipse-tycho/tycho that referenced this pull request Feb 2, 2022
Dummy pom.xml file is needed for invoker to start but it overrides it
with content of zip file.
Due to codehaus-plexus/plexus-archiver#128
archiver never overrides it as it has newer mdate than what's in
archive. Delete manually before extracting.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants