Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(10269)

Unified Diff: chrome/common/zip.cc

Issue 11309014: File manager: support for zipping selected files. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Define zip::ZipFileList method to internalize details with handling file lists. Created 8 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/common/zip.cc
diff --git a/chrome/common/zip.cc b/chrome/common/zip.cc
index 9ec489459cd320345633eae4d9d4fe13b8a12439..93a896f463f5fb96750dc22d7e19fabef42db073 100644
--- a/chrome/common/zip.cc
+++ b/chrome/common/zip.cc
@@ -170,4 +170,38 @@ bool Zip(const FilePath& src_dir, const FilePath& dest_file,
}
}
+bool ZipFileList(const FilePath& src_dir, const FilePath& dest_file,
+ const std::vector<FilePath>& src_file_list) {
+ DCHECK(file_util::DirectoryExists(src_dir));
+
+ zipFile zip_file = internal::OpenForZipping(dest_file.AsUTF8Unsafe(),
+ APPEND_STATUS_CREATE);
+
+ if (!zip_file) {
+ DLOG(WARNING) << "couldn't create file " << dest_file.value();
+ return false;
+ }
+
+ bool success = true;
+ for (std::vector<FilePath>::const_iterator iter = src_file_list.begin();
+ iter != src_file_list.end(); iter++) {
+ const FilePath& path = *iter;
+ if (!src_dir.IsParent(path)) {
+ DLOG(ERROR) << "Ignoring file outside source directory " << path.value();
+ continue;
+ }
+ if (!AddEntryToZip(zip_file, path, src_dir)) {
+ success = false;
+ break;
+ }
+ }
+
+ if (ZIP_OK != zipClose(zip_file, NULL)) { // global comment
+ DLOG(ERROR) << "Error closing zip file " << dest_file.value();
+ success = false;
+ }
+
+ return success;
+}
+
} // namespace zip

Powered by Google App Engine
This is Rietveld 408576698