Skip to content

Loading…

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

Merged
merged 1 commit into from

2 participants

@dmarkow

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.

@simonoff
rubyzip member

Please update README for this feature.

@dmarkow

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!

@simonoff
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
View
3 lib/zip/zip_file.rb
@@ -73,6 +73,7 @@ def initialize(fileName, create = nil, buffer = false)
end
@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
end
- @entrySet != @storedEntries || @create == ZipFile::CREATE
+ @comment != @storedComment || @entrySet != @storedEntries || @create == ZipFile::CREATE
end
# Searches for entry with the specified name. Returns nil if
View
8 test/ziptest.rb
@@ -1452,6 +1452,14 @@ def test_compound2
end
end
+ def test_changeComment
+ ZipFile.open(TEST_ZIP.zip_name) do |zf|
+ zf.comment = "my changed comment"
+ end
+ zfRead = ZipFile.open(TEST_ZIP.zip_name)
+ assert_equal("my changed comment", zfRead.comment)
+ end
+
private
def assert_contains(zf, entryName, filename = entryName)
assert(zf.entries.detect { |e| e.name == entryName} != nil, "entry #{entryName} not in #{zf.entries.join(', ')} in zip file #{zf}")
Something went wrong with that request. Please try again.