Skip to content

Commit

Permalink
Use new dirty statuses to detect zip file changes.
Browse files Browse the repository at this point in the history
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. rubyzip#506) this
means we save a lot of memory, and a lot of time constructing the zip
file in memory.
  • Loading branch information
hainesr committed Feb 7, 2022
1 parent 3c2310d commit bfd528d
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions lib/zip/file.rb
Expand Up @@ -103,8 +103,6 @@ def initialize(path_or_io, create: false, buffer: false, **options)
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]
Expand Down Expand Up @@ -318,10 +316,13 @@ def close
# 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
Expand Down

0 comments on commit bfd528d

Please sign in to comment.