Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

lastwritetime is changing while extracting a zipfile in c#?

I am using Sharpziplib version 0.86 to extract a zip file. It is working fine but while extracting a winzip file through code,Lastwritetime is changing in seconds...

Have used this also File.SetLastWriteTime(fullPath, theEntry.DateTime);

Actual file Lastwritetime:4/8/2010 2:29:03PM After zipping that file using winzip and while extracting that file using the code,extracted file Lastwritetime changes to 4/8/2010 2:29:04PM...Is there any fix for this???

like image 783
bala3569 Avatar asked Dec 15 '10 08:12

bala3569


2 Answers

I got this response from Sharpziplib Forum

Hi

This appears to be a WinZip bug. I have not noticed this before.

I did this test:

1) Use WinZip to add a file to a zip. In WinZip click Properties and Details. Look through the details list and find the file time stamp.

2) Use SharpZipLib to create a similar zip file with the same inputfile. Open the result in Winzip and look at the Properties > Details for the file time stamp.

My input file has a Modified timestamp (file properties) of 2010-12-14 15:51:28 and in my test, SharpZipLib stored it correctly in the zip, while WinZip stored it as 2010-12-14 15:51:30

In other words WinZip added 2 seconds when putting it into the zip. After extracting (either with WinZip or SharpZip), the Modified is now 15:51:30 instead of the original 15:51:28.

it is amazing that such an obvious bug in WinZip can have gone unreported and unfixed for so long. If you have a paid version you should certainly raise a bug fault with them.

I just remembered something about 2 second granularity in the old 8.3 file system timestamps.

Quick google found this ...

Quote "Original DOS file system had only 32 bytes to represent a file in the directory. The very restrictive 8.3 filename and the limited granularity (2 second) in file date are corrected in the Win32 file systems (VFAT)." from http://www.xxcopy.com/xxcopy15.htm

The Zip format only allows 2 second granularity in the standard time stamp entry.The date and time are encoded in standard MS-DOS format.

An optional NTFS Extra Data field (0x000a) can be included, which may hold last modification time, last access time and creation time. WinZip does not appear to create it. SharpZip will use it if present but as far as I can see, it is not created when using FastZip to create a zip. That might be a useful option to add to the code. You can certainly create it manually if using ZipFile.

Hope this helps, David

like image 197
bala3569 Avatar answered Nov 09 '22 01:11

bala3569


I think it might just be the operating system that is causing this. I've tried what happens in Explorer. I've got a text file with a modified time stamp of 17:06:45. I right click on the file and choose Send to | Compressed (zipped) folder. Then I right click on the new zip-file and choose Extract All... followed by Next, Next, Finish. Now the extracted text file has a time stamp of 17:06:46.

The same happens when I use 7-Zip, or WinRar. But then it only happens when using a .zip file. If I let them create a .7Z or a .RAR file the time stamp isn't changed.

Found an article on Wikipedia about the zip format. If you search it for "seconds" you'll find a section describing that the ZIP file system mimics the DOS FAT file system, which only has a time resolution of two seconds.

like image 4
comecme Avatar answered Nov 09 '22 02:11

comecme