Chromium Code Reviews| Index: third_party/zlib/google/zip.cc |
| diff --git a/third_party/zlib/google/zip.cc b/third_party/zlib/google/zip.cc |
| index d1ba74fb147a328d6aabcca5fe697a1640291654..baf9c99a5ea0ad7744befc9c142accf11a7c8b68 100644 |
| --- a/third_party/zlib/google/zip.cc |
| +++ b/third_party/zlib/google/zip.cc |
| @@ -4,6 +4,9 @@ |
| #include "third_party/zlib/google/zip.h" |
| +#include <string> |
| +#include <vector> |
| + |
| #include "base/bind.h" |
| #include "base/file_util.h" |
| #include "base/files/file_enumerator.h" |
| @@ -24,6 +27,36 @@ |
| namespace { |
| +zip_fileinfo TimeToZipFileInfo(const base::Time& file_time) { |
|
satorux1
2013/12/12 08:03:57
function comment is missing.
http://google-styleg
|
| + base::Time::Exploded file_time_parts; |
| + file_time.LocalExplode(&file_time_parts); |
| + |
| + zip_fileinfo zip_info = {}; |
| + if (file_time_parts.year >= 1980) { |
| + // This if check works around the handling of the year value in |
| + // contrib/minizip/zip.c in function zip64local_TmzDateToDosDate |
| + // It assumes that dates below 1980 are in the double digit format. |
| + // Hence the fail safe option is just to allow the default date (epoch) |
| + // to be set. |
| + zip_info.tmz_date.tm_year = file_time_parts.year; |
| + zip_info.tmz_date.tm_mon = file_time_parts.month - 1; |
| + zip_info.tmz_date.tm_mday = file_time_parts.day_of_month; |
| + zip_info.tmz_date.tm_hour = file_time_parts.hour; |
| + zip_info.tmz_date.tm_min = file_time_parts.minute; |
| + zip_info.tmz_date.tm_sec = file_time_parts.second; |
| + } |
| + |
| + return zip_info; |
| +} |
| + |
| +zip_fileinfo GetFileInfoForZipping(const base::FilePath& path) { |
|
satorux1
2013/12/12 08:03:57
ditto
|
| + base::Time file_time; |
| + base::PlatformFileInfo file_info; |
| + if (base::GetFileInfo(path, &file_info)) |
| + file_time = file_info.last_modified; |
| + return TimeToZipFileInfo(file_time); |
| +} |
| + |
| bool AddFileToZip(zipFile zip_file, const base::FilePath& src_dir) { |
| net::FileStream stream(NULL); |
| int flags = base::PLATFORM_FILE_OPEN | base::PLATFORM_FILE_READ; |
| @@ -65,12 +98,14 @@ bool AddEntryToZip(zipFile zip_file, const base::FilePath& path, |
| // Section 4.4.4 http://www.pkware.com/documents/casestudies/APPNOTE.TXT |
| // Setting the Language encoding flag so the file is told to be in utf-8. |
| - const unsigned long LANGUAGE_ENCODING_FLAG = 0x1 << 11; |
| + const uLong LANGUAGE_ENCODING_FLAG = 0x1 << 11; |
| + |
| + zip_fileinfo file_info = GetFileInfoForZipping(path); |
| if (ZIP_OK != zipOpenNewFileInZip4( |
| - zip_file, //file |
| + zip_file, // file |
| str_path.c_str(), // filename |
| - NULL, // zipfi (file_info) |
| + &file_info, // zipfi |
| NULL, // extrafield_local, |
| 0u, // size_extrafield_local |
| NULL, // extrafield_global |
| @@ -82,7 +117,7 @@ bool AddEntryToZip(zipFile zip_file, const base::FilePath& path, |
| -MAX_WBITS, // windowBits |
| DEF_MEM_LEVEL, // memLevel |
| Z_DEFAULT_STRATEGY, // strategy |
| - NULL, //password |
| + NULL, // password |
| 0, // crcForCrypting |
| 0, // versionMadeBy |
| LANGUAGE_ENCODING_FLAG)) { // flagBase |