| 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" |
| 11 #include "base/file_util.h" | 11 #include "base/files/file.h" |
| 12 #include "base/files/file_enumerator.h" | 12 #include "base/files/file_enumerator.h" |
| 13 #include "base/logging.h" | 13 #include "base/logging.h" |
| 14 #include "base/strings/string16.h" | 14 #include "base/strings/string16.h" |
| 15 #include "base/strings/string_util.h" | 15 #include "base/strings/string_util.h" |
| 16 #include "net/base/file_stream.h" | |
| 17 #include "third_party/zlib/google/zip_internal.h" | 16 #include "third_party/zlib/google/zip_internal.h" |
| 18 #include "third_party/zlib/google/zip_reader.h" | 17 #include "third_party/zlib/google/zip_reader.h" |
| 19 | 18 |
| 20 #if defined(USE_SYSTEM_MINIZIP) | 19 #if defined(USE_SYSTEM_MINIZIP) |
| 21 #include <minizip/unzip.h> | 20 #include <minizip/unzip.h> |
| 22 #include <minizip/zip.h> | 21 #include <minizip/zip.h> |
| 23 #else | 22 #else |
| 24 #include "third_party/zlib/contrib/minizip/unzip.h" | 23 #include "third_party/zlib/contrib/minizip/unzip.h" |
| 25 #include "third_party/zlib/contrib/minizip/zip.h" | 24 #include "third_party/zlib/contrib/minizip/zip.h" |
| 26 #endif | 25 #endif |
| (...skipping 26 matching lines...) Expand all Loading... |
| 53 // Returns a zip_fileinfo with the last modification date of |path| set. | 52 // Returns a zip_fileinfo with the last modification date of |path| set. |
| 54 zip_fileinfo GetFileInfoForZipping(const base::FilePath& path) { | 53 zip_fileinfo GetFileInfoForZipping(const base::FilePath& path) { |
| 55 base::Time file_time; | 54 base::Time file_time; |
| 56 base::File::Info file_info; | 55 base::File::Info file_info; |
| 57 if (base::GetFileInfo(path, &file_info)) | 56 if (base::GetFileInfo(path, &file_info)) |
| 58 file_time = file_info.last_modified; | 57 file_time = file_info.last_modified; |
| 59 return TimeToZipFileInfo(file_time); | 58 return TimeToZipFileInfo(file_time); |
| 60 } | 59 } |
| 61 | 60 |
| 62 bool AddFileToZip(zipFile zip_file, const base::FilePath& src_dir) { | 61 bool AddFileToZip(zipFile zip_file, const base::FilePath& src_dir) { |
| 63 net::FileStream stream(NULL); | 62 base::File file(src_dir, base::File::FLAG_OPEN | base::File::FLAG_READ); |
| 64 int flags = base::PLATFORM_FILE_OPEN | base::PLATFORM_FILE_READ; | 63 if (!file.IsValid()) { |
| 65 if (stream.OpenSync(src_dir, flags) != 0) { | 64 DLOG(ERROR) << "Could not open file for path " << src_dir.value(); |
| 66 DLOG(ERROR) << "Could not open stream for path " | |
| 67 << src_dir.value(); | |
| 68 return false; | 65 return false; |
| 69 } | 66 } |
| 70 | 67 |
| 71 int num_bytes; | 68 int num_bytes; |
| 72 char buf[zip::internal::kZipBufSize]; | 69 char buf[zip::internal::kZipBufSize]; |
| 73 do { | 70 do { |
| 74 num_bytes = stream.ReadSync(buf, zip::internal::kZipBufSize); | 71 num_bytes = file.ReadAtCurrentPos(buf, zip::internal::kZipBufSize); |
| 75 if (num_bytes > 0) { | 72 if (num_bytes > 0) { |
| 76 if (ZIP_OK != zipWriteInFileInZip(zip_file, buf, num_bytes)) { | 73 if (ZIP_OK != zipWriteInFileInZip(zip_file, buf, num_bytes)) { |
| 77 DLOG(ERROR) << "Could not write data to zip for path " | 74 DLOG(ERROR) << "Could not write data to zip for path " |
| 78 << src_dir.value(); | 75 << src_dir.value(); |
| 79 return false; | 76 return false; |
| 80 } | 77 } |
| 81 } | 78 } |
| 82 } while (num_bytes > 0); | 79 } while (num_bytes > 0); |
| 83 | 80 |
| 84 return true; | 81 return true; |
| (...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 255 if (ZIP_OK != zipClose(zip_file, NULL)) { | 252 if (ZIP_OK != zipClose(zip_file, NULL)) { |
| 256 DLOG(ERROR) << "Error closing zip file for fd " << dest_fd; | 253 DLOG(ERROR) << "Error closing zip file for fd " << dest_fd; |
| 257 success = false; | 254 success = false; |
| 258 } | 255 } |
| 259 | 256 |
| 260 return success; | 257 return success; |
| 261 } | 258 } |
| 262 #endif // defined(OS_POSIX) | 259 #endif // defined(OS_POSIX) |
| 263 | 260 |
| 264 } // namespace zip | 261 } // namespace zip |
| OLD | NEW |