Upstream version 7.36.149.0
[platform/framework/web/crosswalk.git] / src / third_party / zlib / google / zip.cc
index 5fbfca9..726df33 100644 (file)
 
 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::File::Info 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) {
   base::File file(src_dir, base::File::FLAG_OPEN | base::File::FLAG_READ);
   if (!file.IsValid()) {
@@ -95,34 +63,9 @@ bool AddEntryToZip(zipFile zip_file, const base::FilePath& path,
   if (is_directory)
     str_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 uLong LANGUAGE_ENCODING_FLAG = 0x1 << 11;
-
-  zip_fileinfo file_info = GetFileInfoForZipping(path);
-
-  if (ZIP_OK != zipOpenNewFileInZip4(
-                    zip_file,  // file
-                    str_path.c_str(),  // filename
-                    &file_info,  // zipfi
-                    NULL,  // extrafield_local,
-                    0u,  // size_extrafield_local
-                    NULL,  // extrafield_global
-                    0u,  // size_extrafield_global
-                    NULL,  // comment
-                    Z_DEFLATED,  // method
-                    Z_DEFAULT_COMPRESSION,  // level
-                    0,  // raw
-                    -MAX_WBITS,  // windowBits
-                    DEF_MEM_LEVEL,  // memLevel
-                    Z_DEFAULT_STRATEGY,  // strategy
-                    NULL,  // password
-                    0,  // crcForCrypting
-                    0,  // versionMadeBy
-                    LANGUAGE_ENCODING_FLAG)) {  // flagBase
-    DLOG(ERROR) << "Could not open zip file entry " << str_path;
+  zip_fileinfo file_info = zip::internal::GetFileInfoForZipping(path);
+  if (!zip::internal::ZipOpenNewFileInZip(zip_file, str_path, &file_info))
     return false;
-  }
 
   bool success = true;
   if (!is_directory) {
@@ -202,7 +145,7 @@ bool ZipWithFilterCallback(const base::FilePath& src_dir,
 
     if (!AddEntryToZip(zip_file, path, src_dir)) {
       success = false;
-      return false;
+      break;
     }
   }