summaryrefslogtreecommitdiffstats
path: root/third_party/zlib
diff options
context:
space:
mode:
authorjoaoe@opera.com <joaoe@opera.com@0039d316-1c4b-4281-b951-d872f2087c98>2014-05-02 16:50:09 +0000
committerjoaoe@opera.com <joaoe@opera.com@0039d316-1c4b-4281-b951-d872f2087c98>2014-05-02 16:50:09 +0000
commit9b3ec83e377ee60bbf824dac6f16ffd52c3d7726 (patch)
tree2068ff33b2a35c31bb3abe32d48ad3d42c891d20 /third_party/zlib
parent8ba4196018803bc3fc0ccd2cce9d4f1a3f01fad8 (diff)
downloadchromium_src-9b3ec83e377ee60bbf824dac6f16ffd52c3d7726.zip
chromium_src-9b3ec83e377ee60bbf824dac6f16ffd52c3d7726.tar.gz
chromium_src-9b3ec83e377ee60bbf824dac6f16ffd52c3d7726.tar.bz2
Move internal zip code from zip.cc to zip_internal.cc
Also added missing <vector> told by the linter, fixed leak of a zipFile in ZipWithFilterCallback in case of error, and corrected error in function name. BUG=359428 Review URL: https://codereview.chromium.org/222323002 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@267815 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'third_party/zlib')
-rw-r--r--third_party/zlib/google/zip.cc63
-rw-r--r--third_party/zlib/google/zip.h2
-rw-r--r--third_party/zlib/google/zip_internal.cc68
-rw-r--r--third_party/zlib/google/zip_internal.h14
-rw-r--r--third_party/zlib/google/zip_reader.cc2
5 files changed, 85 insertions, 64 deletions
diff --git a/third_party/zlib/google/zip.cc b/third_party/zlib/google/zip.cc
index 5fbfca9..726df33 100644
--- a/third_party/zlib/google/zip.cc
+++ b/third_party/zlib/google/zip.cc
@@ -26,38 +26,6 @@
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;
}
}
diff --git a/third_party/zlib/google/zip.h b/third_party/zlib/google/zip.h
index 9809fce..0232401 100644
--- a/third_party/zlib/google/zip.h
+++ b/third_party/zlib/google/zip.h
@@ -5,6 +5,8 @@
#ifndef THIRD_PARTY_ZLIB_GOOGLE_ZIP_H_
#define THIRD_PARTY_ZLIB_GOOGLE_ZIP_H_
+#include <vector>
+
#include "base/callback.h"
#include "base/files/file_path.h"
diff --git a/third_party/zlib/google/zip_internal.cc b/third_party/zlib/google/zip_internal.cc
index a01ae8c..6349b7a 100644
--- a/third_party/zlib/google/zip_internal.cc
+++ b/third_party/zlib/google/zip_internal.cc
@@ -2,12 +2,14 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#include "third_party/zlib/google/zip.h"
+#include "third_party/zlib/google/zip_internal.h"
#include <algorithm>
+#include "base/file_util.h"
#include "base/logging.h"
#include "base/strings/utf_string_conversions.h"
+#include "base/time/time.h"
#if defined(USE_SYSTEM_MINIZIP)
#include <minizip/ioapi.h>
@@ -230,6 +232,28 @@ int GetErrorOfZipBuffer(void* /*opaque*/, void* /*stream*/) {
return 0;
}
+// 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;
+}
} // namespace
namespace zip {
@@ -266,7 +290,7 @@ unzFile OpenHandleForUnzipping(HANDLE zip_handle) {
#endif
// static
-unzFile PreprareMemoryForUnzipping(const std::string& data) {
+unzFile PrepareMemoryForUnzipping(const std::string& data) {
if (data.empty())
return NULL;
@@ -312,5 +336,45 @@ zipFile OpenFdForZipping(int zip_fd, int append_flag) {
}
#endif
+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 ZipOpenNewFileInZip(zipFile zip_file,
+ const std::string& str_path,
+ const zip_fileinfo* file_info) {
+ // 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;
+
+ 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;
+ return false;
+ }
+ return true;
+}
+
} // namespace internal
} // namespace zip
diff --git a/third_party/zlib/google/zip_internal.h b/third_party/zlib/google/zip_internal.h
index 57894be..ffd4039 100644
--- a/third_party/zlib/google/zip_internal.h
+++ b/third_party/zlib/google/zip_internal.h
@@ -19,6 +19,10 @@
#include "third_party/zlib/contrib/minizip/zip.h"
#endif
+namespace base {
+class FilePath;
+}
+
// Utility functions and constants used internally for the zip file
// library in the directory. Don't use them outside of the library.
namespace zip {
@@ -41,7 +45,7 @@ unzFile OpenHandleForUnzipping(HANDLE zip_handle);
// Creates a custom unzFile object which reads data from the specified string.
// This custom unzFile object overrides the I/O API functions of zlib so it can
// read data from the specified string.
-unzFile PreprareMemoryForUnzipping(const std::string& data);
+unzFile PrepareMemoryForUnzipping(const std::string& data);
// Opens the given file name in UTF-8 for zipping, with some setup for
// Windows. |append_flag| will be passed to zipOpen2().
@@ -53,6 +57,14 @@ zipFile OpenForZipping(const std::string& file_name_utf8, int append_flag);
zipFile OpenFdForZipping(int zip_fd, int append_flag);
#endif
+// Returns a zip_fileinfo with the last modification date of |path| set.
+zip_fileinfo GetFileInfoForZipping(const base::FilePath& path);
+
+// Wrapper around zipOpenNewFileInZip4 which passes most common options.
+bool ZipOpenNewFileInZip(zipFile zip_file,
+ const std::string& str_path,
+ const zip_fileinfo* file_info);
+
const int kZipMaxPath = 256;
const int kZipBufSize = 8192;
diff --git a/third_party/zlib/google/zip_reader.cc b/third_party/zlib/google/zip_reader.cc
index f34f4f7..aa85fa3 100644
--- a/third_party/zlib/google/zip_reader.cc
+++ b/third_party/zlib/google/zip_reader.cc
@@ -107,7 +107,7 @@ bool ZipReader::OpenFromPlatformFile(base::PlatformFile zip_fd) {
}
bool ZipReader::OpenFromString(const std::string& data) {
- zip_file_ = internal::PreprareMemoryForUnzipping(data);
+ zip_file_ = internal::PrepareMemoryForUnzipping(data);
if (!zip_file_)
return false;
return OpenInternal();