OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
64 printf("warning: input files are modified by this tool\n"); | 64 printf("warning: input files are modified by this tool\n"); |
65 printf("dump_cache --input=path1 [--output=path2]\n"); | 65 printf("dump_cache --input=path1 [--output=path2]\n"); |
66 printf("--dump-headers: display file headers\n"); | 66 printf("--dump-headers: display file headers\n"); |
67 printf("--dump-contents: display all entries\n"); | 67 printf("--dump-contents: display all entries\n"); |
68 printf("--upgrade: copy contents to the output path\n"); | 68 printf("--upgrade: copy contents to the output path\n"); |
69 printf("--dump-to-files: write the contents of the cache to files\n"); | 69 printf("--dump-to-files: write the contents of the cache to files\n"); |
70 return INVALID_ARGUMENT; | 70 return INVALID_ARGUMENT; |
71 } | 71 } |
72 | 72 |
73 // Starts a new process, to generate the files. | 73 // Starts a new process, to generate the files. |
74 int LaunchSlave(const CommandLine& command_line, | 74 int LaunchSlave(CommandLine command_line, |
75 const std::wstring& pipe_number, int version) { | 75 const std::wstring& pipe_number, |
76 // TODO(port): remove this string-munging hackery. | 76 int version) { |
77 std::wstring hacked_command_line = command_line.command_line_string(); | |
78 const std::wstring old_exe(L"dump_cache"); | |
79 size_t to_remove = hacked_command_line.find(old_exe); | |
80 hacked_command_line.erase(to_remove, old_exe.size()); | |
81 | |
82 bool do_upgrade = command_line.HasSwitch(kUpgrade); | 77 bool do_upgrade = command_line.HasSwitch(kUpgrade); |
83 bool do_convert_to_text = command_line.HasSwitch(kDumpToFiles); | 78 bool do_convert_to_text = command_line.HasSwitch(kDumpToFiles); |
84 | 79 |
85 std::wstring new_program; | 80 if (do_upgrade) { |
86 if (do_upgrade) | 81 FilePath program(base::StringPrintf(L"%ls%d", L"dump_cache", version)); |
87 new_program = base::StringPrintf(L"%ls%d", L"dump_cache_", version); | 82 command_line.SetProgram(program); |
88 else | 83 } |
89 new_program = base::StringPrintf(L"dump_cache"); | |
90 | |
91 hacked_command_line.insert(to_remove, new_program); | |
92 | |
93 CommandLine new_command_line = CommandLine::FromString(hacked_command_line); | |
94 | 84 |
95 if (do_upgrade || do_convert_to_text) | 85 if (do_upgrade || do_convert_to_text) |
96 new_command_line.AppendSwitch(kSlave); | 86 command_line.AppendSwitch(kSlave); |
97 | 87 |
98 // TODO(evanm): remove needless usage of wstring from here and elsewhere. | 88 // TODO(evanm): remove needless usage of wstring from here and elsewhere. |
99 new_command_line.AppendSwitchASCII(kPipe, WideToASCII(pipe_number)); | 89 command_line.AppendSwitchASCII(kPipe, WideToASCII(pipe_number)); |
100 if (!base::LaunchProcess(new_command_line, base::LaunchOptions(), NULL)) { | 90 if (!base::LaunchProcess(command_line, base::LaunchOptions(), NULL)) { |
101 printf("Unable to launch the needed version of this tool: %ls\n", | 91 printf("Unable to launch the needed version of this tool: %ls\n", |
102 new_program.c_str()); | 92 command_line.GetProgram().value().c_str()); |
103 printf(kUpgradeHelp); | 93 printf(kUpgradeHelp); |
104 return TOOL_NOT_FOUND; | 94 return TOOL_NOT_FOUND; |
105 } | 95 } |
106 return ALL_GOOD; | 96 return ALL_GOOD; |
107 } | 97 } |
108 | 98 |
109 // ----------------------------------------------------------------------- | 99 // ----------------------------------------------------------------------- |
110 | 100 |
111 int main(int argc, const char* argv[]) { | 101 int main(int argc, const char* argv[]) { |
112 // Setup an AtExitManager so Singleton objects will be destroyed. | 102 // Setup an AtExitManager so Singleton objects will be destroyed. |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
177 Sleep(500); | 167 Sleep(500); |
178 return ALL_GOOD; | 168 return ALL_GOOD; |
179 } | 169 } |
180 | 170 |
181 if (command_line.HasSwitch(kDumpContents)) | 171 if (command_line.HasSwitch(kDumpContents)) |
182 return DumpContents(input_path); | 172 return DumpContents(input_path); |
183 if (command_line.HasSwitch(kDumpHeaders)) | 173 if (command_line.HasSwitch(kDumpHeaders)) |
184 return DumpHeaders(input_path); | 174 return DumpHeaders(input_path); |
185 return Help(); | 175 return Help(); |
186 } | 176 } |
OLD | NEW |