Skip to content


Properly commit when the comment is the only thing changed. #41

merged 1 commit into from

2 participants


Right now, the only way to change the comment on a zip file is to actually change the contents of the zip file in some way. This pull request adds a @storedComment variable (similar to @storedEntries) and updates the commit_required? method to check for a changed comment. Test included.

rubyzip member

Please update README for this feature.


I thought of this more as a bug fix than a feature, and I don't really see where in the README it would make sense to mention this behavior, unless you'd like it to be a configuration option. Let me know and I'll get it updated, thanks!

rubyzip member

Ok, I will rewrite README for it and many other features. Thank you for your bug fix.

@simonoff simonoff merged commit 403cca6 into rubyzip:master
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Showing with 10 additions and 1 deletion.
  1. +2 −1 lib/zip/zip_file.rb
  2. +8 −0 test/ziptest.rb
3 lib/zip/zip_file.rb
@@ -73,6 +73,7 @@ def initialize(fileName, create = nil, buffer = false)
@create = create
@storedEntries = @entrySet.dup
+ @storedComment = @comment
@restore_ownership = false
@restore_permissions = false
@restore_times = true
@@ -229,7 +230,7 @@ def commit_required?
@entrySet.each do |e|
return true if e.dirty
- @entrySet != @storedEntries || @create == ZipFile::CREATE
+ @comment != @storedComment || @entrySet != @storedEntries || @create == ZipFile::CREATE
# Searches for entry with the specified name. Returns nil if
8 test/ziptest.rb
@@ -1452,6 +1452,14 @@ def test_compound2
+ def test_changeComment
+ do |zf|
+ zf.comment = "my changed comment"
+ end
+ zfRead =
+ assert_equal("my changed comment", zfRead.comment)
+ end
def assert_contains(zf, entryName, filename = entryName)
assert(zf.entries.detect { |e| == entryName} != nil, "entry #{entryName} not in #{zf.entries.join(', ')} in zip file #{zf}")
Something went wrong with that request. Please try again.