Use new dirty statuses to detect zip file changes.

This also means that we no longer need to keep a copy of the original
set of `Entry`s or the central directory comment to test for changes.

For situations where a zip file has a lot of entries (e.g. #506) this
means we save a lot of memory, and a lot of time constructing the zip
file in memory.
This commit is contained in:
Robert Haines 2022-02-07 22:22:20 +00:00
parent 08641db9f8
commit 5cd1ef2910
1 changed files with 5 additions and 4 deletions

View File

@ -105,8 +105,6 @@ module Zip
raise Error, "File #{@name} not found"
end
@stored_entries = @cdir.entries.map(&:dup)
@stored_comment = @cdir.comment
@restore_ownership = options[:restore_ownership]
@restore_permissions = options[:restore_permissions]
@restore_times = options[:restore_times]
@ -317,10 +315,13 @@ module Zip
# Returns true if any changes has been made to this archive since
# the previous commit
def commit_required?
return true if @create || @cdir.dirty?
@cdir.each do |e|
return true if e.dirty
return true if e.dirty?
end
comment != @stored_comment || entries != @stored_entries || @create
false
end
# Searches for entry with the specified name. Returns nil if