Zip Timestamp Extraction Help

Hi,

I am trying to validate uploads on an application where the uploaded
file is a zipped archive, and I want some validation to include
acceptable datestamps within the zipfile,

When I open a zip, with invalid datestamp, I receive the console
output:

‘Invalid date/time in zip entry’

Which is great, but I want to be able to extract this information and
use it to reject the upload, but I can’t seem to find a method which
will allow me to extract this information from the zip.

Does anybody know of a method I can use which will return the date/
time stamp of the zip file, or return the Rescue statement above if
it
is invalid?

Thank you

Pete

On Sun, Oct 10, 2010 at 10:54 AM, Pete [email protected] wrote:

Which is great, but I want to be able to extract this information and
use it to reject the upload, but I can’t seem to find a method which
will allow me to extract this information from the zip.

Does anybody know of a method I can use which will return the date/
time stamp of the zip file

Install the rubyzip gem.


Hassan S. ------------------------ [email protected]
twitter: @hassan

On Mon, Oct 11, 2010 at 2:04 AM, Pete [email protected] wrote:

but I am still having the same problems - I am trying to use the
methods (mtime etc) to access the timestamp information that is
initially being returned as the rescue statement ‘Invalid date/time in
zip entry’

What exactly is it that’s returning that statement?

All I need to do is be able to access this ‘invalid date/time’ entry,
but none of the ‘time’ methods seem to return this.

I’m sure they don’t. If, as I suspect, you’re getting that message when
you use ‘unzip’ from the command line, that message is coming from
that specific program.

I would imagine you’ll have to write your own method to examine the
timestamps of the files in the zip and decide whether they meet your
criteria for “invalid”.

FWIW,

Hassan S. ------------------------ [email protected]
twitter: @hassan

Thanks,

rubyzip gem installed,

but I am still having the same problems - I am trying to use the
methods (mtime etc) to access the timestamp information that is
initially being returned as the rescue statement ‘Invalid date/time in
zip entry’

All I need to do is be able to access this ‘invalid date/time’ entry,
but none of the ‘time’ methods seem to return this.

This message is only shown upon opening the zip file - is there a time
method I can use on the zip itself, rather than on the contents which
might show me the invalid timestamp?

Thanks again

Pete

I had the same problem; in my case it arose from treating the file
reference returned from Zip::ZipFile.each{} as a string (like
Dir.each{}) instead of whatever it actually is. Add “.name” where you
need the file name. This code gave the error:

Zip::ZipFile.open(file) { |zip_file|
zip_file.each { |f|
myLogger(“Inspecting file #{f}”)
next unless f.file?

…and this worked:

Zip::ZipFile.open(file) { |zip_file|
zip_file.each { |f|
myLogger(“Inspecting file #{f.name}”)
next unless f.file?

Cheers,

BillR

The line of output is acutally in the rubyzip.rb file itself, line 584

def set_time(binaryDosDate, binaryDosTime)
@time = Time.parse_binary_dos_format(binaryDosDate,
binaryDosTime)
rescue ArgumentError
puts “Invalid date/time in zip entry”
end
end

The Timestamp in the Zip file, is causing the rescue statement to be
output after the file has been opened, but I would like to be able to
‘catch’ this if at all possible,

Thanks

Pete