Menu

#13 time attribute bug

open
None
5
2012-07-18
2006-08-21
No

The following bug was submitted to me by email:

Hi!

I'm investigating what seems to be a bug in RubyZip.
I'm trying to
create a zip file and maintain the timestamp of the
file. Here's what
I do:

Zip::ZipFile::open(filename) { |zipfile|
entry = zipfile.find_entry(entry_name)
if entry
entry.time = mtime
puts entry.time
end

zipfile.commit()
}

The time printed out by the "puts" statement does not
match the
timestamp in the generated zip-file.

Am I doing something wrong, or is the "time=" method
not implemented correctly?

--
/Jesper

Discussion

  • Atushi Sakauchi

    Atushi Sakauchi - 2006-09-05

    Logged In: YES
    user_id=1591032

    Hi.

    I found that the timestamp does not used in
    ZipOutputStream.put_next_entry()

    I made a patch.

    --- zip.rb.orig Tue Sep 5 15:49:45 2006
    +++ zip.rb Tue Sep 5 19:53:59 2006
    @@ -953,7 +953,8 @@
    # +entry+ can be a ZipEntry object or a string.
    def put_next_entry(entry, level =
    Zlib::DEFAULT_COMPRESSION)
    raise ZipError, "zip stream is closed" if @closed
    - newEntry = entry.kind_of?(ZipEntry) ? entry :
    ZipEntry.new(@fileName, entry.to_s)
    + newEntry = entry.kind_of?(ZipEntry) ? entry :
    ZipEntry.new(@fileName, entry.to_s,
    + "", "", 0, 0, ZipEntry::DEFLATED, 0, entry.time )
    init_next_entry(newEntry, level)
    @currentEntry=newEntry
    end

     
  • SOUMA Yutaka

    SOUMA Yutaka - 2007-03-13

    Logged In: YES
    user_id=1742486
    Originator: NO

    Hi. last patch works not well, so I wrote new patch.
    rake test passed and files' mtime valid in local test code.
    please test and import asap.

    --- lib/zip/zip.rb.org 2007-03-12 22:29:16.000000000 +0900
    +++ lib/zip/zip.rb 2007-03-13 16:31:30.000000000 +0900
    @@ -954,6 +954,11 @@
    def put_next_entry(entry, level = Zlib::DEFAULT_COMPRESSION)
    raise ZipError, "zip stream is closed" if @closed
    newEntry = entry.kind_of?(ZipEntry) ? entry : ZipEntry.new(@fileName, entry.to_s)
    + begin
    + newEntry.time= File.mtime( entry.to_s )
    + rescue
    + newEntry.time = Time.now()
    + end
    init_next_entry(newEntry, level)
    @currentEntry=newEntry
    end
    @@ -1667,11 +1672,13 @@

       def to_local_bin
         s = pack_for_local
    
    • return '' unless s
      self.class.const_get(:HEADER_ID) + [s.length].pack("v") + s
      end

      def to_c_dir_bin
      s = pack_for_c_dir
      + return '' unless s
      self.class.const_get(:HEADER_ID) + [s.length].pack("v") + s
      end
      end
      @@ -1707,6 +1714,7 @@
      end

      def pack_for_local
      + return nil unless @flag
      s = [@flag].pack("C")
      @flag & 1 != 0 and s << [@mtime.to_i].pack("V")
      @flag & 2 != 0 and s << [@atime.to_i].pack("V")
      @@ -1715,6 +1723,7 @@
      end

      def pack_for_c_dir
      + return nil unless @flag
      s = [@flag].pack("C")
      @flag & 1 == 1 and s << [@mtime.to_i].pack("V")
      s

     
  • SOUMA Yutaka

    SOUMA Yutaka - 2007-03-13

    Logged In: YES
    user_id=1742486
    Originator: NO

    sorry, that patch has 2 silly miss(tab 2 space convert miss)
    please replase 2 line
    + return nil unless @flag
    to
    + return nil unless @flag
    (1 space character lacks)

     

Anonymous
Anonymous

Add attachments
Cancel