From 4777bc566e7931c891c4fa16261f04ed940ec9d5 Mon Sep 17 00:00:00 2001 From: "aa@chromium.org" Date: Mon, 1 Jun 2009 02:53:00 +0000 Subject: Implements a Zip() utility function. Refactor existing Unzip-relatedness into shared locations. Review URL: http://codereview.chromium.org/118028 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@17305 0039d316-1c4b-4281-b951-d872f2087c98 --- chrome/browser/extensions/extensions_service.cc | 2 +- chrome/chrome.gyp | 6 +- chrome/common/common.vcproj | 16 +- chrome/common/extensions/extension_unpacker.cc | 4 +- chrome/common/unzip.cc | 200 ---------------- chrome/common/unzip.h | 19 -- chrome/common/unzip_unittest.cc | 93 -------- chrome/common/zip.cc | 299 ++++++++++++++++++++++++ chrome/common/zip.h | 20 ++ chrome/common/zip_unittest.cc | 105 +++++++++ chrome/test/data/unzip/test.zip | Bin 5236 -> 0 bytes chrome/test/data/unzip/test/foo.txt | 1 - chrome/test/data/unzip/test/foo/bar.txt | 1 - chrome/test/data/unzip/test/foo/bar/baz.txt | 1 - chrome/test/data/unzip/test/foo/bar/quux.txt | 39 ---- chrome/test/data/unzip/test_nocompress.zip | Bin 14667 -> 0 bytes chrome/test/data/zip/test.zip | Bin 0 -> 5052 bytes chrome/test/data/zip/test/foo.txt | 1 + chrome/test/data/zip/test/foo/bar.txt | 1 + chrome/test/data/zip/test/foo/bar/baz.txt | 1 + chrome/test/data/zip/test/foo/bar/quux.txt | 39 ++++ chrome/test/data/zip/test_nocompress.zip | Bin 0 -> 14239 bytes chrome/test/unit/unittests.vcproj | 6 +- 23 files changed, 483 insertions(+), 371 deletions(-) delete mode 100644 chrome/common/unzip.cc delete mode 100644 chrome/common/unzip.h delete mode 100644 chrome/common/unzip_unittest.cc create mode 100644 chrome/common/zip.cc create mode 100644 chrome/common/zip.h create mode 100644 chrome/common/zip_unittest.cc delete mode 100644 chrome/test/data/unzip/test.zip delete mode 100644 chrome/test/data/unzip/test/foo.txt delete mode 100644 chrome/test/data/unzip/test/foo/bar.txt delete mode 100644 chrome/test/data/unzip/test/foo/bar/baz.txt delete mode 100644 chrome/test/data/unzip/test/foo/bar/quux.txt delete mode 100644 chrome/test/data/unzip/test_nocompress.zip create mode 100755 chrome/test/data/zip/test.zip create mode 100644 chrome/test/data/zip/test/foo.txt create mode 100644 chrome/test/data/zip/test/foo/bar.txt create mode 100644 chrome/test/data/zip/test/foo/bar/baz.txt create mode 100644 chrome/test/data/zip/test/foo/bar/quux.txt create mode 100755 chrome/test/data/zip/test_nocompress.zip (limited to 'chrome') diff --git a/chrome/browser/extensions/extensions_service.cc b/chrome/browser/extensions/extensions_service.cc index b86c454..6db4c2e 100644 --- a/chrome/browser/extensions/extensions_service.cc +++ b/chrome/browser/extensions/extensions_service.cc @@ -31,7 +31,7 @@ #include "chrome/common/json_value_serializer.h" #include "chrome/common/notification_service.h" #include "chrome/common/pref_service.h" -#include "chrome/common/unzip.h" +#include "chrome/common/zip.h" #include "chrome/common/url_constants.h" #include "grit/chromium_strings.h" #include "grit/generated_resources.h" diff --git a/chrome/chrome.gyp b/chrome/chrome.gyp index f17b24e..2be4aea 100644 --- a/chrome/chrome.gyp +++ b/chrome/chrome.gyp @@ -412,8 +412,6 @@ 'common/transport_dib_linux.cc', 'common/transport_dib_mac.cc', 'common/transport_dib_win.cc', - 'common/unzip.cc', # Requires zlib directly. - 'common/unzip.h', 'common/url_constants.cc', 'common/url_constants.h', 'common/visitedlink_common.cc', @@ -426,6 +424,8 @@ 'common/x11_util.cc', 'common/x11_util.h', 'common/x11_util_internal.h', + 'common/zip.cc', # Requires zlib directly. + 'common/zip.h', 'third_party/xdg_user_dirs/xdg_user_dir_lookup.cc', 'tools/build/win/precompiled.cc', @@ -3182,8 +3182,8 @@ 'common/property_bag_unittest.cc', 'common/resource_dispatcher_unittest.cc', 'common/time_format_unittest.cc', - 'common/unzip_unittest.cc', 'common/worker_thread_ticker_unittest.cc', + 'common/zip_unittest.cc', 'renderer/extensions/extension_api_client_unittest.cc', 'renderer/extensions/greasemonkey_api_unittest.cc', 'renderer/extensions/json_schema_unittest.cc', diff --git a/chrome/common/common.vcproj b/chrome/common/common.vcproj index dc3ed4d..386bf35 100644 --- a/chrome/common/common.vcproj +++ b/chrome/common/common.vcproj @@ -746,14 +746,6 @@ > - - - - @@ -789,6 +781,14 @@ RelativePath=".\worker_thread_ticker.h" > + + + + diff --git a/chrome/common/extensions/extension_unpacker.cc b/chrome/common/extensions/extension_unpacker.cc index c39f9a2..f98e875 100644 --- a/chrome/common/extensions/extension_unpacker.cc +++ b/chrome/common/extensions/extension_unpacker.cc @@ -16,10 +16,10 @@ #include "chrome/common/extensions/extension.h" #include "chrome/common/json_value_serializer.h" #include "chrome/common/notification_service.h" -#include "chrome/common/unzip.h" #include "chrome/common/url_constants.h" #include "third_party/skia/include/core/SkBitmap.h" #include "webkit/glue/image_decoder.h" +#include "chrome/common/zip.h" namespace { const char kCurrentVersionFileName[] = "Current Version"; @@ -255,7 +255,7 @@ bool ExtensionUnpacker::Run() { return false; } - if (!Unzip(extension_path_, temp_install_dir_, NULL)) { + if (!Unzip(extension_path_, temp_install_dir_)) { SetError("Couldn't unzip extension."); return false; } diff --git a/chrome/common/unzip.cc b/chrome/common/unzip.cc deleted file mode 100644 index b1062b6..0000000 --- a/chrome/common/unzip.cc +++ /dev/null @@ -1,200 +0,0 @@ -// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "chrome/common/unzip.h" - -#include "base/file_util.h" -#include "base/string_util.h" -#include "net/base/file_stream.h" -#include "third_party/zlib/contrib/minizip/unzip.h" -#if defined(OS_WIN) -#include "third_party/zlib/contrib/minizip/iowin32.h" -#endif - -static const int kZipMaxPath = 256; -static const int kUnzipBufSize = 8192; - -// Extract the 'current' selected file from the zip into dest_dir. -// Output filename is stored in out_file. Returns true on success. -static bool ExtractCurrentFile(unzFile zip_file, - const FilePath& dest_dir, - FilePath* out_file) { - char filename_inzip[kZipMaxPath] = {0}; - unz_file_info file_info; - int err = unzGetCurrentFileInfo(zip_file, &file_info, filename_inzip, - sizeof(filename_inzip), NULL, 0, NULL, 0); - if (err != UNZ_OK) - return false; - if (filename_inzip[0] == '\0') - return false; - - err = unzOpenCurrentFile(zip_file); - if (err != UNZ_OK) - return false; - - FilePath::StringType filename; - std::vector filename_parts; -#if defined(OS_WIN) - filename = UTF8ToWide(filename_inzip); -#elif defined(OS_POSIX) - filename = filename_inzip; -#endif - SplitString(filename, '/', &filename_parts); - - FilePath dest_file(dest_dir); - std::vector::iterator iter; - for (iter = filename_parts.begin(); iter != filename_parts.end(); ++iter) - dest_file = dest_file.Append(*iter); - if (out_file) - *out_file = dest_file; - // If this is a directory, just create it and return. - if (filename_inzip[strlen(filename_inzip) - 1] == '/') { - if (!file_util::CreateDirectory(dest_file)) - return false; - return true; - } - // TODO(erikkay): Can we always count on the directory entry coming before a - // file in that directory? If so, then these three lines can be removed. - FilePath dir = dest_file.DirName(); - if (!file_util::CreateDirectory(dir)) - return false; - - net::FileStream stream; - int flags = base::PLATFORM_FILE_CREATE_ALWAYS | base::PLATFORM_FILE_WRITE; - if (stream.Open(dest_file, flags) != 0) - return false; - - bool ret = true; - int num_bytes = 0; - char buf[kUnzipBufSize]; - do { - num_bytes = unzReadCurrentFile(zip_file, buf, kUnzipBufSize); - if (num_bytes < 0) { - // If num_bytes < 0, then it's a specific UNZ_* error code. - // While we're not currently handling these codes specifically, save - // it away in case we want to in the future. - err = num_bytes; - break; - } - if (num_bytes > 0) { - if (num_bytes != stream.Write(buf, num_bytes, NULL)) { - ret = false; - break; - } - } - } while (num_bytes > 0); - - stream.Close(); - if (err == UNZ_OK) - err = unzCloseCurrentFile(zip_file); - else - unzCloseCurrentFile(zip_file); // Don't lose the original error code. - if (err != UNZ_OK) - ret = false; - return ret; -} - -#if defined(OS_WIN) -typedef struct { - HANDLE hf; - int error; -} WIN32FILE_IOWIN; - -// This function is derived from third_party/minizip/iowin32.c. -// Its only difference is that it treats the char* as UTF8 and -// uses the Unicode version of CreateFile. -static void* UnzipOpenFunc(void *opaque, const char* filename, int mode) { - DWORD desired_access, creation_disposition; - DWORD share_mode, flags_and_attributes; - HANDLE file = 0; - void* ret = NULL; - - desired_access = share_mode = flags_and_attributes = 0; - - if ((mode & ZLIB_FILEFUNC_MODE_READWRITEFILTER) == ZLIB_FILEFUNC_MODE_READ) { - desired_access = GENERIC_READ; - creation_disposition = OPEN_EXISTING; - share_mode = FILE_SHARE_READ; - } else if (mode & ZLIB_FILEFUNC_MODE_EXISTING) { - desired_access = GENERIC_WRITE | GENERIC_READ; - creation_disposition = OPEN_EXISTING; - } else if (mode & ZLIB_FILEFUNC_MODE_CREATE) { - desired_access = GENERIC_WRITE | GENERIC_READ; - creation_disposition = CREATE_ALWAYS; - } - - std::wstring filename_wstr = UTF8ToWide(filename); - if ((filename != NULL) && (desired_access != 0)) { - file = CreateFile(filename_wstr.c_str(), desired_access, share_mode, - NULL, creation_disposition, flags_and_attributes, NULL); - } - - if (file == INVALID_HANDLE_VALUE) - file = NULL; - - if (file != NULL) { - WIN32FILE_IOWIN file_ret; - file_ret.hf = file; - file_ret.error = 0; - ret = malloc(sizeof(WIN32FILE_IOWIN)); - if (ret == NULL) - CloseHandle(file); - else - *(static_cast(ret)) = file_ret; - } - return ret; -} -#endif - -// TODO(erikkay): Make this function asynchronous so that a large zip file -// won't starve the thread it's running on. This won't be entirely possible -// since reads need to be synchronous, but we can at least make writes async. -bool Unzip(const FilePath& zip_path, const FilePath& dest_dir, - std::vector* files) { -#if defined(OS_WIN) - zlib_filefunc_def unzip_funcs; - fill_win32_filefunc(&unzip_funcs); - unzip_funcs.zopen_file = UnzipOpenFunc; -#endif - -#if defined(OS_POSIX) - std::string zip_file_str = zip_path.value(); - unzFile zip_file = unzOpen(zip_file_str.c_str()); -#elif defined(OS_WIN) - std::string zip_file_str = WideToUTF8(zip_path.value()); - unzFile zip_file = unzOpen2(zip_file_str.c_str(), &unzip_funcs); -#endif - if (!zip_file) { - LOG(WARNING) << "couldn't open extension file " << zip_file_str; - return false; - } - unz_global_info zip_info; - int err; - err = unzGetGlobalInfo(zip_file, &zip_info); - if (err != UNZ_OK) { - LOG(WARNING) << "couldn't open extension file " << zip_file_str; - return false; - } - bool ret = true; - for (unsigned int i = 0; i < zip_info.number_entry; ++i) { - FilePath dest_file; - if (!ExtractCurrentFile(zip_file, dest_dir, &dest_file)) { - ret = false; - break; - } - if (files) - files->push_back(dest_file); - - if (i + 1 < zip_info.number_entry) { - err = unzGoToNextFile(zip_file); - if (err != UNZ_OK) { - LOG(WARNING) << "error %d in unzGoToNextFile"; - ret = false; - break; - } - } - } - unzClose(zip_file); - return ret; -} diff --git a/chrome/common/unzip.h b/chrome/common/unzip.h deleted file mode 100644 index 7693185..0000000 --- a/chrome/common/unzip.h +++ /dev/null @@ -1,19 +0,0 @@ -// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef CHROME_COMMON_UNZIP_H_ -#define CHROME_COMMON_UNZIP_H_ - -#include - -#include "base/file_path.h" - -// Unzip the contents of zip_file into dest_dir. The complete paths of all -// created files and directories are added to files if it is non-NULL. -// Returns true on success. Does not clean up dest_dir on failure. -// Does not support encrypted or password protected zip files. -bool Unzip(const FilePath& zip_file, const FilePath& dest_dir, - std::vector* files); - -#endif // CHROME_COMMON_UNZIP_H_ diff --git a/chrome/common/unzip_unittest.cc b/chrome/common/unzip_unittest.cc deleted file mode 100644 index b8382c0..0000000 --- a/chrome/common/unzip_unittest.cc +++ /dev/null @@ -1,93 +0,0 @@ -// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include - -#include "base/file_path.h" -#include "base/file_util.h" -#include "base/path_service.h" -#include "base/string_util.h" -#include "chrome/common/chrome_paths.h" -#include "chrome/common/unzip.h" -#include "testing/gtest/include/gtest/gtest.h" -#include "testing/platform_test.h" - -namespace { - -// Make the test a PlatformTest to setup autorelease pools properly on Mac. -class UnzipTest : public PlatformTest { - protected: - virtual void SetUp() { - PlatformTest::SetUp(); - - ASSERT_TRUE(file_util::CreateNewTempDirectory( - FILE_PATH_LITERAL("unzip_unittest_"), &test_dir_)); - - FilePath zip_path(test_dir_.AppendASCII("test")); - zip_contents_.insert(zip_path); - zip_contents_.insert(zip_path.AppendASCII("foo.txt")); - zip_path = zip_path.AppendASCII("foo"); - zip_contents_.insert(zip_path); - zip_contents_.insert(zip_path.AppendASCII("bar.txt")); - zip_path = zip_path.AppendASCII("bar"); - zip_contents_.insert(zip_path); - zip_contents_.insert(zip_path.AppendASCII("baz.txt")); - zip_contents_.insert(zip_path.AppendASCII("quux.txt")); - zip_path = zip_path.AppendASCII("baz"); - zip_contents_.insert(zip_path); - } - - virtual void TearDown() { - PlatformTest::TearDown(); - // Clean up test directory - ASSERT_TRUE(file_util::Delete(test_dir_, true)); - ASSERT_FALSE(file_util::PathExists(test_dir_)); - } - - void TestZipFile(const FilePath::StringType& filename) { - FilePath test_dir; - ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &test_dir)); - test_dir = test_dir.AppendASCII("unzip"); - FilePath path = test_dir.Append(filename); - - ASSERT_TRUE(file_util::PathExists(path)) << "no file " << path.value(); - std::vector out_files; - ASSERT_TRUE(Unzip(path, test_dir_, &out_files)); - - file_util::FileEnumerator files(test_dir_, true, - file_util::FileEnumerator::FILES_AND_DIRECTORIES); - FilePath next_path = files.Next(); - size_t count = 0; - while (!next_path.value().empty()) { - EXPECT_EQ(zip_contents_.count(next_path), 1U) << - "Couldn't find " << next_path.value(); - count++; - next_path = files.Next(); - } - EXPECT_EQ(count, zip_contents_.size()); - EXPECT_EQ(count, out_files.size()); - std::vector::iterator iter; - for (iter = out_files.begin(); iter != out_files.end(); ++iter) { - EXPECT_EQ(zip_contents_.count(*iter), 1U) << - "Couldn't find " << (*iter).value(); - } - } - - // the path to temporary directory used to contain the test operations - FilePath test_dir_; - - // hard-coded contents of a known zip file - std::set zip_contents_; -}; - - -TEST_F(UnzipTest, Unzip) { - TestZipFile(FILE_PATH_LITERAL("test.zip")); -} - -TEST_F(UnzipTest, UnzipUncompressed) { - TestZipFile(FILE_PATH_LITERAL("test_nocompress.zip")); -} - -} // namespace diff --git a/chrome/common/zip.cc b/chrome/common/zip.cc new file mode 100644 index 0000000..8ffd12c --- /dev/null +++ b/chrome/common/zip.cc @@ -0,0 +1,299 @@ +// Copyright (c) 2009 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "chrome/common/zip.h" + +#include "base/file_util.h" +#include "base/string_util.h" +#include "net/base/file_stream.h" +#include "third_party/zlib/contrib/minizip/unzip.h" +#include "third_party/zlib/contrib/minizip/zip.h" +#if defined(OS_WIN) +#include "third_party/zlib/contrib/minizip/iowin32.h" +#endif + +static const int kZipMaxPath = 256; +static const int kZipBufSize = 8192; + +// Extract the 'current' selected file from the zip into dest_dir. +// Output filename is stored in out_file. Returns true on success. +static bool ExtractCurrentFile(unzFile zip_file, + const FilePath& dest_dir) { + char filename_inzip[kZipMaxPath] = {0}; + unz_file_info file_info; + int err = unzGetCurrentFileInfo(zip_file, &file_info, filename_inzip, + sizeof(filename_inzip), NULL, 0, NULL, 0); + if (err != UNZ_OK) + return false; + if (filename_inzip[0] == '\0') + return false; + + err = unzOpenCurrentFile(zip_file); + if (err != UNZ_OK) + return false; + + FilePath::StringType filename; + std::vector filename_parts; +#if defined(OS_WIN) + filename = UTF8ToWide(filename_inzip); +#elif defined(OS_POSIX) + filename = filename_inzip; +#endif + SplitString(filename, '/', &filename_parts); + + FilePath dest_file(dest_dir); + std::vector::iterator iter; + for (iter = filename_parts.begin(); iter != filename_parts.end(); ++iter) + dest_file = dest_file.Append(*iter); + + // If this is a directory, just create it and return. + if (filename_inzip[strlen(filename_inzip) - 1] == '/') { + if (!file_util::CreateDirectory(dest_file)) + return false; + return true; + } + + // We can't rely on parent directory entries being specified in the zip, so we + // make sure they are created. + FilePath dir = dest_file.DirName(); + if (!file_util::CreateDirectory(dir)) + return false; + + net::FileStream stream; + int flags = base::PLATFORM_FILE_CREATE_ALWAYS | base::PLATFORM_FILE_WRITE; + if (stream.Open(dest_file, flags) != 0) + return false; + + bool ret = true; + int num_bytes = 0; + char buf[kZipBufSize]; + do { + num_bytes = unzReadCurrentFile(zip_file, buf, kZipBufSize); + if (num_bytes < 0) { + // If num_bytes < 0, then it's a specific UNZ_* error code. + // While we're not currently handling these codes specifically, save + // it away in case we want to in the future. + err = num_bytes; + break; + } + if (num_bytes > 0) { + if (num_bytes != stream.Write(buf, num_bytes, NULL)) { + ret = false; + break; + } + } + } while (num_bytes > 0); + + stream.Close(); + if (err == UNZ_OK) + err = unzCloseCurrentFile(zip_file); + else + unzCloseCurrentFile(zip_file); // Don't lose the original error code. + if (err != UNZ_OK) + ret = false; + return ret; +} + +#if defined(OS_WIN) +typedef struct { + HANDLE hf; + int error; +} WIN32FILE_IOWIN; + +// This function is derived from third_party/minizip/iowin32.c. +// Its only difference is that it treats the char* as UTF8 and +// uses the Unicode version of CreateFile. +static void* ZipOpenFunc(void *opaque, const char* filename, int mode) { + DWORD desired_access, creation_disposition; + DWORD share_mode, flags_and_attributes; + HANDLE file = 0; + void* ret = NULL; + + desired_access = share_mode = flags_and_attributes = 0; + + if ((mode & ZLIB_FILEFUNC_MODE_READWRITEFILTER) == ZLIB_FILEFUNC_MODE_READ) { + desired_access = GENERIC_READ; + creation_disposition = OPEN_EXISTING; + share_mode = FILE_SHARE_READ; + } else if (mode & ZLIB_FILEFUNC_MODE_EXISTING) { + desired_access = GENERIC_WRITE | GENERIC_READ; + creation_disposition = OPEN_EXISTING; + } else if (mode & ZLIB_FILEFUNC_MODE_CREATE) { + desired_access = GENERIC_WRITE | GENERIC_READ; + creation_disposition = CREATE_ALWAYS; + } + + std::wstring filename_wstr = UTF8ToWide(filename); + if ((filename != NULL) && (desired_access != 0)) { + file = CreateFile(filename_wstr.c_str(), desired_access, share_mode, + NULL, creation_disposition, flags_and_attributes, NULL); + } + + if (file == INVALID_HANDLE_VALUE) + file = NULL; + + if (file != NULL) { + WIN32FILE_IOWIN file_ret; + file_ret.hf = file; + file_ret.error = 0; + ret = malloc(sizeof(WIN32FILE_IOWIN)); + if (ret == NULL) + CloseHandle(file); + else + *(static_cast(ret)) = file_ret; + } + return ret; +} +#endif + +bool Unzip(const FilePath& src_file, const FilePath& dest_dir) { +#if defined(OS_WIN) + zlib_filefunc_def zip_funcs; + fill_win32_filefunc(&zip_funcs); + zip_funcs.zopen_file = ZipOpenFunc; +#endif + +#if defined(OS_POSIX) + std::string src_file_str = src_file.value(); + unzFile zip_file = unzOpen(src_file_str.c_str()); +#elif defined(OS_WIN) + std::string src_file_str = WideToUTF8(src_file.value()); + unzFile zip_file = unzOpen2(src_file_str.c_str(), &zip_funcs); +#endif + if (!zip_file) { + LOG(WARNING) << "couldn't create file " << src_file_str; + return false; + } + unz_global_info zip_info; + int err; + err = unzGetGlobalInfo(zip_file, &zip_info); + if (err != UNZ_OK) { + LOG(WARNING) << "couldn't open zip " << src_file_str; + return false; + } + bool ret = true; + for (unsigned int i = 0; i < zip_info.number_entry; ++i) { + if (!ExtractCurrentFile(zip_file, dest_dir)) { + ret = false; + break; + } + + if (i + 1 < zip_info.number_entry) { + err = unzGoToNextFile(zip_file); + if (err != UNZ_OK) { + LOG(WARNING) << "error %d in unzGoToNextFile"; + ret = false; + break; + } + } + } + unzClose(zip_file); + return ret; +} + +static bool AddFileToZip(zipFile zip_file, const FilePath& src_dir) { + net::FileStream stream; + int flags = base::PLATFORM_FILE_OPEN | base::PLATFORM_FILE_READ; + if (stream.Open(src_dir, flags) != 0) { + LOG(ERROR) << "Could not open stream for path " + << WideToASCII(src_dir.ToWStringHack()); + return false; + } + + int num_bytes; + char buf[kZipBufSize]; + do { + num_bytes = stream.Read(buf, kZipBufSize, NULL); + if (num_bytes > 0) { + if (ZIP_OK != zipWriteInFileInZip(zip_file, buf, num_bytes)) { + LOG(ERROR) << "Could not write data to zip for path " + << WideToASCII(src_dir.ToWStringHack()); + return false; + } + } + } while (num_bytes > 0); + + return true; +} + +static bool AddEntryToZip(zipFile zip_file, const FilePath& path, + const FilePath& root_path) { +#if defined(OS_WIN) + std::string str_path = + WideToUTF8(path.value().substr(root_path.value().length() + 1)); + ReplaceSubstringsAfterOffset(&str_path, 0u, "\\", "/"); +#else + std::string str_path = path.value().substr(root_path.value().length() + 1); +#endif + + bool is_directory = file_util::DirectoryExists(path); + if (is_directory) + str_path += "/"; + + if (ZIP_OK != zipOpenNewFileInZip( + zip_file, str_path.c_str(), + NULL, NULL, 0u, NULL, 0u, NULL, // file info, extrafield local, length, + // extrafield global, length, comment + Z_DEFLATED, Z_DEFAULT_COMPRESSION)) { + LOG(ERROR) << "Could not open zip file entry " << str_path; + return false; + } + + bool success = true; + if (!is_directory) { + success = AddFileToZip(zip_file, path); + } + + if (ZIP_OK != zipCloseFileInZip(zip_file)) { + LOG(ERROR) << "Could not close zip file entry " << str_path; + return false; + } + + return success; +} + +bool Zip(const FilePath& src_dir, const FilePath& dest_file) { + DCHECK(file_util::DirectoryExists(src_dir)); + +#if defined(OS_WIN) + zlib_filefunc_def zip_funcs; + fill_win32_filefunc(&zip_funcs); + zip_funcs.zopen_file = ZipOpenFunc; +#endif + +#if defined(OS_POSIX) + std::string dest_file_str = dest_file.value(); + std::string src_dir_str = src_dir.value(); + zipFile zip_file = zipOpen(src_dir_str.c_str(), APPEND_STATUS_CREATE); +#elif defined(OS_WIN) + std::string dest_file_str = WideToUTF8(dest_file.value()); + zipFile zip_file = zipOpen2(dest_file_str.c_str(), APPEND_STATUS_CREATE, + NULL, // global comment + &zip_funcs); +#endif + + if (!zip_file) { + LOG(WARNING) << "couldn't create file " << dest_file_str; + return false; + } + + bool success = true; + file_util::FileEnumerator file_enumerator( + src_dir, true, // recursive + file_util::FileEnumerator::FILES_AND_DIRECTORIES); + for (FilePath path = file_enumerator.Next(); !path.value().empty(); + path = file_enumerator.Next()) { + if (!AddEntryToZip(zip_file, path, src_dir)) { + success = false; + return false; + } + } + + if (ZIP_OK != zipClose(zip_file, NULL)) { // global comment + LOG(ERROR) << "Error closing zip file " << dest_file_str; + return false; + } + + return success; +} diff --git a/chrome/common/zip.h b/chrome/common/zip.h new file mode 100644 index 0000000..23823d8 --- /dev/null +++ b/chrome/common/zip.h @@ -0,0 +1,20 @@ +// Copyright (c) 2009 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef CHROME_COMMON_ZIP_H_ +#define CHROME_COMMON_ZIP_H_ + +#include + +#include "base/file_path.h" + +// Zip the contents of src_dir into dest_file. src_path must be a directory. +// An entry will *not* be created in the zip for the root folder -- children +// of src_dir will be at the root level of the created zip. +bool Zip(const FilePath& src_dir, const FilePath& dest_file); + +// Unzip the contents of zip_file into dest_dir. +bool Unzip(const FilePath& zip_file, const FilePath& dest_dir); + +#endif // CHROME_COMMON_ZIP_H_ diff --git a/chrome/common/zip_unittest.cc b/chrome/common/zip_unittest.cc new file mode 100644 index 0000000..cf46318 --- /dev/null +++ b/chrome/common/zip_unittest.cc @@ -0,0 +1,105 @@ +// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include + +#include "base/file_path.h" +#include "base/file_util.h" +#include "base/path_service.h" +#include "base/string_util.h" +#include "chrome/common/chrome_paths.h" +#include "chrome/common/zip.h" +#include "testing/gtest/include/gtest/gtest.h" +#include "testing/platform_test.h" + +namespace { + +// Make the test a PlatformTest to setup autorelease pools properly on Mac. +class ZipTest : public PlatformTest { + protected: + virtual void SetUp() { + PlatformTest::SetUp(); + + ASSERT_TRUE(file_util::CreateNewTempDirectory( + FILE_PATH_LITERAL("unzip_unittest_"), &test_dir_)); + + FilePath zip_path(test_dir_); + zip_contents_.insert(zip_path.AppendASCII("foo.txt")); + zip_path = zip_path.AppendASCII("foo"); + zip_contents_.insert(zip_path); + zip_contents_.insert(zip_path.AppendASCII("bar.txt")); + zip_path = zip_path.AppendASCII("bar"); + zip_contents_.insert(zip_path); + zip_contents_.insert(zip_path.AppendASCII("baz.txt")); + zip_contents_.insert(zip_path.AppendASCII("quux.txt")); + zip_path = zip_path.AppendASCII("baz"); + zip_contents_.insert(zip_path); + } + + virtual void TearDown() { + PlatformTest::TearDown(); + // Clean up test directory + ASSERT_TRUE(file_util::Delete(test_dir_, true)); + ASSERT_FALSE(file_util::PathExists(test_dir_)); + } + + void TestUnzipFile(const FilePath::StringType& filename) { + FilePath test_dir; + ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &test_dir)); + test_dir = test_dir.AppendASCII("zip"); + TestUnzipFile(test_dir.Append(filename)); + } + + void TestUnzipFile(const FilePath& path) { + ASSERT_TRUE(file_util::PathExists(path)) << "no file " << path.value(); + ASSERT_TRUE(Unzip(path, test_dir_)); + + file_util::FileEnumerator files(test_dir_, true, + file_util::FileEnumerator::FILES_AND_DIRECTORIES); + FilePath next_path = files.Next(); + size_t count = 0; + while (!next_path.value().empty()) { + EXPECT_EQ(zip_contents_.count(next_path), 1U) << + "Couldn't find " << next_path.value(); + count++; + next_path = files.Next(); + } + EXPECT_EQ(count, zip_contents_.size()); + } + + // the path to temporary directory used to contain the test operations + FilePath test_dir_; + + // hard-coded contents of a known zip file + std::set zip_contents_; +}; + + +TEST_F(ZipTest, Unzip) { + TestUnzipFile(FILE_PATH_LITERAL("test.zip")); +} + +TEST_F(ZipTest, UnzipUncompressed) { + TestUnzipFile(FILE_PATH_LITERAL("test_nocompress.zip")); +} + + +TEST_F(ZipTest, Zip) { + FilePath src_dir; + ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &src_dir)); + src_dir = src_dir.AppendASCII("zip").AppendASCII("test"); + + FilePath zip_file; + ASSERT_TRUE(file_util::CreateNewTempDirectory( + FILE_PATH_LITERAL("unzip_unittest_"), &zip_file)); + zip_file = zip_file.AppendASCII("out.zip"); + + EXPECT_TRUE(Zip(src_dir, zip_file)); + + TestUnzipFile(zip_file); + + EXPECT_TRUE(file_util::Delete(zip_file, false)); +} + +} // namespace diff --git a/chrome/test/data/unzip/test.zip b/chrome/test/data/unzip/test.zip deleted file mode 100644 index 737d119..0000000 Binary files a/chrome/test/data/unzip/test.zip and /dev/null differ diff --git a/chrome/test/data/unzip/test/foo.txt b/chrome/test/data/unzip/test/foo.txt deleted file mode 100644 index 257cc56..0000000 --- a/chrome/test/data/unzip/test/foo.txt +++ /dev/null @@ -1 +0,0 @@ -foo diff --git a/chrome/test/data/unzip/test/foo/bar.txt b/chrome/test/data/unzip/test/foo/bar.txt deleted file mode 100644 index 5716ca5..0000000 --- a/chrome/test/data/unzip/test/foo/bar.txt +++ /dev/null @@ -1 +0,0 @@ -bar diff --git a/chrome/test/data/unzip/test/foo/bar/baz.txt b/chrome/test/data/unzip/test/foo/bar/baz.txt deleted file mode 100644 index 7601807..0000000 --- a/chrome/test/data/unzip/test/foo/bar/baz.txt +++ /dev/null @@ -1 +0,0 @@ -baz diff --git a/chrome/test/data/unzip/test/foo/bar/quux.txt b/chrome/test/data/unzip/test/foo/bar/quux.txt deleted file mode 100644 index 4797879..0000000 --- a/chrome/test/data/unzip/test/foo/bar/quux.txt +++ /dev/null @@ -1,39 +0,0 @@ -Lorem ipsum dolor sit amet, consectetur adipiscing elit. In sem urna, semper ac, adipiscing sed, varius eget, quam. Fusce ipsum dolor, condimentum et, ornare in, consequat ac, nulla. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. Nulla feugiat justo ac enim. Ut vehicula dapibus elit. Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Aliquam lacus sem, viverra in, laoreet quis, cursus non, odio. Maecenas in elit. Pellentesque vitae dui. Ut dictum tellus et orci. Sed consectetur. Fusce tincidunt. Cras vulputate adipiscing metus. Aliquam lacinia. Vestibulum leo. Donec enim. Etiam imperdiet libero. Nam tellus ante, lobortis eget, dapibus vel, accumsan ultricies, nibh. In ultrices mauris at est. - -Phasellus ac elit sit amet felis aliquet venenatis. Sed porta libero at massa. Fusce blandit diam eget lorem. Nullam velit diam, fermentum eget, scelerisque non, faucibus a, tellus. Ut accumsan eros vitae velit. Proin vehicula aliquam felis. Proin ligula augue, gravida a, fermentum sit amet, sodales ac, purus. Phasellus sagittis scelerisque tellus. Ut gravida metus quis enim. Curabitur malesuada orci in massa. Pellentesque nibh turpis, adipiscing vel, rutrum quis, rhoncus vel, dolor. Pellentesque suscipit, arcu in egestas semper, lorem sapien vehicula nunc, non scelerisque lectus ante at diam. Etiam varius leo. Sed dictum, ante sed imperdiet ornare, felis leo lobortis eros, eu tincidunt lorem tellus sit amet mi. Mauris nisl elit, placerat non, scelerisque id, congue non, ligula. Nulla eget mi eu dolor scelerisque tempor. Fusce non lorem vel nibh mattis blandit. - -Vivamus sit amet urna quis eros varius condimentum. Phasellus placerat ligula ac felis. Vivamus tempor, metus id fermentum feugiat, justo ligula malesuada nisl, ut vulputate nisi arcu in eros. Vestibulum non erat in massa laoreet luctus. Praesent tempor, tortor eget sodales condimentum, purus odio gravida tellus, pellentesque euismod enim diam id augue. Duis malesuada lacus eu felis. Suspendisse tristique faucibus arcu. Etiam ac sapien. Aenean dolor enim, semper auctor, dapibus cursus, varius et, arcu. Aenean pede nunc, varius nec, pulvinar a, accumsan id, dui. Nulla a risus eget nibh pharetra rutrum. Quisque adipiscing adipiscing neque. Praesent faucibus lacus eu nulla. Vestibulum nec nunc vel quam cursus sollicitudin. Nam at quam at neque pharetra elementum. Sed ornare ullamcorper nibh. - -Aliquam aliquam vulputate diam. Ut molestie pharetra neque. Pellentesque sodales blandit nibh. Donec eget mauris eget mauris blandit pharetra. Etiam imperdiet commodo tellus. Nulla felis justo, vestibulum hendrerit, posuere vitae, viverra ut, risus. Pellentesque auctor, ante egestas suscipit vestibulum, sem dolor posuere urna, pellentesque dignissim ante orci a lectus. Suspendisse potenti. Sed et pede pretium arcu porttitor porta. Nullam nec nulla. Fusce lacinia, massa ac fermentum congue, dui quam varius mauris, vitae ullamcorper pede lacus at nisl. Suspendisse aliquam pede a sapien. Morbi pellentesque, mi id mattis aliquet, nisl erat tincidunt lorem, eu bibendum nunc nisi nec erat. Suspendisse commodo dapibus dolor. Quisque id risus. Nullam gravida est tempor lectus. - -Morbi mattis. Cras sagittis. Sed eleifend odio sit amet nibh. Cras sit amet massa. Donec congue nulla vel augue. Maecenas fermentum turpis at diam. In lobortis. Phasellus aliquet. Etiam eu diam. Integer accumsan. Integer sagittis tempor mi. Aliquam interdum lectus id augue. Donec vel eros. Donec vitae orci a sapien imperdiet consectetur. - -Maecenas est lorem, luctus vel, fringilla sed, rutrum nec, nisl. Donec sapien. Vestibulum at metus. Praesent erat. Nulla semper metus a lacus. Morbi ultrices. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae; Vivamus odio. Ut mauris. Fusce et risus. Proin at mauris a eros imperdiet mollis. Sed adipiscing hendrerit nisl. Curabitur libero. Donec nulla. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. - -Nullam non lacus. Vivamus rhoncus dolor sit amet ipsum. Vivamus volutpat eleifend odio. Vestibulum nunc. In at magna a pede gravida vulputate. Praesent ligula tellus, rhoncus elementum, pulvinar a, condimentum vitae, libero. Donec ornare dui. Proin non lorem quis massa placerat interdum. Nam justo. Aliquam rutrum dignissim mi. Mauris tellus. Proin dui felis, lacinia quis, volutpat a, blandit sed, neque. Etiam non dolor eu justo interdum tristique. Morbi volutpat, elit vitae rutrum iaculis, augue mi accumsan metus, sed porttitor felis mi sed felis. - -Nulla quam lectus, pharetra non, sodales sit amet, pretium quis, massa. Aliquam orci. Duis id massa. Pellentesque porttitor nibh id quam. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae; Donec convallis, pede vitae volutpat consequat, justo lorem ultricies nisi, ut scelerisque leo lorem in tellus. Cras bibendum. Sed hendrerit placerat tortor. Sed felis. Aliquam erat volutpat. Praesent rhoncus nisi. Vestibulum justo felis, tincidunt luctus, suscipit sed, tincidunt ut, lorem. Proin non risus ac mi mattis volutpat. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. Nam pellentesque nisl sit amet sapien rutrum porta. - -Phasellus ut pede non odio ultricies egestas. Aenean nibh. Mauris magna felis, posuere non, tempus et, bibendum ut, felis. Donec vel ipsum ac nisi dapibus lobortis. Sed congue ligula at est. Vivamus elit est, rhoncus vitae, tempus at, consectetur nec, elit. Duis vehicula tellus vitae sem. Suspendisse rhoncus felis sit amet magna. Maecenas vulputate risus in diam. Nunc sollicitudin risus eget quam. Nam pretium purus eleifend dolor. Integer erat nulla, mattis eu, sollicitudin sed, sagittis nec, metus. - -Donec ante felis, ultrices nec, pellentesque nec, elementum et, nunc. Pellentesque in tortor sit amet urna aliquet tincidunt. Praesent ultrices. Sed tincidunt. Donec turpis enim, feugiat eu, cursus ut, viverra ut, odio. Morbi in orci quis enim vehicula lobortis. Proin in neque. Pellentesque venenatis neque sit amet augue. Proin suscipit nibh. Praesent et diam. - -In eget ligula quis libero vulputate eleifend. Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae; Nunc non urna vitae mi vulputate adipiscing. Nulla vitae arcu. Nullam ut nisl ac enim pulvinar auctor. Suspendisse tortor pede, consectetur in, volutpat at, condimentum vel, ligula. Pellentesque nisi est, vulputate vitae, hendrerit id, venenatis sit amet, urna. Nunc lobortis. Sed rhoncus, tortor vitae pellentesque facilisis, massa ante interdum massa, feugiat faucibus pede nunc et tellus. Quisque auctor sollicitudin nibh. Aliquam congue. Praesent ullamcorper mi id lacus. Nullam ac risus et velit ullamcorper vehicula. Vestibulum consectetur convallis neque. Donec dapibus, ante a rutrum interdum, mi dui auctor lacus, quis posuere eros diam eu nisl. Integer nec velit vel purus eleifend condimentum. Cras quis nunc. Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. - -Sed euismod, metus eu consectetur dictum, felis eros sodales pede, ac pellentesque lacus orci sed velit. Praesent a justo. Aliquam massa dolor, condimentum non, dapibus quis, vestibulum a, purus. Duis gravida porta dolor. Nullam sit amet mi sagittis massa pretium ultricies. Ut fringilla. Aliquam venenatis feugiat dui. Pellentesque tempor, leo et ullamcorper placerat, felis libero blandit nisl, sit amet pharetra nisl erat sit amet dolor. In sem erat, porta rhoncus, auctor ac, convallis feugiat, dui. Sed tempus metus at erat. Cras gravida. Cras urna nisi, fermentum non, sodales sed, adipiscing sed, nulla. - -Donec pellentesque, velit sit amet ultricies dictum, sem quam posuere arcu, tristique mollis nibh dui ac libero. Vestibulum consectetur velit sed dolor. Nullam ornare sodales nisi. Sed facilisis sollicitudin arcu. Proin vitae lectus vel nulla auctor faucibus. Aenean nec nisl sit amet risus faucibus tincidunt. Ut sed nisl. Vivamus vehicula ligula a nunc. Curabitur mauris. Integer est felis, fermentum aliquam, dignissim id, gravida id, purus. Nullam porta felis eget ante. Phasellus lacinia, odio et elementum viverra, dui neque tempus massa, ac adipiscing lectus velit vitae turpis. Integer scelerisque neque in tortor. Duis et elit. Mauris elementum urna sed risus. Nunc aliquet, ipsum ac venenatis elementum, sapien orci vulputate lacus, eu lobortis sapien lorem non enim. Donec enim sapien, gravida vitae, vestibulum et, mattis dapibus, sem. Phasellus mi. - -Cras a lorem nec diam aliquet viverra. Aliquam sed leo sit amet neque porta venenatis. Nulla facilisi. Duis lectus felis, fermentum quis, sagittis a, vestibulum consectetur, orci. Suspendisse sodales odio vitae lectus. Curabitur nunc. Phasellus cursus diam sit amet ipsum. Aenean cursus tellus eget nunc. Vivamus mattis urna a lorem. Mauris vitae mi. Morbi luctus molestie pede. Vestibulum lobortis lacus sed lacus. Aliquam nisl libero, pellentesque sed, facilisis ut, varius vehicula, lacus. Mauris orci. Pellentesque sed risus id quam sodales lobortis. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Sed facilisis, odio vitae laoreet auctor, nulla dui sagittis lectus, sit amet viverra orci arcu et lectus. Pellentesque ut sem. Maecenas a est. - -Suspendisse tincidunt. Sed bibendum molestie ligula. Suspendisse massa mauris, cursus a, luctus eget, posuere sed, nulla. Fusce vitae urna. Duis fermentum. Donec a neque ac pede lobortis mollis. Donec massa ligula, facilisis et, dapibus sed, ultrices non, sem. Phasellus diam. Maecenas velit arcu, viverra ut, gravida ac, tincidunt eget, nunc. Sed sit amet enim non dui tristique lacinia. Vivamus eu orci. Duis metus. Nulla facilisi. Phasellus at lectus. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae; Vivamus mauris. Duis dictum, erat eu scelerisque sollicitudin, mi augue tincidunt lorem, vel lacinia lectus nibh quis dui. Ut ornare dignissim elit. Phasellus posuere ligula vel justo. - -Sed neque. Quisque porttitor lorem vel arcu. Praesent a mi et risus suscipit egestas. Proin est lectus, rhoncus sit amet, aliquet non, fermentum ut, nulla. Aenean erat nisl, rutrum dictum, placerat vel, malesuada ac, arcu. Suspendisse posuere, ante sed consequat gravida, velit mi dignissim sem, et pretium dui diam in elit. Sed dictum nulla. Duis tristique tincidunt eros. Morbi velit. Donec a lorem. Aliquam cursus. Vivamus dapibus varius neque. Quisque eget diam. Nulla facilisi. Pellentesque eu sapien. Curabitur egestas cursus risus. Proin odio tortor, interdum eget, fringilla venenatis, luctus et, turpis. Phasellus nulla lorem, ullamcorper ut, elementum rhoncus, ultrices sed, ipsum. Nam volutpat. - -Quisque eu purus. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. Curabitur non nulla. Donec dignissim porta lorem. Mauris ornare venenatis odio. Aenean eu lectus at eros porta molestie. Vivamus neque. Morbi aliquam. Nulla tincidunt enim id ligula. Nunc gravida felis consectetur dolor. Phasellus tempus. Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Nulla nec libero quis ipsum auctor vehicula. Maecenas consectetur tempor turpis. Integer commodo. In hac habitasse platea dictumst. Donec nec justo quis sem placerat gravida. Donec sollicitudin, turpis sit amet bibendum elementum, nisl ligula venenatis ipsum, vel sollicitudin justo arcu eu leo. Phasellus aliquet faucibus libero. - -Nam molestie nulla eu risus. Fusce id erat. Maecenas volutpat nunc eu ligula. Sed tortor est, imperdiet quis, viverra et, ornare in, ipsum. Praesent aliquet. Nulla suscipit. In posuere enim in odio. Nullam ante ipsum, imperdiet id, convallis id, hendrerit id, libero. Donec convallis libero ut felis. Curabitur venenatis placerat justo. Vestibulum mauris arcu, scelerisque et, dapibus vel, scelerisque a, lectus. Sed sit amet orci id felis tristique tincidunt. Curabitur adipiscing, nulla vel pretium tristique, tellus ipsum lacinia eros, vitae venenatis pede lectus sit amet neque. Nulla feugiat. Aenean euismod, nunc vel rutrum mattis, lorem purus venenatis sapien, sed facilisis pede enim at elit. Vivamus viverra. Cras vitae purus ac felis fringilla condimentum. Nullam ac nisi vitae massa faucibus aliquet. - -Etiam ut nibh nec neque elementum iaculis. Maecenas facilisis nulla at lorem. Pellentesque elit sapien, ultricies at, dignissim nec, cursus eu, pede. Morbi gravida, ipsum eget malesuada eleifend, est arcu pulvinar nisl, et fermentum urna felis sed tellus. Mauris fermentum sollicitudin neque. Nunc at odio. Pellentesque et turpis. Cras congue congue nisi. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Etiam feugiat dapibus tellus. Aenean aliquam, mi id interdum feugiat, nunc lorem laoreet massa, ac semper urna sem vel purus. Quisque bibendum tellus ut est. - -Morbi aliquam lectus sit amet nisi. Praesent urna purus, porttitor vitae, accumsan in, sollicitudin at, lorem. Donec diam dui, hendrerit eget, tincidunt ut, ultrices vehicula, dolor. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aliquam erat volutpat. Pellentesque iaculis iaculis lacus. Fusce auctor. Morbi vulputate purus at felis. Maecenas a pede nec metus vulputate ullamcorper. Cras non lectus. Suspendisse lacinia. diff --git a/chrome/test/data/unzip/test_nocompress.zip b/chrome/test/data/unzip/test_nocompress.zip deleted file mode 100644 index ac30bbc..0000000 Binary files a/chrome/test/data/unzip/test_nocompress.zip and /dev/null differ diff --git a/chrome/test/data/zip/test.zip b/chrome/test/data/zip/test.zip new file mode 100755 index 0000000..dec8b2a Binary files /dev/null and b/chrome/test/data/zip/test.zip differ diff --git a/chrome/test/data/zip/test/foo.txt b/chrome/test/data/zip/test/foo.txt new file mode 100644 index 0000000..257cc56 --- /dev/null +++ b/chrome/test/data/zip/test/foo.txt @@ -0,0 +1 @@ +foo diff --git a/chrome/test/data/zip/test/foo/bar.txt b/chrome/test/data/zip/test/foo/bar.txt new file mode 100644 index 0000000..5716ca5 --- /dev/null +++ b/chrome/test/data/zip/test/foo/bar.txt @@ -0,0 +1 @@ +bar diff --git a/chrome/test/data/zip/test/foo/bar/baz.txt b/chrome/test/data/zip/test/foo/bar/baz.txt new file mode 100644 index 0000000..7601807 --- /dev/null +++ b/chrome/test/data/zip/test/foo/bar/baz.txt @@ -0,0 +1 @@ +baz diff --git a/chrome/test/data/zip/test/foo/bar/quux.txt b/chrome/test/data/zip/test/foo/bar/quux.txt new file mode 100644 index 0000000..4797879 --- /dev/null +++ b/chrome/test/data/zip/test/foo/bar/quux.txt @@ -0,0 +1,39 @@ +Lorem ipsum dolor sit amet, consectetur adipiscing elit. In sem urna, semper ac, adipiscing sed, varius eget, quam. Fusce ipsum dolor, condimentum et, ornare in, consequat ac, nulla. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. Nulla feugiat justo ac enim. Ut vehicula dapibus elit. Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Aliquam lacus sem, viverra in, laoreet quis, cursus non, odio. Maecenas in elit. Pellentesque vitae dui. Ut dictum tellus et orci. Sed consectetur. Fusce tincidunt. Cras vulputate adipiscing metus. Aliquam lacinia. Vestibulum leo. Donec enim. Etiam imperdiet libero. Nam tellus ante, lobortis eget, dapibus vel, accumsan ultricies, nibh. In ultrices mauris at est. + +Phasellus ac elit sit amet felis aliquet venenatis. Sed porta libero at massa. Fusce blandit diam eget lorem. Nullam velit diam, fermentum eget, scelerisque non, faucibus a, tellus. Ut accumsan eros vitae velit. Proin vehicula aliquam felis. Proin ligula augue, gravida a, fermentum sit amet, sodales ac, purus. Phasellus sagittis scelerisque tellus. Ut gravida metus quis enim. Curabitur malesuada orci in massa. Pellentesque nibh turpis, adipiscing vel, rutrum quis, rhoncus vel, dolor. Pellentesque suscipit, arcu in egestas semper, lorem sapien vehicula nunc, non scelerisque lectus ante at diam. Etiam varius leo. Sed dictum, ante sed imperdiet ornare, felis leo lobortis eros, eu tincidunt lorem tellus sit amet mi. Mauris nisl elit, placerat non, scelerisque id, congue non, ligula. Nulla eget mi eu dolor scelerisque tempor. Fusce non lorem vel nibh mattis blandit. + +Vivamus sit amet urna quis eros varius condimentum. Phasellus placerat ligula ac felis. Vivamus tempor, metus id fermentum feugiat, justo ligula malesuada nisl, ut vulputate nisi arcu in eros. Vestibulum non erat in massa laoreet luctus. Praesent tempor, tortor eget sodales condimentum, purus odio gravida tellus, pellentesque euismod enim diam id augue. Duis malesuada lacus eu felis. Suspendisse tristique faucibus arcu. Etiam ac sapien. Aenean dolor enim, semper auctor, dapibus cursus, varius et, arcu. Aenean pede nunc, varius nec, pulvinar a, accumsan id, dui. Nulla a risus eget nibh pharetra rutrum. Quisque adipiscing adipiscing neque. Praesent faucibus lacus eu nulla. Vestibulum nec nunc vel quam cursus sollicitudin. Nam at quam at neque pharetra elementum. Sed ornare ullamcorper nibh. + +Aliquam aliquam vulputate diam. Ut molestie pharetra neque. Pellentesque sodales blandit nibh. Donec eget mauris eget mauris blandit pharetra. Etiam imperdiet commodo tellus. Nulla felis justo, vestibulum hendrerit, posuere vitae, viverra ut, risus. Pellentesque auctor, ante egestas suscipit vestibulum, sem dolor posuere urna, pellentesque dignissim ante orci a lectus. Suspendisse potenti. Sed et pede pretium arcu porttitor porta. Nullam nec nulla. Fusce lacinia, massa ac fermentum congue, dui quam varius mauris, vitae ullamcorper pede lacus at nisl. Suspendisse aliquam pede a sapien. Morbi pellentesque, mi id mattis aliquet, nisl erat tincidunt lorem, eu bibendum nunc nisi nec erat. Suspendisse commodo dapibus dolor. Quisque id risus. Nullam gravida est tempor lectus. + +Morbi mattis. Cras sagittis. Sed eleifend odio sit amet nibh. Cras sit amet massa. Donec congue nulla vel augue. Maecenas fermentum turpis at diam. In lobortis. Phasellus aliquet. Etiam eu diam. Integer accumsan. Integer sagittis tempor mi. Aliquam interdum lectus id augue. Donec vel eros. Donec vitae orci a sapien imperdiet consectetur. + +Maecenas est lorem, luctus vel, fringilla sed, rutrum nec, nisl. Donec sapien. Vestibulum at metus. Praesent erat. Nulla semper metus a lacus. Morbi ultrices. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae; Vivamus odio. Ut mauris. Fusce et risus. Proin at mauris a eros imperdiet mollis. Sed adipiscing hendrerit nisl. Curabitur libero. Donec nulla. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. + +Nullam non lacus. Vivamus rhoncus dolor sit amet ipsum. Vivamus volutpat eleifend odio. Vestibulum nunc. In at magna a pede gravida vulputate. Praesent ligula tellus, rhoncus elementum, pulvinar a, condimentum vitae, libero. Donec ornare dui. Proin non lorem quis massa placerat interdum. Nam justo. Aliquam rutrum dignissim mi. Mauris tellus. Proin dui felis, lacinia quis, volutpat a, blandit sed, neque. Etiam non dolor eu justo interdum tristique. Morbi volutpat, elit vitae rutrum iaculis, augue mi accumsan metus, sed porttitor felis mi sed felis. + +Nulla quam lectus, pharetra non, sodales sit amet, pretium quis, massa. Aliquam orci. Duis id massa. Pellentesque porttitor nibh id quam. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae; Donec convallis, pede vitae volutpat consequat, justo lorem ultricies nisi, ut scelerisque leo lorem in tellus. Cras bibendum. Sed hendrerit placerat tortor. Sed felis. Aliquam erat volutpat. Praesent rhoncus nisi. Vestibulum justo felis, tincidunt luctus, suscipit sed, tincidunt ut, lorem. Proin non risus ac mi mattis volutpat. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. Nam pellentesque nisl sit amet sapien rutrum porta. + +Phasellus ut pede non odio ultricies egestas. Aenean nibh. Mauris magna felis, posuere non, tempus et, bibendum ut, felis. Donec vel ipsum ac nisi dapibus lobortis. Sed congue ligula at est. Vivamus elit est, rhoncus vitae, tempus at, consectetur nec, elit. Duis vehicula tellus vitae sem. Suspendisse rhoncus felis sit amet magna. Maecenas vulputate risus in diam. Nunc sollicitudin risus eget quam. Nam pretium purus eleifend dolor. Integer erat nulla, mattis eu, sollicitudin sed, sagittis nec, metus. + +Donec ante felis, ultrices nec, pellentesque nec, elementum et, nunc. Pellentesque in tortor sit amet urna aliquet tincidunt. Praesent ultrices. Sed tincidunt. Donec turpis enim, feugiat eu, cursus ut, viverra ut, odio. Morbi in orci quis enim vehicula lobortis. Proin in neque. Pellentesque venenatis neque sit amet augue. Proin suscipit nibh. Praesent et diam. + +In eget ligula quis libero vulputate eleifend. Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae; Nunc non urna vitae mi vulputate adipiscing. Nulla vitae arcu. Nullam ut nisl ac enim pulvinar auctor. Suspendisse tortor pede, consectetur in, volutpat at, condimentum vel, ligula. Pellentesque nisi est, vulputate vitae, hendrerit id, venenatis sit amet, urna. Nunc lobortis. Sed rhoncus, tortor vitae pellentesque facilisis, massa ante interdum massa, feugiat faucibus pede nunc et tellus. Quisque auctor sollicitudin nibh. Aliquam congue. Praesent ullamcorper mi id lacus. Nullam ac risus et velit ullamcorper vehicula. Vestibulum consectetur convallis neque. Donec dapibus, ante a rutrum interdum, mi dui auctor lacus, quis posuere eros diam eu nisl. Integer nec velit vel purus eleifend condimentum. Cras quis nunc. Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. + +Sed euismod, metus eu consectetur dictum, felis eros sodales pede, ac pellentesque lacus orci sed velit. Praesent a justo. Aliquam massa dolor, condimentum non, dapibus quis, vestibulum a, purus. Duis gravida porta dolor. Nullam sit amet mi sagittis massa pretium ultricies. Ut fringilla. Aliquam venenatis feugiat dui. Pellentesque tempor, leo et ullamcorper placerat, felis libero blandit nisl, sit amet pharetra nisl erat sit amet dolor. In sem erat, porta rhoncus, auctor ac, convallis feugiat, dui. Sed tempus metus at erat. Cras gravida. Cras urna nisi, fermentum non, sodales sed, adipiscing sed, nulla. + +Donec pellentesque, velit sit amet ultricies dictum, sem quam posuere arcu, tristique mollis nibh dui ac libero. Vestibulum consectetur velit sed dolor. Nullam ornare sodales nisi. Sed facilisis sollicitudin arcu. Proin vitae lectus vel nulla auctor faucibus. Aenean nec nisl sit amet risus faucibus tincidunt. Ut sed nisl. Vivamus vehicula ligula a nunc. Curabitur mauris. Integer est felis, fermentum aliquam, dignissim id, gravida id, purus. Nullam porta felis eget ante. Phasellus lacinia, odio et elementum viverra, dui neque tempus massa, ac adipiscing lectus velit vitae turpis. Integer scelerisque neque in tortor. Duis et elit. Mauris elementum urna sed risus. Nunc aliquet, ipsum ac venenatis elementum, sapien orci vulputate lacus, eu lobortis sapien lorem non enim. Donec enim sapien, gravida vitae, vestibulum et, mattis dapibus, sem. Phasellus mi. + +Cras a lorem nec diam aliquet viverra. Aliquam sed leo sit amet neque porta venenatis. Nulla facilisi. Duis lectus felis, fermentum quis, sagittis a, vestibulum consectetur, orci. Suspendisse sodales odio vitae lectus. Curabitur nunc. Phasellus cursus diam sit amet ipsum. Aenean cursus tellus eget nunc. Vivamus mattis urna a lorem. Mauris vitae mi. Morbi luctus molestie pede. Vestibulum lobortis lacus sed lacus. Aliquam nisl libero, pellentesque sed, facilisis ut, varius vehicula, lacus. Mauris orci. Pellentesque sed risus id quam sodales lobortis. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Sed facilisis, odio vitae laoreet auctor, nulla dui sagittis lectus, sit amet viverra orci arcu et lectus. Pellentesque ut sem. Maecenas a est. + +Suspendisse tincidunt. Sed bibendum molestie ligula. Suspendisse massa mauris, cursus a, luctus eget, posuere sed, nulla. Fusce vitae urna. Duis fermentum. Donec a neque ac pede lobortis mollis. Donec massa ligula, facilisis et, dapibus sed, ultrices non, sem. Phasellus diam. Maecenas velit arcu, viverra ut, gravida ac, tincidunt eget, nunc. Sed sit amet enim non dui tristique lacinia. Vivamus eu orci. Duis metus. Nulla facilisi. Phasellus at lectus. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae; Vivamus mauris. Duis dictum, erat eu scelerisque sollicitudin, mi augue tincidunt lorem, vel lacinia lectus nibh quis dui. Ut ornare dignissim elit. Phasellus posuere ligula vel justo. + +Sed neque. Quisque porttitor lorem vel arcu. Praesent a mi et risus suscipit egestas. Proin est lectus, rhoncus sit amet, aliquet non, fermentum ut, nulla. Aenean erat nisl, rutrum dictum, placerat vel, malesuada ac, arcu. Suspendisse posuere, ante sed consequat gravida, velit mi dignissim sem, et pretium dui diam in elit. Sed dictum nulla. Duis tristique tincidunt eros. Morbi velit. Donec a lorem. Aliquam cursus. Vivamus dapibus varius neque. Quisque eget diam. Nulla facilisi. Pellentesque eu sapien. Curabitur egestas cursus risus. Proin odio tortor, interdum eget, fringilla venenatis, luctus et, turpis. Phasellus nulla lorem, ullamcorper ut, elementum rhoncus, ultrices sed, ipsum. Nam volutpat. + +Quisque eu purus. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. Curabitur non nulla. Donec dignissim porta lorem. Mauris ornare venenatis odio. Aenean eu lectus at eros porta molestie. Vivamus neque. Morbi aliquam. Nulla tincidunt enim id ligula. Nunc gravida felis consectetur dolor. Phasellus tempus. Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Nulla nec libero quis ipsum auctor vehicula. Maecenas consectetur tempor turpis. Integer commodo. In hac habitasse platea dictumst. Donec nec justo quis sem placerat gravida. Donec sollicitudin, turpis sit amet bibendum elementum, nisl ligula venenatis ipsum, vel sollicitudin justo arcu eu leo. Phasellus aliquet faucibus libero. + +Nam molestie nulla eu risus. Fusce id erat. Maecenas volutpat nunc eu ligula. Sed tortor est, imperdiet quis, viverra et, ornare in, ipsum. Praesent aliquet. Nulla suscipit. In posuere enim in odio. Nullam ante ipsum, imperdiet id, convallis id, hendrerit id, libero. Donec convallis libero ut felis. Curabitur venenatis placerat justo. Vestibulum mauris arcu, scelerisque et, dapibus vel, scelerisque a, lectus. Sed sit amet orci id felis tristique tincidunt. Curabitur adipiscing, nulla vel pretium tristique, tellus ipsum lacinia eros, vitae venenatis pede lectus sit amet neque. Nulla feugiat. Aenean euismod, nunc vel rutrum mattis, lorem purus venenatis sapien, sed facilisis pede enim at elit. Vivamus viverra. Cras vitae purus ac felis fringilla condimentum. Nullam ac nisi vitae massa faucibus aliquet. + +Etiam ut nibh nec neque elementum iaculis. Maecenas facilisis nulla at lorem. Pellentesque elit sapien, ultricies at, dignissim nec, cursus eu, pede. Morbi gravida, ipsum eget malesuada eleifend, est arcu pulvinar nisl, et fermentum urna felis sed tellus. Mauris fermentum sollicitudin neque. Nunc at odio. Pellentesque et turpis. Cras congue congue nisi. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Etiam feugiat dapibus tellus. Aenean aliquam, mi id interdum feugiat, nunc lorem laoreet massa, ac semper urna sem vel purus. Quisque bibendum tellus ut est. + +Morbi aliquam lectus sit amet nisi. Praesent urna purus, porttitor vitae, accumsan in, sollicitudin at, lorem. Donec diam dui, hendrerit eget, tincidunt ut, ultrices vehicula, dolor. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aliquam erat volutpat. Pellentesque iaculis iaculis lacus. Fusce auctor. Morbi vulputate purus at felis. Maecenas a pede nec metus vulputate ullamcorper. Cras non lectus. Suspendisse lacinia. diff --git a/chrome/test/data/zip/test_nocompress.zip b/chrome/test/data/zip/test_nocompress.zip new file mode 100755 index 0000000..f70d473 Binary files /dev/null and b/chrome/test/data/zip/test_nocompress.zip differ diff --git a/chrome/test/unit/unittests.vcproj b/chrome/test/unit/unittests.vcproj index fdaf278..ad678b9 100644 --- a/chrome/test/unit/unittests.vcproj +++ b/chrome/test/unit/unittests.vcproj @@ -1082,15 +1082,15 @@ > -- cgit v1.1