OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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 // A tool to dump HTML5 filesystem from CUI. | 5 // A tool to dump HTML5 filesystem from CUI. |
6 // | 6 // |
7 // Usage: | 7 // Usage: |
8 // | 8 // |
9 // ./out/Release/dump_file_system [options] <filesystem dir> [origin]... | 9 // ./out/Release/dump_file_system [options] <filesystem dir> [origin]... |
10 // | 10 // |
(...skipping 20 matching lines...) Expand all Loading... |
31 | 31 |
32 #include <stack> | 32 #include <stack> |
33 #include <string> | 33 #include <string> |
34 #include <utility> | 34 #include <utility> |
35 #include <vector> | 35 #include <vector> |
36 | 36 |
37 #include "base/file_util.h" | 37 #include "base/file_util.h" |
38 #include "base/files/file_path.h" | 38 #include "base/files/file_path.h" |
39 #include "base/format_macros.h" | 39 #include "base/format_macros.h" |
40 #include "base/strings/stringprintf.h" | 40 #include "base/strings/stringprintf.h" |
41 #include "webkit/browser/fileapi/obfuscated_file_util.h" | 41 #include "storage/browser/fileapi/obfuscated_file_util.h" |
42 #include "webkit/browser/fileapi/sandbox_directory_database.h" | 42 #include "storage/browser/fileapi/sandbox_directory_database.h" |
43 #include "webkit/browser/fileapi/sandbox_file_system_backend.h" | 43 #include "storage/browser/fileapi/sandbox_file_system_backend.h" |
44 #include "webkit/browser/fileapi/sandbox_origin_database.h" | 44 #include "storage/browser/fileapi/sandbox_origin_database.h" |
45 #include "webkit/common/fileapi/file_system_types.h" | 45 #include "storage/common/fileapi/file_system_types.h" |
46 #include "webkit/common/fileapi/file_system_util.h" | 46 #include "storage/common/fileapi/file_system_util.h" |
47 | 47 |
48 namespace { | 48 namespace { |
49 | 49 |
50 bool g_opt_long; | 50 bool g_opt_long; |
51 const char* g_opt_fs_type = "p"; | 51 const char* g_opt_fs_type = "p"; |
52 | 52 |
53 void ShowMessageAndExit(const std::string& msg) { | 53 void ShowMessageAndExit(const std::string& msg) { |
54 fprintf(stderr, "%s\n", msg.c_str()); | 54 fprintf(stderr, "%s\n", msg.c_str()); |
55 exit(EXIT_FAILURE); | 55 exit(EXIT_FAILURE); |
56 } | 56 } |
57 | 57 |
58 void ShowUsageAndExit(const std::string& arg0) { | 58 void ShowUsageAndExit(const std::string& arg0) { |
59 ShowMessageAndExit( | 59 ShowMessageAndExit("Usage: " + arg0 + |
60 "Usage: " + arg0 + | 60 " [-l] [-t] [-s] <filesystem dir> [origin]..."); |
61 " [-l] [-t] [-s] <filesystem dir> [origin]..."); | |
62 } | 61 } |
63 | 62 |
64 } // namespace | 63 } // namespace |
65 | 64 |
66 namespace fileapi { | 65 namespace storage { |
67 | 66 |
68 static void DumpDirectoryTree(const std::string& origin_name, | 67 static void DumpDirectoryTree(const std::string& origin_name, |
69 base::FilePath origin_dir) { | 68 base::FilePath origin_dir) { |
70 origin_dir = origin_dir.Append(g_opt_fs_type); | 69 origin_dir = origin_dir.Append(g_opt_fs_type); |
71 | 70 |
72 printf("=== ORIGIN %s %s ===\n", | 71 printf("=== ORIGIN %s %s ===\n", |
73 origin_name.c_str(), FilePathToString(origin_dir).c_str()); | 72 origin_name.c_str(), |
| 73 FilePathToString(origin_dir).c_str()); |
74 | 74 |
75 if (!base::DirectoryExists(origin_dir)) | 75 if (!base::DirectoryExists(origin_dir)) |
76 return; | 76 return; |
77 | 77 |
78 SandboxDirectoryDatabase directory_db(origin_dir, NULL); | 78 SandboxDirectoryDatabase directory_db(origin_dir, NULL); |
79 SandboxDirectoryDatabase::FileId root_id; | 79 SandboxDirectoryDatabase::FileId root_id; |
80 if (!directory_db.GetFileWithPath(StringToFilePath("/"), &root_id)) | 80 if (!directory_db.GetFileWithPath(StringToFilePath("/"), &root_id)) |
81 return; | 81 return; |
82 | 82 |
83 std::stack<std::pair<SandboxDirectoryDatabase::FileId, | 83 std::stack<std::pair<SandboxDirectoryDatabase::FileId, std::string> > paths; |
84 std::string> > paths; | |
85 paths.push(std::make_pair(root_id, "")); | 84 paths.push(std::make_pair(root_id, "")); |
86 while (!paths.empty()) { | 85 while (!paths.empty()) { |
87 SandboxDirectoryDatabase::FileId id = paths.top().first; | 86 SandboxDirectoryDatabase::FileId id = paths.top().first; |
88 const std::string dirname = paths.top().second; | 87 const std::string dirname = paths.top().second; |
89 paths.pop(); | 88 paths.pop(); |
90 | 89 |
91 SandboxDirectoryDatabase::FileInfo info; | 90 SandboxDirectoryDatabase::FileInfo info; |
92 if (!directory_db.GetFileInfo(id, &info)) { | 91 if (!directory_db.GetFileInfo(id, &info)) { |
93 ShowMessageAndExit(base::StringPrintf("GetFileInfo failed for %"PRId64, | 92 ShowMessageAndExit( |
94 id)); | 93 base::StringPrintf("GetFileInfo failed for %" PRId64, id)); |
95 } | 94 } |
96 | 95 |
97 const std::string name = | 96 const std::string name = |
98 dirname + "/" + FilePathToString(base::FilePath(info.name)); | 97 dirname + "/" + FilePathToString(base::FilePath(info.name)); |
99 std::vector<SandboxDirectoryDatabase::FileId> children; | 98 std::vector<SandboxDirectoryDatabase::FileId> children; |
100 if (info.is_directory()) { | 99 if (info.is_directory()) { |
101 if (!directory_db.ListChildren(id, &children)) { | 100 if (!directory_db.ListChildren(id, &children)) { |
102 ShowMessageAndExit(base::StringPrintf( | 101 ShowMessageAndExit(base::StringPrintf( |
103 "ListChildren failed for %s (%"PRId64")", | 102 "ListChildren failed for %s (%" PRId64 ")", info.name.c_str(), id)); |
104 info.name.c_str(), id)); | |
105 } | 103 } |
106 | 104 |
107 for (size_t j = children.size(); j; j--) | 105 for (size_t j = children.size(); j; j--) |
108 paths.push(make_pair(children[j-1], name)); | 106 paths.push(make_pair(children[j - 1], name)); |
109 } | 107 } |
110 | 108 |
111 // +1 for the leading extra slash. | 109 // +1 for the leading extra slash. |
112 const char* display_name = name.c_str() + 1; | 110 const char* display_name = name.c_str() + 1; |
113 const char* directory_suffix = info.is_directory() ? "/" : ""; | 111 const char* directory_suffix = info.is_directory() ? "/" : ""; |
114 if (g_opt_long) { | 112 if (g_opt_long) { |
115 int64 size; | 113 int64 size; |
116 if (info.is_directory()) { | 114 if (info.is_directory()) { |
117 size = static_cast<int64>(children.size()); | 115 size = static_cast<int64>(children.size()); |
118 } else { | 116 } else { |
119 base::GetFileSize(origin_dir.Append(info.data_path), &size); | 117 base::GetFileSize(origin_dir.Append(info.data_path), &size); |
120 } | 118 } |
121 // TODO(hamaji): Modification time? | 119 // TODO(hamaji): Modification time? |
122 printf("%s%s %"PRId64" %"PRId64" %s\n", | 120 printf("%s%s %" PRId64 " %" PRId64 " %s\n", |
123 display_name, | 121 display_name, |
124 directory_suffix, | 122 directory_suffix, |
125 id, | 123 id, |
126 size, | 124 size, |
127 FilePathToString(info.data_path).c_str()); | 125 FilePathToString(info.data_path).c_str()); |
128 } else { | 126 } else { |
129 printf("%s%s\n", display_name, directory_suffix); | 127 printf("%s%s\n", display_name, directory_suffix); |
130 } | 128 } |
131 } | 129 } |
132 } | 130 } |
133 | 131 |
134 static void DumpOrigin(const base::FilePath& file_system_dir, | 132 static void DumpOrigin(const base::FilePath& file_system_dir, |
135 const std::string& origin_name) { | 133 const std::string& origin_name) { |
136 SandboxOriginDatabase origin_db(file_system_dir, NULL); | 134 SandboxOriginDatabase origin_db(file_system_dir, NULL); |
137 base::FilePath origin_dir; | 135 base::FilePath origin_dir; |
138 if (!origin_db.HasOriginPath(origin_name)) { | 136 if (!origin_db.HasOriginPath(origin_name)) { |
139 ShowMessageAndExit("Origin " + origin_name + " is not in " + | 137 ShowMessageAndExit("Origin " + origin_name + " is not in " + |
140 FilePathToString(file_system_dir)); | 138 FilePathToString(file_system_dir)); |
141 } | 139 } |
142 | 140 |
143 if (!origin_db.GetPathForOrigin(origin_name, &origin_dir)) { | 141 if (!origin_db.GetPathForOrigin(origin_name, &origin_dir)) { |
144 ShowMessageAndExit("Failed to get path of origin " + origin_name + | 142 ShowMessageAndExit("Failed to get path of origin " + origin_name + " in " + |
145 " in " + FilePathToString(file_system_dir)); | 143 FilePathToString(file_system_dir)); |
146 } | 144 } |
147 DumpDirectoryTree(origin_name, file_system_dir.Append(origin_dir)); | 145 DumpDirectoryTree(origin_name, file_system_dir.Append(origin_dir)); |
148 } | 146 } |
149 | 147 |
150 static void DumpFileSystem(const base::FilePath& file_system_dir) { | 148 static void DumpFileSystem(const base::FilePath& file_system_dir) { |
151 SandboxOriginDatabase origin_db(file_system_dir, NULL); | 149 SandboxOriginDatabase origin_db(file_system_dir, NULL); |
152 std::vector<SandboxOriginDatabase::OriginRecord> origins; | 150 std::vector<SandboxOriginDatabase::OriginRecord> origins; |
153 origin_db.ListAllOrigins(&origins); | 151 origin_db.ListAllOrigins(&origins); |
154 for (size_t i = 0; i < origins.size(); i++) { | 152 for (size_t i = 0; i < origins.size(); i++) { |
155 const SandboxOriginDatabase::OriginRecord& origin = origins[i]; | 153 const SandboxOriginDatabase::OriginRecord& origin = origins[i]; |
156 DumpDirectoryTree(origin.origin, file_system_dir.Append(origin.path)); | 154 DumpDirectoryTree(origin.origin, file_system_dir.Append(origin.path)); |
157 puts(""); | 155 puts(""); |
158 } | 156 } |
159 } | 157 } |
160 | 158 |
161 } // namespace fileapi | 159 } // namespace storage |
162 | 160 |
163 int main(int argc, char* argv[]) { | 161 int main(int argc, char* argv[]) { |
164 const char* arg0 = argv[0]; | 162 const char* arg0 = argv[0]; |
165 std::string username = "Default"; | 163 std::string username = "Default"; |
166 while (true) { | 164 while (true) { |
167 if (argc < 2) | 165 if (argc < 2) |
168 ShowUsageAndExit(arg0); | 166 ShowUsageAndExit(arg0); |
169 | 167 |
170 if (std::string(argv[1]) == "-l") { | 168 if (std::string(argv[1]) == "-l") { |
171 g_opt_long = true; | 169 g_opt_long = true; |
172 argc--; | 170 argc--; |
173 argv++; | 171 argv++; |
174 } else if (std::string(argv[1]) == "-t") { | 172 } else if (std::string(argv[1]) == "-t") { |
175 g_opt_fs_type = "t"; | 173 g_opt_fs_type = "t"; |
176 argc--; | 174 argc--; |
177 argv++; | 175 argv++; |
178 } else if (std::string(argv[1]) == "-s") { | 176 } else if (std::string(argv[1]) == "-s") { |
179 g_opt_fs_type = "s"; | 177 g_opt_fs_type = "s"; |
180 argc--; | 178 argc--; |
181 argv++; | 179 argv++; |
182 } else { | 180 } else { |
183 break; | 181 break; |
184 } | 182 } |
185 } | 183 } |
186 | 184 |
187 if (argc < 2) | 185 if (argc < 2) |
188 ShowUsageAndExit(arg0); | 186 ShowUsageAndExit(arg0); |
189 | 187 |
190 const base::FilePath file_system_dir = fileapi::StringToFilePath(argv[1]); | 188 const base::FilePath file_system_dir = storage::StringToFilePath(argv[1]); |
191 if (!base::DirectoryExists(file_system_dir)) { | 189 if (!base::DirectoryExists(file_system_dir)) { |
192 ShowMessageAndExit(fileapi::FilePathToString(file_system_dir) + | 190 ShowMessageAndExit(storage::FilePathToString(file_system_dir) + |
193 " is not a filesystem directory"); | 191 " is not a filesystem directory"); |
194 } | 192 } |
195 | 193 |
196 if (argc == 2) { | 194 if (argc == 2) { |
197 fileapi::DumpFileSystem(file_system_dir); | 195 storage::DumpFileSystem(file_system_dir); |
198 } else { | 196 } else { |
199 for (int i = 2; i < argc; i++) { | 197 for (int i = 2; i < argc; i++) { |
200 fileapi::DumpOrigin(file_system_dir, argv[i]); | 198 storage::DumpOrigin(file_system_dir, argv[i]); |
201 } | 199 } |
202 } | 200 } |
203 return 0; | 201 return 0; |
204 } | 202 } |
OLD | NEW |