Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1604)

Unified Diff: third_party/zlib/google/zip.cc

Issue 99333019: Preserve modification timestamp when zipping files. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: better comments, cleanup Created 7 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | third_party/zlib/google/zip_reader.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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..39f58ce596e075f423d32a5934f59a6b68f6f15d 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,38 @@
namespace {
+// Returns a zip_fileinfo struct with the time represented by |file_time|.
+zip_fileinfo TimeToZipFileInfo(const base::Time& file_time) {
+ 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 to leave the date unset. Some programs
+ // might show the unset date as 1980-0-0 which is invalid.
+ 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;
+}
+
+// Returns a zip_fileinfo with the last modification date of |path| set.
+zip_fileinfo GetFileInfoForZipping(const base::FilePath& path) {
+ 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 +100,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 +119,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
« no previous file with comments | « no previous file | third_party/zlib/google/zip_reader.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698