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

Side by Side Diff: third_party/zlib/google/zip.cc

Issue 19052005: Move PathIsWritable, DirectoryExists, ContentsEqual, and TextContentsEqual to the base namespace. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 5 months 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 "base/bind.h" 7 #include "base/bind.h"
8 #include "base/file_util.h" 8 #include "base/file_util.h"
9 #include "base/files/file_enumerator.h" 9 #include "base/files/file_enumerator.h"
10 #include "base/logging.h" 10 #include "base/logging.h"
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
50 } 50 }
51 51
52 bool AddEntryToZip(zipFile zip_file, const base::FilePath& path, 52 bool AddEntryToZip(zipFile zip_file, const base::FilePath& path,
53 const base::FilePath& root_path) { 53 const base::FilePath& root_path) {
54 std::string str_path = 54 std::string str_path =
55 path.AsUTF8Unsafe().substr(root_path.AsUTF8Unsafe().length() + 1); 55 path.AsUTF8Unsafe().substr(root_path.AsUTF8Unsafe().length() + 1);
56 #if defined(OS_WIN) 56 #if defined(OS_WIN)
57 ReplaceSubstringsAfterOffset(&str_path, 0u, "\\", "/"); 57 ReplaceSubstringsAfterOffset(&str_path, 0u, "\\", "/");
58 #endif 58 #endif
59 59
60 bool is_directory = file_util::DirectoryExists(path); 60 bool is_directory = base::DirectoryExists(path);
61 if (is_directory) 61 if (is_directory)
62 str_path += "/"; 62 str_path += "/";
63 63
64 if (ZIP_OK != zipOpenNewFileInZip( 64 if (ZIP_OK != zipOpenNewFileInZip(
65 zip_file, str_path.c_str(), 65 zip_file, str_path.c_str(),
66 NULL, NULL, 0u, NULL, 0u, NULL, // file info, extrafield local, length, 66 NULL, NULL, 0u, NULL, 0u, NULL, // file info, extrafield local, length,
67 // extrafield global, length, comment 67 // extrafield global, length, comment
68 Z_DEFLATED, Z_DEFAULT_COMPRESSION)) { 68 Z_DEFLATED, Z_DEFAULT_COMPRESSION)) {
69 DLOG(ERROR) << "Could not open zip file entry " << str_path; 69 DLOG(ERROR) << "Could not open zip file entry " << str_path;
70 return false; 70 return false;
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
120 DLOG(WARNING) << "Failed to advance to the next file"; 120 DLOG(WARNING) << "Failed to advance to the next file";
121 return false; 121 return false;
122 } 122 }
123 } 123 }
124 return true; 124 return true;
125 } 125 }
126 126
127 bool ZipWithFilterCallback(const base::FilePath& src_dir, 127 bool ZipWithFilterCallback(const base::FilePath& src_dir,
128 const base::FilePath& dest_file, 128 const base::FilePath& dest_file,
129 const FilterCallback& filter_cb) { 129 const FilterCallback& filter_cb) {
130 DCHECK(file_util::DirectoryExists(src_dir)); 130 DCHECK(base::DirectoryExists(src_dir));
131 131
132 zipFile zip_file = internal::OpenForZipping(dest_file.AsUTF8Unsafe(), 132 zipFile zip_file = internal::OpenForZipping(dest_file.AsUTF8Unsafe(),
133 APPEND_STATUS_CREATE); 133 APPEND_STATUS_CREATE);
134 134
135 if (!zip_file) { 135 if (!zip_file) {
136 DLOG(WARNING) << "couldn't create file " << dest_file.value(); 136 DLOG(WARNING) << "couldn't create file " << dest_file.value();
137 return false; 137 return false;
138 } 138 }
139 139
140 bool success = true; 140 bool success = true;
(...skipping 27 matching lines...) Expand all
168 } else { 168 } else {
169 return ZipWithFilterCallback( 169 return ZipWithFilterCallback(
170 src_dir, dest_file, base::Bind(&ExcludeHiddenFilesFilter)); 170 src_dir, dest_file, base::Bind(&ExcludeHiddenFilesFilter));
171 } 171 }
172 } 172 }
173 173
174 #if defined(OS_POSIX) 174 #if defined(OS_POSIX)
175 bool ZipFiles(const base::FilePath& src_dir, 175 bool ZipFiles(const base::FilePath& src_dir,
176 const std::vector<base::FilePath>& src_relative_paths, 176 const std::vector<base::FilePath>& src_relative_paths,
177 int dest_fd) { 177 int dest_fd) {
178 DCHECK(file_util::DirectoryExists(src_dir)); 178 DCHECK(base::DirectoryExists(src_dir));
179 zipFile zip_file = internal::OpenFdForZipping(dest_fd, APPEND_STATUS_CREATE); 179 zipFile zip_file = internal::OpenFdForZipping(dest_fd, APPEND_STATUS_CREATE);
180 180
181 if (!zip_file) { 181 if (!zip_file) {
182 DLOG(ERROR) << "couldn't create file for fd " << dest_fd; 182 DLOG(ERROR) << "couldn't create file for fd " << dest_fd;
183 return false; 183 return false;
184 } 184 }
185 185
186 bool success = true; 186 bool success = true;
187 for (std::vector<base::FilePath>::const_iterator iter = 187 for (std::vector<base::FilePath>::const_iterator iter =
188 src_relative_paths.begin(); 188 src_relative_paths.begin();
189 iter != src_relative_paths.end(); ++iter) { 189 iter != src_relative_paths.end(); ++iter) {
190 const base::FilePath& path = src_dir.Append(*iter); 190 const base::FilePath& path = src_dir.Append(*iter);
191 if (!AddEntryToZip(zip_file, path, src_dir)) { 191 if (!AddEntryToZip(zip_file, path, src_dir)) {
192 // TODO(hshi): clean up the partial zip file when error occurs. 192 // TODO(hshi): clean up the partial zip file when error occurs.
193 success = false; 193 success = false;
194 break; 194 break;
195 } 195 }
196 } 196 }
197 197
198 if (ZIP_OK != zipClose(zip_file, NULL)) { 198 if (ZIP_OK != zipClose(zip_file, NULL)) {
199 DLOG(ERROR) << "Error closing zip file for fd " << dest_fd; 199 DLOG(ERROR) << "Error closing zip file for fd " << dest_fd;
200 success = false; 200 success = false;
201 } 201 }
202 202
203 return success; 203 return success;
204 } 204 }
205 #endif // defined(OS_POSIX) 205 #endif // defined(OS_POSIX)
206 206
207 } // namespace zip 207 } // namespace zip
OLDNEW
« no previous file with comments | « third_party/leveldatabase/env_chromium.cc ('k') | third_party/zlib/google/zip_reader_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698