Gradle

  • Log In Access more options
    • Online Help
    • Keyboard Shortcuts
    • About JIRA
    • JIRA Credits
    • What’s New
  • Dashboards Access more options (Alt+d)
  • Projects Access more options (Alt+p)
  • Issues Access more options (Alt+i)
To raise new issues or bugs against Gradle, please use forums.gradle.org.
  • Gradle
  • GRADLE-2171

Add an option to avoid duplicate entries when creating a zip file

  • Log In
  • Views
    • XML
    • Word
    • Printable

Details

  • Type: Bug Bug
  • Status: Open Open
  • Resolution: Unresolved
  • Affects Version/s: None
  • Fix Version/s: None
  • Gradle Forums topic Reference:

    problem - Add an option to avoid duplicate entries when creating a zip file (pending)

Description

Hi everyone,

While working on another issue, I stumbled across this issue: when you create a Zip file with the Zip task, you might end up with multiple identical entries in the Zip, e.g. the exact same file more than once in the same directory within the Zip. This is the case when multiple "from"'s are given which end up creating the same Filename at the same location within the resulting zip.

As the Zip spec doesn't forbid this case (I think), these Zip files are, in theory, okay. However, depending on how and where you try to extract them, you'll end up with a whole slue or problems and errors. This is why gradle should propose an option to ensure file uniqueness in Zip files.

imho, zip entry uniqueness should even be the default behavior for a couple of reasons: First, it would make the zip task behave the same as the copy task (when it comes to filesystem copies), which also only keeps the last file copied in case of a conflict. Lastly, having multiple identical zip entries is clearly the corner case that 99,99% of users and use cases do NOT want, so in accordance with gradle's general philosophy, those who want the "special" behavior should be the ones having to customize the task.

For the history, please see:
[1]http://forums.gradle.org/gradle/topic...

best regards,
Mike
----------------------------------------------------------------------------------------
[1] http://forums.gradle.org/gradle/topics/solution_for_copying_a_subdirectory_wihtin_a_zip_into_another_zip

Issue Links

Duplicates

Bug - A problem which impairs or prevents the functions of the product. GRADLE-1050 Jar task should merge entries, not create duplicates, at least by default.

  • Open - The issue is open and ready for the assignee to start work on it.

Activity

Ascending order - Click to sort in descending order
  • All
  • Comments
  • History
  • Activity
  • TeamCity
  • Remote Attachments
  • Commits
  • Source
  • Reviews
Hide
Permalink
Michael Brand added a comment - 26/Mar/12 9:26 AM

Seems like Gradle Zip should provide the same options that Ant zip provides:

duplicate: behavior when a duplicate file is found. Valid values are "add", "preserve", and "fail". The default value is "add".

Show
Michael Brand added a comment - 26/Mar/12 9:26 AM Seems like Gradle Zip should provide the same options that Ant zip provides: duplicate: behavior when a duplicate file is found. Valid values are "add", "preserve", and "fail". The default value is "add".
Hide
Permalink
Peter Niederwieser added a comment - 14/Jul/12 4:38 AM

I have a tested fix that filters duplicates for Zips/Jars/Wars/Ears/Tars. Do we need to support other behaviors (e.g. fail fast)? Can we change the default? Seems like adding duplicate entries is almost never useful. Conversely, people regularly run into the problem that the same file gets added multiple times. For comparison, the JDK ZipOutputStream class fails hard when an attempt is made to add another entry with the same path.

Show
Peter Niederwieser added a comment - 14/Jul/12 4:38 AM I have a tested fix that filters duplicates for Zips/Jars/Wars/Ears/Tars. Do we need to support other behaviors (e.g. fail fast)? Can we change the default? Seems like adding duplicate entries is almost never useful. Conversely, people regularly run into the problem that the same file gets added multiple times. For comparison, the JDK ZipOutputStream class fails hard when an attempt is made to add another entry with the same path.
Hide
Permalink
Jason D added a comment - 27/Nov/12 4:17 PM - edited

The solution to this may also apply to GRADLE-1050 . (Consider voting for that one too )

Show
Jason D added a comment - 27/Nov/12 4:17 PM - edited The solution to this may also apply to GRADLE-1050 . (Consider voting for that one too )
Hide
Permalink
Kyle Mahan added a comment - 06/May/13 10:40 AM - edited

I agree that filtering duplicates would be a much friendlier (default?) behavior. Configuring with Ant's add/preserve/fail would also be satisfactory to me but feels a little un-Gradle-like.

task zip(type: Zip) {
  from ...
  onDuplicate 'fail'
}

as opposed to something like

task zip(type: Zip) {
  from ...
  onDuplicate { throw new RuntimeException("Duplicate: $it") }
}

I would be interested in helping to test Peter's patch or contributing code to this issue if it would help!

Show
Kyle Mahan added a comment - 06/May/13 10:40 AM - edited I agree that filtering duplicates would be a much friendlier (default?) behavior. Configuring with Ant's add/preserve/fail would also be satisfactory to me but feels a little un-Gradle-like.
task zip(type: Zip) {
  from ...
  onDuplicate 'fail'
}
as opposed to something like
task zip(type: Zip) {
  from ...
  onDuplicate { throw new RuntimeException("Duplicate: $it") }
}
I would be interested in helping to test Peter's patch or contributing code to this issue if it would help!

People

  • Assignee:
    Unassigned
    Reporter:
    Gradle Forums
Vote (17)
Watch (15)

Dates

  • Created:
    14/Mar/12 11:12 AM
    Updated:
    06/May/13 10:48 AM
  • Atlassian JIRA (v5.0.3#729-sha1:bf569e4)
  • Report a problem
  • Powered by a free Atlassian JIRA open source license for Gradle. Try JIRA - bug tracking software for your team.