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
3 // found in the LICENSE file.
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.
11 #include "base/at_exit.h"
12 #include "base/command_line.h"
13 #include "base/strings/string16.h"
14 #include "base/strings/string_util.h"
15 #include "base/strings/stringprintf.h"
16 #include "net/disk_cache/blockfile/disk_format.h"
17 #include "net/tools/dump_cache/dump_files.h"
18 #include "net/tools/dump_cache/simple_cache_dumper.h"
29 // Folders to read and write cache files.
30 const char kInputPath[] = "input";
31 const char kOutputPath[] = "output";
33 // Dumps the file headers to stdout.
34 const char kDumpHeaders[] = "dump-headers";
36 // Dumps all entries to stdout.
37 const char kDumpContents[] = "dump-contents";
39 // Convert the cache to files.
40 const char kDumpToFiles[] = "dump-to-files";
43 printf("warning: input files are modified by this tool\n");
44 printf("dump_cache --input=path1 [--output=path2]\n");
45 printf("--dump-headers: display file headers\n");
46 printf("--dump-contents: display all entries\n");
47 printf("--dump-to-files: write the contents of the cache to files\n");
48 return INVALID_ARGUMENT;
51 // -----------------------------------------------------------------------
53 int main(int argc, const char* argv[]) {
54 // Setup an AtExitManager so Singleton objects will be destroyed.
55 base::AtExitManager at_exit_manager;
57 base::CommandLine::Init(argc, argv);
59 const base::CommandLine& command_line =
60 *base::CommandLine::ForCurrentProcess();
61 base::FilePath input_path = command_line.GetSwitchValuePath(kInputPath);
62 if (input_path.empty())
65 bool dump_to_files = command_line.HasSwitch(kDumpToFiles);
67 base::FilePath output_path = command_line.GetSwitchValuePath(kOutputPath);
68 if (dump_to_files && output_path.empty())
71 int version = GetMajorVersion(input_path);
73 return FILE_ACCESS_ERROR;
76 net::SimpleCacheDumper dumper(input_path, output_path);
81 if (command_line.HasSwitch(kDumpContents))
82 return DumpContents(input_path);
84 if (command_line.HasSwitch(kDumpHeaders))
85 return DumpHeaders(input_path);