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

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

Merged
merged 1 commit into from Apr 7, 2012
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 2 additions & 1 deletion lib/zip/zip_file.rb
Expand Up @@ -73,6 +73,7 @@ def initialize(fileName, create = nil, buffer = false)
end end
@create = create @create = create
@storedEntries = @entrySet.dup @storedEntries = @entrySet.dup
@storedComment = @comment
@restore_ownership = false @restore_ownership = false
@restore_permissions = false @restore_permissions = false
@restore_times = true @restore_times = true
Expand Down Expand Up @@ -229,7 +230,7 @@ def commit_required?
@entrySet.each do |e| @entrySet.each do |e|
return true if e.dirty return true if e.dirty
end end
@entrySet != @storedEntries || @create == ZipFile::CREATE @comment != @storedComment || @entrySet != @storedEntries || @create == ZipFile::CREATE
end end


# Searches for entry with the specified name. Returns nil if # Searches for entry with the specified name. Returns nil if
Expand Down
8 changes: 8 additions & 0 deletions test/ziptest.rb
Expand Up @@ -1452,6 +1452,14 @@ def test_compound2
end end
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 private
def assert_contains(zf, entryName, filename = entryName) 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}") assert(zf.entries.detect { |e| e.name == entryName} != nil, "entry #{entryName} not in #{zf.entries.join(', ')} in zip file #{zf}")
Expand Down