| OLD | NEW |
| 1 // Copyright (c) 2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2008 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 // This command-line program dumps the contents of a set of cache files, either | 5 // This command-line program dumps the contents of a set of cache files, either |
| 6 // to stdout or to another set of cache files. | 6 // to stdout or to another set of cache files. |
| 7 | 7 |
| 8 #include <stdio.h> | 8 #include <stdio.h> |
| 9 #include <string> | 9 #include <string> |
| 10 | 10 |
| 11 #include "base/at_exit.h" | 11 #include "base/at_exit.h" |
| 12 #include "base/command_line.h" | 12 #include "base/command_line.h" |
| 13 #include "base/process_util.h" | 13 #include "base/process_util.h" |
| 14 #include "base/scoped_handle.h" | 14 #include "base/scoped_handle.h" |
| 15 #include "base/string_util.h" | 15 #include "base/string_util.h" |
| 16 | 16 |
| 17 #include "net/disk_cache/disk_format.h" | 17 #include "net/disk_cache/disk_format.h" |
| 18 | 18 |
| 19 enum Errors { | 19 enum Errors { |
| 20 GENERIC = -1, | 20 GENERIC = -1, |
| 21 ALL_GOOD = 0, | 21 ALL_GOOD = 0, |
| 22 INVALID_ARGUMENT = 1, | 22 INVALID_ARGUMENT = 1, |
| 23 FILE_ACCESS_ERROR, | 23 FILE_ACCESS_ERROR, |
| 24 UNKNOWN_VERSION, | 24 UNKNOWN_VERSION, |
| 25 TOOL_NOT_FOUND, | 25 TOOL_NOT_FOUND, |
| 26 }; | 26 }; |
| 27 | 27 |
| 28 int GetMajorVersion(const std::wstring input_path); | 28 int GetMajorVersion(const std::wstring& input_path); |
| 29 int DumpContents(const std::wstring input_path); | 29 int DumpContents(const std::wstring& input_path); |
| 30 int DumpHeaders(const std::wstring input_path); | 30 int DumpHeaders(const std::wstring& input_path); |
| 31 int RunSlave(const std::wstring input_path, const std::wstring pipe_number); | 31 int RunSlave(const std::wstring& input_path, const std::wstring& pipe_number); |
| 32 int Upgrade(const std::wstring output_path, HANDLE pipe); | 32 int Upgrade(const std::wstring& output_path, HANDLE pipe); |
| 33 HANDLE CreateServer(std::wstring* pipe_number); | 33 HANDLE CreateServer(std::wstring* pipe_number); |
| 34 | 34 |
| 35 const char kUpgradeHelp[] = | 35 const char kUpgradeHelp[] = |
| 36 "\nIn order to use the upgrade function, a version of this tool that\n" | 36 "\nIn order to use the upgrade function, a version of this tool that\n" |
| 37 "understands the file format of the files to upgrade is needed. For\n" | 37 "understands the file format of the files to upgrade is needed. For\n" |
| 38 "instance, to upgrade files saved with file format 3.4 to version 5.2,\n" | 38 "instance, to upgrade files saved with file format 3.4 to version 5.2,\n" |
| 39 "a version of this program that was compiled with version 3.4 has to be\n" | 39 "a version of this program that was compiled with version 3.4 has to be\n" |
| 40 "located beside this executable, and named dump_cache_3.exe, and this\n" | 40 "located beside this executable, and named dump_cache_3.exe, and this\n" |
| 41 "executable should be compiled with version 5.2 being the current one."; | 41 "executable should be compiled with version 5.2 being the current one."; |
| 42 | 42 |
| (...skipping 17 matching lines...) Expand all Loading... |
| 60 int Help() { | 60 int Help() { |
| 61 printf("warning: input files are modified by this tool\n"); | 61 printf("warning: input files are modified by this tool\n"); |
| 62 printf("dump_cache --input=path1 [--output=path2]\n"); | 62 printf("dump_cache --input=path1 [--output=path2]\n"); |
| 63 printf("--dump-headers: display file headers\n"); | 63 printf("--dump-headers: display file headers\n"); |
| 64 printf("--dump-contents: display all entries\n"); | 64 printf("--dump-contents: display all entries\n"); |
| 65 printf("--upgrade: copy contents to the output path\n"); | 65 printf("--upgrade: copy contents to the output path\n"); |
| 66 return INVALID_ARGUMENT; | 66 return INVALID_ARGUMENT; |
| 67 } | 67 } |
| 68 | 68 |
| 69 // Starts a new process, to generate the files. | 69 // Starts a new process, to generate the files. |
| 70 int LaunchSlave(const CommandLine& command_line, const std::wstring pipe_number, | 70 int LaunchSlave(const CommandLine& command_line, |
| 71 int version) { | 71 const std::wstring& pipe_number, int version) { |
| 72 // TODO(port): remove this string-munging hackery. | 72 // TODO(port): remove this string-munging hackery. |
| 73 std::wstring hacked_command_line = command_line.command_line_string(); | 73 std::wstring hacked_command_line = command_line.command_line_string(); |
| 74 const std::wstring old_exe(L"dump_cache.exe"); | 74 const std::wstring old_exe(L"dump_cache.exe"); |
| 75 size_t to_remove = hacked_command_line.find(old_exe); | 75 size_t to_remove = hacked_command_line.find(old_exe); |
| 76 hacked_command_line.erase(to_remove, old_exe.size()); | 76 hacked_command_line.erase(to_remove, old_exe.size()); |
| 77 | 77 |
| 78 std::wstring new_program = StringPrintf(L"%ls%d.exe", L"dump_cache_", | 78 std::wstring new_program = StringPrintf(L"%ls%d.exe", L"dump_cache_", |
| 79 version); | 79 version); |
| 80 hacked_command_line.insert(to_remove, new_program); | 80 hacked_command_line.insert(to_remove, new_program); |
| 81 | 81 |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 157 Sleep(500); | 157 Sleep(500); |
| 158 return ALL_GOOD; | 158 return ALL_GOOD; |
| 159 } | 159 } |
| 160 | 160 |
| 161 if (command_line.HasSwitch(kDumpContents)) | 161 if (command_line.HasSwitch(kDumpContents)) |
| 162 return DumpContents(input_path); | 162 return DumpContents(input_path); |
| 163 if (command_line.HasSwitch(kDumpHeaders)) | 163 if (command_line.HasSwitch(kDumpHeaders)) |
| 164 return DumpHeaders(input_path); | 164 return DumpHeaders(input_path); |
| 165 return Help(); | 165 return Help(); |
| 166 } | 166 } |
| OLD | NEW |