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 "chrome/common/zip.h" | 5 #include "chrome/common/zip.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/file_util.h" | 8 #include "base/file_util.h" |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "base/string16.h" | 10 #include "base/string16.h" |
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
163 bool include_hidden_files) { | 163 bool include_hidden_files) { |
164 if (include_hidden_files) { | 164 if (include_hidden_files) { |
165 return ZipWithFilterCallback( | 165 return ZipWithFilterCallback( |
166 src_dir, dest_file, base::Bind(&ExcludeNoFilesFilter)); | 166 src_dir, dest_file, base::Bind(&ExcludeNoFilesFilter)); |
167 } else { | 167 } else { |
168 return ZipWithFilterCallback( | 168 return ZipWithFilterCallback( |
169 src_dir, dest_file, base::Bind(&ExcludeHiddenFilesFilter)); | 169 src_dir, dest_file, base::Bind(&ExcludeHiddenFilesFilter)); |
170 } | 170 } |
171 } | 171 } |
172 | 172 |
| 173 bool ZipFileList(const FilePath& src_dir, const FilePath& dest_file, |
| 174 const std::vector<FilePath>& src_file_list) { |
| 175 DCHECK(file_util::DirectoryExists(src_dir)); |
| 176 |
| 177 zipFile zip_file = internal::OpenForZipping(dest_file.AsUTF8Unsafe(), |
| 178 APPEND_STATUS_CREATE); |
| 179 |
| 180 if (!zip_file) { |
| 181 DLOG(WARNING) << "couldn't create file " << dest_file.value(); |
| 182 return false; |
| 183 } |
| 184 |
| 185 bool success = true; |
| 186 for (std::vector<FilePath>::const_iterator iter = src_file_list.begin(); |
| 187 iter != src_file_list.end(); iter++) { |
| 188 const FilePath& path = *iter; |
| 189 if (!src_dir.IsParent(path)) { |
| 190 DLOG(ERROR) << "Ignoring file outside source directory " << path.value(); |
| 191 continue; |
| 192 } |
| 193 if (!AddEntryToZip(zip_file, path, src_dir)) { |
| 194 success = false; |
| 195 break; |
| 196 } |
| 197 } |
| 198 |
| 199 if (ZIP_OK != zipClose(zip_file, NULL)) { // global comment |
| 200 DLOG(ERROR) << "Error closing zip file " << dest_file.value(); |
| 201 success = false; |
| 202 } |
| 203 |
| 204 return success; |
| 205 } |
| 206 |
173 } // namespace zip | 207 } // namespace zip |
OLD | NEW |