diff options
-rw-r--r-- | chrome/browser/extensions/extension_creator.cc | 2 | ||||
-rw-r--r-- | chrome/browser/extensions/extension_file_util.cc | 3 | ||||
-rw-r--r-- | chrome/common/zip.cc | 6 | ||||
-rw-r--r-- | chrome/common/zip.h | 5 | ||||
-rw-r--r-- | chrome/common/zip_unittest.cc | 42 | ||||
-rwxr-xr-x[-rw-r--r--] | chrome/test/data/zip/test.zip | bin | 4952 -> 5065 bytes | |||
-rw-r--r-- | chrome/test/data/zip/test/foo/bar/.hidden | 1 | ||||
-rwxr-xr-x[-rw-r--r--] | chrome/test/data/zip/test_nocompress.zip | bin | 14139 -> 14252 bytes |
8 files changed, 46 insertions, 13 deletions
diff --git a/chrome/browser/extensions/extension_creator.cc b/chrome/browser/extensions/extension_creator.cc index 8f65ad5..d9bc4d6 100644 --- a/chrome/browser/extensions/extension_creator.cc +++ b/chrome/browser/extensions/extension_creator.cc @@ -123,7 +123,7 @@ bool ExtensionCreator::CreateZip(const FilePath& extension_dir, file_util::CreateNewTempDirectory(FILE_PATH_LITERAL("chrome_"), zip_path); *zip_path = zip_path->Append(FILE_PATH_LITERAL("extension.zip")); - if (!Zip(extension_dir, *zip_path)) { + if (!Zip(extension_dir, *zip_path, false)) { // no hidden files error_message_ = "Failed to create temporary zip file during packaging."; return false; } diff --git a/chrome/browser/extensions/extension_file_util.cc b/chrome/browser/extensions/extension_file_util.cc index 5b1e16c..26a551b 100644 --- a/chrome/browser/extensions/extension_file_util.cc +++ b/chrome/browser/extensions/extension_file_util.cc @@ -384,7 +384,8 @@ bool CheckForIllegalFilenames(const FilePath& extension_path, std::string* error) { // Reserved underscore names. static const char* reserved_names[] = { - Extension::kLocaleFolder + Extension::kLocaleFolder, + "__MACOSX" }; static std::set<std::string> reserved_underscore_names( reserved_names, reserved_names + arraysize(reserved_names)); diff --git a/chrome/common/zip.cc b/chrome/common/zip.cc index 9c0adea..097f035 100644 --- a/chrome/common/zip.cc +++ b/chrome/common/zip.cc @@ -258,7 +258,8 @@ static bool AddEntryToZip(zipFile zip_file, const FilePath& path, return success; } -bool Zip(const FilePath& src_dir, const FilePath& dest_file) { +bool Zip(const FilePath& src_dir, const FilePath& dest_file, + bool include_hidden_files) { DCHECK(file_util::DirectoryExists(src_dir)); #if defined(OS_WIN) @@ -291,6 +292,9 @@ bool Zip(const FilePath& src_dir, const FilePath& dest_file) { file_util::FileEnumerator::DIRECTORIES)); for (FilePath path = file_enumerator.Next(); !path.value().empty(); path = file_enumerator.Next()) { + if (!include_hidden_files && path.BaseName().ToWStringHack()[0] == L'.') + continue; + if (!AddEntryToZip(zip_file, path, src_dir)) { success = false; return false; diff --git a/chrome/common/zip.h b/chrome/common/zip.h index 23823d8..2c3d456 100644 --- a/chrome/common/zip.h +++ b/chrome/common/zip.h @@ -12,7 +12,10 @@ // 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); +// If |include_hidden_files| is true, files starting with "." are included. +// Otherwise they are omitted. +bool Zip(const FilePath& src_dir, const FilePath& dest_file, + bool include_hidden_files); // Unzip the contents of zip_file into dest_dir. bool Unzip(const FilePath& zip_file, const FilePath& dest_dir); diff --git a/chrome/common/zip_unittest.cc b/chrome/common/zip_unittest.cc index dfa07249..ae43a09 100644 --- a/chrome/common/zip_unittest.cc +++ b/chrome/common/zip_unittest.cc @@ -33,20 +33,24 @@ class ZipTest : public PlatformTest { zip_contents_.insert(zip_path); zip_contents_.insert(zip_path.AppendASCII("baz.txt")); zip_contents_.insert(zip_path.AppendASCII("quux.txt")); + zip_contents_.insert(zip_path.AppendASCII(".hidden")); } virtual void TearDown() { PlatformTest::TearDown(); } - void TestUnzipFile(const FilePath::StringType& filename, bool need_success) { + void TestUnzipFile(const FilePath::StringType& filename, + bool expect_hidden_files, bool need_success) { FilePath test_dir; ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &test_dir)); test_dir = test_dir.AppendASCII("zip"); - TestUnzipFile(test_dir.Append(filename), need_success); + TestUnzipFile(test_dir.Append(filename), expect_hidden_files, + need_success); } - void TestUnzipFile(const FilePath& path, bool need_success) { + void TestUnzipFile(const FilePath& path, bool expect_hidden_files, + bool need_success) { ASSERT_TRUE(file_util::PathExists(path)) << "no file " << path.value(); if (need_success) { ASSERT_TRUE(Unzip(path, test_dir_)); @@ -70,7 +74,15 @@ class ZipTest : public PlatformTest { } next_path = files.Next(); } - EXPECT_EQ(count, zip_contents_.size()); + + size_t expected_count = 0; + for (std::set<FilePath>::iterator iter = zip_contents_.begin(); + iter != zip_contents_.end(); ++iter) { + if (expect_hidden_files || iter->BaseName().ToWStringHack()[0] != L'.') + ++expected_count; + } + + EXPECT_EQ(expected_count, count); } // the path to temporary directory used to contain the test operations @@ -83,15 +95,15 @@ class ZipTest : public PlatformTest { }; TEST_F(ZipTest, Unzip) { - TestUnzipFile(FILE_PATH_LITERAL("test.zip"), true); + TestUnzipFile(FILE_PATH_LITERAL("test.zip"), true, true); } TEST_F(ZipTest, UnzipUncompressed) { - TestUnzipFile(FILE_PATH_LITERAL("test_nocompress.zip"), true); + TestUnzipFile(FILE_PATH_LITERAL("test_nocompress.zip"), true, true); } TEST_F(ZipTest, UnzipEvil) { - TestUnzipFile(FILE_PATH_LITERAL("evil.zip"), false); + TestUnzipFile(FILE_PATH_LITERAL("evil.zip"), true, false); FilePath evil_file = test_dir_; evil_file = evil_file.AppendASCII( "../levilevilevilevilevilevilevilevilevilevilevilevil"); @@ -107,9 +119,21 @@ TEST_F(ZipTest, Zip) { ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); FilePath zip_file = temp_dir.path().AppendASCII("out.zip"); - EXPECT_TRUE(Zip(src_dir, zip_file)); + EXPECT_TRUE(Zip(src_dir, zip_file, true)); + TestUnzipFile(zip_file, true, true); +} + +TEST_F(ZipTest, ZipIgnoreHidden) { + FilePath src_dir; + ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &src_dir)); + src_dir = src_dir.AppendASCII("zip").AppendASCII("test"); + + ScopedTempDir temp_dir; + ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); + FilePath zip_file = temp_dir.path().AppendASCII("out.zip"); - TestUnzipFile(zip_file, true); + EXPECT_TRUE(Zip(src_dir, zip_file, false)); + TestUnzipFile(zip_file, false, true); } } // namespace diff --git a/chrome/test/data/zip/test.zip b/chrome/test/data/zip/test.zip Binary files differindex e32f108..4bafe30 100644..100755 --- a/chrome/test/data/zip/test.zip +++ b/chrome/test/data/zip/test.zip diff --git a/chrome/test/data/zip/test/foo/bar/.hidden b/chrome/test/data/zip/test/foo/bar/.hidden new file mode 100644 index 0000000..136c05e --- /dev/null +++ b/chrome/test/data/zip/test/foo/bar/.hidden @@ -0,0 +1 @@ +hidden diff --git a/chrome/test/data/zip/test_nocompress.zip b/chrome/test/data/zip/test_nocompress.zip Binary files differindex f95e1d2..25d66c2 100644..100755 --- a/chrome/test/data/zip/test_nocompress.zip +++ b/chrome/test/data/zip/test_nocompress.zip |