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 "base/file_util.h" | 5 #include "base/file_util.h" |
6 | 6 |
7 #if defined(OS_WIN) | 7 #if defined(OS_WIN) |
8 #include <io.h> | 8 #include <io.h> |
9 #endif | 9 #endif |
10 #include <stdio.h> | 10 #include <stdio.h> |
11 | 11 |
12 #include <fstream> | 12 #include <fstream> |
13 | 13 |
| 14 #include "base/files/file_enumerator.h" |
14 #include "base/files/file_path.h" | 15 #include "base/files/file_path.h" |
15 #include "base/logging.h" | 16 #include "base/logging.h" |
16 #include "base/string_util.h" | 17 #include "base/string_util.h" |
17 #include "base/stringprintf.h" | 18 #include "base/stringprintf.h" |
18 #include "base/strings/string_piece.h" | 19 #include "base/strings/string_piece.h" |
19 #include "base/utf_string_conversions.h" | 20 #include "base/utf_string_conversions.h" |
20 | 21 |
| 22 using base::FileEnumerator; |
21 using base::FilePath; | 23 using base::FilePath; |
22 | 24 |
23 namespace { | 25 namespace { |
24 | 26 |
25 const FilePath::CharType kExtensionSeparator = FILE_PATH_LITERAL('.'); | 27 const FilePath::CharType kExtensionSeparator = FILE_PATH_LITERAL('.'); |
26 | 28 |
27 // The maximum number of 'uniquified' files we will try to create. | 29 // The maximum number of 'uniquified' files we will try to create. |
28 // This is used when the filename we're trying to download is already in use, | 30 // This is used when the filename we're trying to download is already in use, |
29 // so we create a new unique filename by appending " (nnn)" before the | 31 // so we create a new unique filename by appending " (nnn)" before the |
30 // extension, where 1 <= nnn <= kMaxUniqueFiles. | 32 // extension, where 1 <= nnn <= kMaxUniqueFiles. |
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
158 contents->append(buf, len); | 160 contents->append(buf, len); |
159 } | 161 } |
160 CloseFile(file); | 162 CloseFile(file); |
161 | 163 |
162 return true; | 164 return true; |
163 } | 165 } |
164 | 166 |
165 bool IsDirectoryEmpty(const FilePath& dir_path) { | 167 bool IsDirectoryEmpty(const FilePath& dir_path) { |
166 FileEnumerator files(dir_path, false, | 168 FileEnumerator files(dir_path, false, |
167 FileEnumerator::FILES | FileEnumerator::DIRECTORIES); | 169 FileEnumerator::FILES | FileEnumerator::DIRECTORIES); |
168 if (files.Next().value().empty()) | 170 if (files.Next().empty()) |
169 return true; | 171 return true; |
170 return false; | 172 return false; |
171 } | 173 } |
172 | 174 |
173 FILE* CreateAndOpenTemporaryFile(FilePath* path) { | 175 FILE* CreateAndOpenTemporaryFile(FilePath* path) { |
174 FilePath directory; | 176 FilePath directory; |
175 if (!GetTempDir(&directory)) | 177 if (!GetTempDir(&directory)) |
176 return NULL; | 178 return NULL; |
177 | 179 |
178 return CreateAndOpenTemporaryFileInDir(directory, path); | 180 return CreateAndOpenTemporaryFileInDir(directory, path); |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
255 return count; | 257 return count; |
256 } | 258 } |
257 } | 259 } |
258 | 260 |
259 return -1; | 261 return -1; |
260 } | 262 } |
261 | 263 |
262 int64 ComputeDirectorySize(const FilePath& root_path) { | 264 int64 ComputeDirectorySize(const FilePath& root_path) { |
263 int64 running_size = 0; | 265 int64 running_size = 0; |
264 FileEnumerator file_iter(root_path, true, FileEnumerator::FILES); | 266 FileEnumerator file_iter(root_path, true, FileEnumerator::FILES); |
265 for (FilePath current = file_iter.Next(); !current.empty(); | 267 while (!file_iter.Next().empty()) |
266 current = file_iter.Next()) { | 268 running_size += file_iter.GetInfo().GetSize(); |
267 FileEnumerator::FindInfo info; | |
268 file_iter.GetFindInfo(&info); | |
269 #if defined(OS_WIN) | |
270 LARGE_INTEGER li = { info.nFileSizeLow, info.nFileSizeHigh }; | |
271 running_size += li.QuadPart; | |
272 #else | |
273 running_size += info.stat.st_size; | |
274 #endif | |
275 } | |
276 return running_size; | 269 return running_size; |
277 } | 270 } |
278 | 271 |
279 /////////////////////////////////////////////// | |
280 // FileEnumerator | |
281 // | |
282 // Note: the main logic is in file_util_<platform>.cc | |
283 | |
284 bool FileEnumerator::ShouldSkip(const FilePath& path) { | |
285 FilePath::StringType basename = path.BaseName().value(); | |
286 return basename == FILE_PATH_LITERAL(".") || | |
287 (basename == FILE_PATH_LITERAL("..") && | |
288 !(INCLUDE_DOT_DOT & file_type_)); | |
289 } | |
290 | |
291 } // namespace | 272 } // namespace |
OLD | NEW |