| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "third_party/zlib/google/zip.h" | 5 #include "third_party/zlib/google/zip.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 88 bool ExcludeHiddenFilesFilter(const base::FilePath& file_path) { | 88 bool ExcludeHiddenFilesFilter(const base::FilePath& file_path) { |
| 89 return file_path.BaseName().value()[0] != '.'; | 89 return file_path.BaseName().value()[0] != '.'; |
| 90 } | 90 } |
| 91 | 91 |
| 92 } // namespace | 92 } // namespace |
| 93 | 93 |
| 94 namespace zip { | 94 namespace zip { |
| 95 | 95 |
| 96 bool Unzip(const base::FilePath& src_file, const base::FilePath& dest_dir) { | 96 bool Unzip(const base::FilePath& src_file, const base::FilePath& dest_dir) { |
| 97 return UnzipWithFilterCallback(src_file, dest_dir, | 97 return UnzipWithFilterCallback(src_file, dest_dir, |
| 98 base::Bind(&ExcludeNoFilesFilter)); | 98 base::Bind(&ExcludeNoFilesFilter), true); |
| 99 } | 99 } |
| 100 | 100 |
| 101 bool UnzipWithFilterCallback(const base::FilePath& src_file, | 101 bool UnzipWithFilterCallback(const base::FilePath& src_file, |
| 102 const base::FilePath& dest_dir, | 102 const base::FilePath& dest_dir, |
| 103 const FilterCallback& filter_cb) { | 103 const FilterCallback& filter_cb, |
| 104 bool log_skipped_files) { |
| 104 ZipReader reader; | 105 ZipReader reader; |
| 105 if (!reader.Open(src_file)) { | 106 if (!reader.Open(src_file)) { |
| 106 DLOG(WARNING) << "Failed to open " << src_file.value(); | 107 DLOG(WARNING) << "Failed to open " << src_file.value(); |
| 107 return false; | 108 return false; |
| 108 } | 109 } |
| 109 while (reader.HasMore()) { | 110 while (reader.HasMore()) { |
| 110 if (!reader.OpenCurrentEntryInZip()) { | 111 if (!reader.OpenCurrentEntryInZip()) { |
| 111 DLOG(WARNING) << "Failed to open the current file in zip"; | 112 DLOG(WARNING) << "Failed to open the current file in zip"; |
| 112 return false; | 113 return false; |
| 113 } | 114 } |
| 114 if (reader.current_entry_info()->is_unsafe()) { | 115 if (reader.current_entry_info()->is_unsafe()) { |
| 115 DLOG(WARNING) << "Found an unsafe file in zip " | 116 DLOG(WARNING) << "Found an unsafe file in zip " |
| 116 << reader.current_entry_info()->file_path().value(); | 117 << reader.current_entry_info()->file_path().value(); |
| 117 return false; | 118 return false; |
| 118 } | 119 } |
| 119 if (filter_cb.Run(reader.current_entry_info()->file_path())) { | 120 if (filter_cb.Run(reader.current_entry_info()->file_path())) { |
| 120 if (!reader.ExtractCurrentEntryIntoDirectory(dest_dir)) { | 121 if (!reader.ExtractCurrentEntryIntoDirectory(dest_dir)) { |
| 121 DLOG(WARNING) << "Failed to extract " | 122 DLOG(WARNING) << "Failed to extract " |
| 122 << reader.current_entry_info()->file_path().value(); | 123 << reader.current_entry_info()->file_path().value(); |
| 123 return false; | 124 return false; |
| 124 } | 125 } |
| 125 } else { | 126 } else if (log_skipped_files) { |
| 126 DLOG(WARNING) << "Skipped file " | 127 DLOG(WARNING) << "Skipped file " |
| 127 << reader.current_entry_info()->file_path().value(); | 128 << reader.current_entry_info()->file_path().value(); |
| 128 } | 129 } |
| 129 | 130 |
| 130 if (!reader.AdvanceToNextEntry()) { | 131 if (!reader.AdvanceToNextEntry()) { |
| 131 DLOG(WARNING) << "Failed to advance to the next file"; | 132 DLOG(WARNING) << "Failed to advance to the next file"; |
| 132 return false; | 133 return false; |
| 133 } | 134 } |
| 134 } | 135 } |
| 135 return true; | 136 return true; |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 209 if (ZIP_OK != zipClose(zip_file, NULL)) { | 210 if (ZIP_OK != zipClose(zip_file, NULL)) { |
| 210 DLOG(ERROR) << "Error closing zip file for fd " << dest_fd; | 211 DLOG(ERROR) << "Error closing zip file for fd " << dest_fd; |
| 211 success = false; | 212 success = false; |
| 212 } | 213 } |
| 213 | 214 |
| 214 return success; | 215 return success; |
| 215 } | 216 } |
| 216 #endif // defined(OS_POSIX) | 217 #endif // defined(OS_POSIX) |
| 217 | 218 |
| 218 } // namespace zip | 219 } // namespace zip |
| OLD | NEW |