Menu

#33 Setting mtime on ZipEntry raises Exception on commit

open
nobody
None
5
2012-07-18
2010-03-24
No

(Related: #1543984)
In version 0.9.4, setting the mtime of a ZipEntry like this:
zipentry.time = File.stat(zipentry.to_s).mtime
raises an Exception when Zip::ZipFile#commit() is called:
zip/zip.rb:1710:in `pack': can't convert nil into Integer (TypeError)

This is due to various errors in class Zip::ZipExtraField::UniversalTime:
@flag should be initialized to 0, not nil, or alternatively, @flag should be accessed as @flag.to_i (or not be used at all, see below).
The attribute writer methods should set the appriopriate bit in @flag:

def mtime=(value)
@mtime = value
@flag = @flag.to_i | 1
end

As I understand it, @flag is actually redundant, indicating which time values are really set. This is easy to detect in the ruby data, as @mtime etc. are initialized to nil. In #merge(), @flag is already ignored, anyway.

So you should probably better not use @flag at all, but generate the value on-the-fly according to the time values:

def flag
f = 0
@mtime and f |= 1
@atime and f |= 2
@ctime and f |= 4
f
end

Discussion

Anonymous
Anonymous

Add attachments
Cancel





Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.