Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(149)

Side by Side Diff: base/file_util_win.cc

Issue 8825: Begin the first small step towards using FilePath everywhere: (Closed)
Patch Set: works on windows Created 12 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « base/file_util_unittest.cc ('k') | base/icu_util.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2006-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 #include "base/file_util.h" 5 #include "base/file_util.h"
6 6
7 #include <windows.h> 7 #include <windows.h>
8 #include <shellapi.h> 8 #include <shellapi.h>
9 #include <shlobj.h> 9 #include <shlobj.h>
10 #include <time.h> 10 #include <time.h>
11 #include <string> 11 #include <string>
12 12
13 #include "base/file_path.h"
13 #include "base/logging.h" 14 #include "base/logging.h"
14 #include "base/scoped_handle.h" 15 #include "base/scoped_handle.h"
15 #include "base/string_util.h" 16 #include "base/string_util.h"
16 #include "base/win_util.h" 17 #include "base/win_util.h"
17 18
18 namespace file_util { 19 namespace file_util {
19 20
20 const wchar_t kPathSeparator = L'\\'; 21 const wchar_t kPathSeparator = L'\\';
21 22
22 std::wstring GetDirectoryFromPath(const std::wstring& path) { 23 std::wstring GetDirectoryFromPath(const std::wstring& path) {
23 wchar_t path_buffer[MAX_PATH]; 24 wchar_t path_buffer[MAX_PATH];
24 wchar_t* file_ptr = NULL; 25 wchar_t* file_ptr = NULL;
25 if (GetFullPathName(path.c_str(), MAX_PATH, path_buffer, &file_ptr) == 0) 26 if (GetFullPathName(path.c_str(), MAX_PATH, path_buffer, &file_ptr) == 0)
26 return L""; 27 return L"";
27 28
28 std::wstring::size_type length = 29 std::wstring::size_type length =
29 file_ptr ? file_ptr - path_buffer : path.length(); 30 file_ptr ? file_ptr - path_buffer : path.length();
30 std::wstring directory(path, 0, length); 31 std::wstring directory(path, 0, length);
31 TrimTrailingSeparator(&directory); 32 TrimTrailingSeparator(&directory);
32 return directory; 33 return directory;
33 } 34 }
34 35
35 bool AbsolutePath(std::wstring* path) { 36 bool AbsolutePath(FilePath* path) {
36 wchar_t file_path_buf[MAX_PATH]; 37 wchar_t file_path_buf[MAX_PATH];
37 if (!_wfullpath(file_path_buf, path->c_str(), MAX_PATH)) 38 if (!_wfullpath(file_path_buf, path->value().c_str(), MAX_PATH))
38 return false; 39 return false;
39 *path = file_path_buf; 40 *path = FilePath(file_path_buf);
40 return true; 41 return true;
41 } 42 }
42 43
43 int CountFilesCreatedAfter(const std::wstring& path, 44 int CountFilesCreatedAfter(const std::wstring& path,
44 const FILETIME& comparison_time) { 45 const FILETIME& comparison_time) {
45 int file_count = 0; 46 int file_count = 0;
46 47
47 WIN32_FIND_DATA find_file_data; 48 WIN32_FIND_DATA find_file_data;
48 std::wstring filename_spec = path + L"\\*"; // All files in given dir 49 std::wstring filename_spec = path + L"\\*"; // All files in given dir
49 HANDLE find_handle = FindFirstFile(filename_spec.c_str(), &find_file_data); 50 HANDLE find_handle = FindFirstFile(filename_spec.c_str(), &find_file_data);
50 if (find_handle != INVALID_HANDLE_VALUE) { 51 if (find_handle != INVALID_HANDLE_VALUE) {
51 do { 52 do {
52 // Don't count current or parent directories. 53 // Don't count current or parent directories.
53 if ((wcscmp(find_file_data.cFileName, L"..") == 0) || 54 if ((wcscmp(find_file_data.cFileName, L"..") == 0) ||
54 (wcscmp(find_file_data.cFileName, L".") == 0)) 55 (wcscmp(find_file_data.cFileName, L".") == 0))
55 continue; 56 continue;
56 57
57 long result = CompareFileTime(&find_file_data.ftCreationTime, 58 long result = CompareFileTime(&find_file_data.ftCreationTime,
58 &comparison_time); 59 &comparison_time);
59 // File was created after or on comparison time 60 // File was created after or on comparison time
60 if ((result == 1) || (result == 0)) 61 if ((result == 1) || (result == 0))
61 ++file_count; 62 ++file_count;
62 } while (FindNextFile(find_handle, &find_file_data)); 63 } while (FindNextFile(find_handle, &find_file_data));
63 FindClose(find_handle); 64 FindClose(find_handle);
64 } 65 }
65 66
66 return file_count; 67 return file_count;
67 } 68 }
68 69
69 bool Delete(const std::wstring& path, bool recursive) { 70 bool Delete(const FilePath& path, bool recursive) {
70 if (path.length() >= MAX_PATH) 71 if (path.value().length() >= MAX_PATH)
71 return false; 72 return false;
72 73
73 // If we're not recursing use DeleteFile; it should be faster. DeleteFile 74 // If we're not recursing use DeleteFile; it should be faster. DeleteFile
74 // fails if passed a directory though, which is why we fall through on 75 // fails if passed a directory though, which is why we fall through on
75 // failure to the SHFileOperation. 76 // failure to the SHFileOperation.
76 if (!recursive && DeleteFile(path.c_str()) != 0) 77 if (!recursive && DeleteFile(path.value().c_str()) != 0)
77 return true; 78 return true;
78 79
79 // SHFILEOPSTRUCT wants the path to be terminated with two NULLs, 80 // SHFILEOPSTRUCT wants the path to be terminated with two NULLs,
80 // so we have to use wcscpy because wcscpy_s writes non-NULLs 81 // so we have to use wcscpy because wcscpy_s writes non-NULLs
81 // into the rest of the buffer. 82 // into the rest of the buffer.
82 wchar_t double_terminated_path[MAX_PATH + 1] = {0}; 83 wchar_t double_terminated_path[MAX_PATH + 1] = {0};
83 #pragma warning(suppress:4996) // don't complain about wcscpy deprecation 84 #pragma warning(suppress:4996) // don't complain about wcscpy deprecation
84 wcscpy(double_terminated_path, path.c_str()); 85 wcscpy(double_terminated_path, path.value().c_str());
85 86
86 SHFILEOPSTRUCT file_operation = {0}; 87 SHFILEOPSTRUCT file_operation = {0};
87 file_operation.wFunc = FO_DELETE; 88 file_operation.wFunc = FO_DELETE;
88 file_operation.pFrom = double_terminated_path; 89 file_operation.pFrom = double_terminated_path;
89 file_operation.fFlags = FOF_NOERRORUI | FOF_SILENT | FOF_NOCONFIRMATION; 90 file_operation.fFlags = FOF_NOERRORUI | FOF_SILENT | FOF_NOCONFIRMATION;
90 if (!recursive) 91 if (!recursive)
91 file_operation.fFlags |= FOF_NORECURSION | FOF_FILESONLY; 92 file_operation.fFlags |= FOF_NORECURSION | FOF_FILESONLY;
92 return (SHFileOperation(&file_operation) == 0); 93 return (SHFileOperation(&file_operation) == 0);
93 } 94 }
94 95
95 bool Move(const std::wstring& from_path, const std::wstring& to_path) { 96 bool Move(const FilePath& from_path, const FilePath& to_path) {
96 // NOTE: I suspect we could support longer paths, but that would involve 97 // NOTE: I suspect we could support longer paths, but that would involve
97 // analyzing all our usage of files. 98 // analyzing all our usage of files.
98 if (from_path.length() >= MAX_PATH || to_path.length() >= MAX_PATH) 99 if (from_path.value().length() >= MAX_PATH ||
100 to_path.value().length() >= MAX_PATH) {
99 return false; 101 return false;
100 return (MoveFileEx(from_path.c_str(), to_path.c_str(), 102 }
103 return (MoveFileEx(from_path.value().c_str(), to_path.value().c_str(),
101 MOVEFILE_COPY_ALLOWED | MOVEFILE_REPLACE_EXISTING) != 0); 104 MOVEFILE_COPY_ALLOWED | MOVEFILE_REPLACE_EXISTING) != 0);
102 } 105 }
103 106
104 bool CopyFile(const std::wstring& from_path, const std::wstring& to_path) { 107 bool CopyFile(const FilePath& from_path, const FilePath& to_path) {
105 // NOTE: I suspect we could support longer paths, but that would involve 108 // NOTE: I suspect we could support longer paths, but that would involve
106 // analyzing all our usage of files. 109 // analyzing all our usage of files.
107 if (from_path.length() >= MAX_PATH || to_path.length() >= MAX_PATH) 110 if (from_path.value().length() >= MAX_PATH ||
111 to_path.value().length() >= MAX_PATH) {
108 return false; 112 return false;
109 return (::CopyFile(from_path.c_str(), to_path.c_str(), false) != 0); 113 }
114 return (::CopyFile(from_path.value().c_str(), to_path.value().c_str(),
115 false) != 0);
110 } 116 }
111 117
112 bool ShellCopy(const std::wstring& from_path, const std::wstring& to_path, 118 bool ShellCopy(const FilePath& from_path, const FilePath& to_path,
113 bool recursive) { 119 bool recursive) {
114 // NOTE: I suspect we could support longer paths, but that would involve 120 // NOTE: I suspect we could support longer paths, but that would involve
115 // analyzing all our usage of files. 121 // analyzing all our usage of files.
116 if (from_path.length() >= MAX_PATH || to_path.length() >= MAX_PATH) 122 if (from_path.value().length() >= MAX_PATH ||
123 to_path.value().length() >= MAX_PATH) {
117 return false; 124 return false;
125 }
118 126
119 // SHFILEOPSTRUCT wants the path to be terminated with two NULLs, 127 // SHFILEOPSTRUCT wants the path to be terminated with two NULLs,
120 // so we have to use wcscpy because wcscpy_s writes non-NULLs 128 // so we have to use wcscpy because wcscpy_s writes non-NULLs
121 // into the rest of the buffer. 129 // into the rest of the buffer.
122 wchar_t double_terminated_path_from[MAX_PATH + 1] = {0}; 130 wchar_t double_terminated_path_from[MAX_PATH + 1] = {0};
123 wchar_t double_terminated_path_to[MAX_PATH + 1] = {0}; 131 wchar_t double_terminated_path_to[MAX_PATH + 1] = {0};
124 #pragma warning(suppress:4996) // don't complain about wcscpy deprecation 132 #pragma warning(suppress:4996) // don't complain about wcscpy deprecation
125 wcscpy(double_terminated_path_from, from_path.c_str()); 133 wcscpy(double_terminated_path_from, from_path.value().c_str());
126 #pragma warning(suppress:4996) // don't complain about wcscpy deprecation 134 #pragma warning(suppress:4996) // don't complain about wcscpy deprecation
127 wcscpy(double_terminated_path_to, to_path.c_str()); 135 wcscpy(double_terminated_path_to, to_path.value().c_str());
128 136
129 SHFILEOPSTRUCT file_operation = {0}; 137 SHFILEOPSTRUCT file_operation = {0};
130 file_operation.wFunc = FO_COPY; 138 file_operation.wFunc = FO_COPY;
131 file_operation.pFrom = double_terminated_path_from; 139 file_operation.pFrom = double_terminated_path_from;
132 file_operation.pTo = double_terminated_path_to; 140 file_operation.pTo = double_terminated_path_to;
133 file_operation.fFlags = FOF_NOERRORUI | FOF_SILENT | FOF_NOCONFIRMATION | 141 file_operation.fFlags = FOF_NOERRORUI | FOF_SILENT | FOF_NOCONFIRMATION |
134 FOF_NOCONFIRMMKDIR; 142 FOF_NOCONFIRMMKDIR;
135 if (!recursive) 143 if (!recursive)
136 file_operation.fFlags |= FOF_NORECURSION | FOF_FILESONLY; 144 file_operation.fFlags |= FOF_NORECURSION | FOF_FILESONLY;
137 145
138 return (SHFileOperation(&file_operation) == 0); 146 return (SHFileOperation(&file_operation) == 0);
139 } 147 }
140 148
141 bool CopyDirectory(const std::wstring& from_path, const std::wstring& to_path, 149 bool CopyDirectory(const FilePath& from_path, const FilePath& to_path,
142 bool recursive) { 150 bool recursive) {
143 if (recursive) 151 if (recursive)
144 return ShellCopy(from_path, to_path, true); 152 return ShellCopy(from_path, to_path, true);
145 153
146 // Instead of creating a new directory, we copy the old one to include the 154 // Instead of creating a new directory, we copy the old one to include the
147 // security information of the folder as part of the copy. 155 // security information of the folder as part of the copy.
148 if (!PathExists(to_path)) { 156 if (!PathExists(to_path)) {
149 // Except that Vista fails to do that, and instead do a recursive copy if 157 // Except that Vista fails to do that, and instead do a recursive copy if
150 // the target directory doesn't exist. 158 // the target directory doesn't exist.
151 if (win_util::GetWinVersion() >= win_util::WINVERSION_VISTA) 159 if (win_util::GetWinVersion() >= win_util::WINVERSION_VISTA)
152 CreateDirectory(to_path); 160 CreateDirectory(to_path);
153 else 161 else
154 ShellCopy(from_path, to_path, false); 162 ShellCopy(from_path, to_path, false);
155 } 163 }
156 164
157 std::wstring directory(from_path); 165 FilePath directory = from_path.Append(L"*.*");
158 AppendToPath(&directory, L"*.*");
159 return ShellCopy(directory, to_path, false); 166 return ShellCopy(directory, to_path, false);
160 } 167 }
161 168
162 bool PathExists(const std::wstring& path) { 169 bool PathExists(const FilePath& path) {
163 return (GetFileAttributes(path.c_str()) != INVALID_FILE_ATTRIBUTES); 170 return (GetFileAttributes(path.value().c_str()) != INVALID_FILE_ATTRIBUTES);
164 } 171 }
165 172
166 bool PathIsWritable(const std::wstring& path) { 173 bool PathIsWritable(const std::wstring& path) {
167 HANDLE dir = 174 HANDLE dir =
168 CreateFile(path.c_str(), FILE_ADD_FILE, 175 CreateFile(path.c_str(), FILE_ADD_FILE,
169 FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE, 176 FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE,
170 NULL, OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, NULL); 177 NULL, OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, NULL);
171 178
172 if (dir == INVALID_HANDLE_VALUE) 179 if (dir == INVALID_HANDLE_VALUE)
173 return false; 180 return false;
174 181
175 CloseHandle(dir); 182 CloseHandle(dir);
176 return true; 183 return true;
177 } 184 }
178 185
179 bool DirectoryExists(const std::wstring& path) { 186 bool DirectoryExists(const FilePath& path) {
180 DWORD fileattr = GetFileAttributes(path.c_str()); 187 DWORD fileattr = GetFileAttributes(path.value().c_str());
181 if (fileattr != INVALID_FILE_ATTRIBUTES) 188 if (fileattr != INVALID_FILE_ATTRIBUTES)
182 return (fileattr & FILE_ATTRIBUTE_DIRECTORY) != 0; 189 return (fileattr & FILE_ATTRIBUTE_DIRECTORY) != 0;
183 return false; 190 return false;
184 } 191 }
185 192
186 bool GetFileCreationLocalTimeFromHandle(HANDLE file_handle, 193 bool GetFileCreationLocalTimeFromHandle(HANDLE file_handle,
187 LPSYSTEMTIME creation_time) { 194 LPSYSTEMTIME creation_time) {
188 if (!file_handle) 195 if (!file_handle)
189 return false; 196 return false;
190 197
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after
365 return SUCCEEDED(result); 372 return SUCCEEDED(result);
366 } 373 }
367 374
368 bool IsDirectoryEmpty(const std::wstring& dir_path) { 375 bool IsDirectoryEmpty(const std::wstring& dir_path) {
369 FileEnumerator files(dir_path, false, FileEnumerator::FILES_AND_DIRECTORIES); 376 FileEnumerator files(dir_path, false, FileEnumerator::FILES_AND_DIRECTORIES);
370 if (files.Next().empty()) 377 if (files.Next().empty())
371 return true; 378 return true;
372 return false; 379 return false;
373 } 380 }
374 381
375 bool GetTempDir(std::wstring* path) { 382 bool GetTempDir(FilePath* path) {
376 wchar_t temp_path[MAX_PATH + 1]; 383 wchar_t temp_path[MAX_PATH + 1];
377 DWORD path_len = ::GetTempPath(MAX_PATH, temp_path); 384 DWORD path_len = ::GetTempPath(MAX_PATH, temp_path);
378 if (path_len >= MAX_PATH || path_len <= 0) 385 if (path_len >= MAX_PATH || path_len <= 0)
379 return false; 386 return false;
380 path->assign(temp_path); 387 // TODO(evanm): the old behavior of this function was to always strip the
381 TrimTrailingSeparator(path); 388 // trailing slash. We duplicate this here, but it shouldn't be necessary
389 // when everyone is using the appropriate FilePath APIs.
390 std::wstring path_str(temp_path);
391 TrimTrailingSeparator(&path_str);
392 *path = FilePath(path_str);
382 return true; 393 return true;
383 } 394 }
384 395
385 bool CreateTemporaryFileName(std::wstring* temp_file) { 396 bool CreateTemporaryFileName(std::wstring* temp_file) {
386 std::wstring temp_path; 397 std::wstring temp_path;
387 398
388 if (!GetTempDir(&temp_path)) 399 if (!GetTempDir(&temp_path))
389 return false; 400 return false;
390 401
391 return CreateTemporaryFileNameInDir(temp_path, temp_file); 402 return CreateTemporaryFileNameInDir(temp_path, temp_file);
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
431 } 442 }
432 443
433 if (count == 50) { 444 if (count == 50) {
434 return false; 445 return false;
435 } 446 }
436 447
437 new_temp_path->assign(path_to_create); 448 new_temp_path->assign(path_to_create);
438 return true; 449 return true;
439 } 450 }
440 451
441 bool CreateDirectory(const std::wstring& full_path) { 452 bool CreateDirectory(const FilePath& full_path) {
442 if (DirectoryExists(full_path)) 453 if (DirectoryExists(full_path))
443 return true; 454 return true;
444 int err = SHCreateDirectoryEx(NULL, full_path.c_str(), NULL); 455 int err = SHCreateDirectoryEx(NULL, full_path.value().c_str(), NULL);
445 return err == ERROR_SUCCESS; 456 return err == ERROR_SUCCESS;
446 } 457 }
447 458
448 bool GetFileInfo(const std::wstring& file_path, FileInfo* results) { 459 bool GetFileInfo(const std::wstring& file_path, FileInfo* results) {
449 WIN32_FILE_ATTRIBUTE_DATA attr; 460 WIN32_FILE_ATTRIBUTE_DATA attr;
450 if (!GetFileAttributesEx(file_path.c_str(), GetFileExInfoStandard, &attr)) 461 if (!GetFileAttributesEx(file_path.c_str(), GetFileExInfoStandard, &attr))
451 return false; 462 return false;
452 463
453 ULARGE_INTEGER size; 464 ULARGE_INTEGER size;
454 size.HighPart = attr.nFileSizeHigh; 465 size.HighPart = attr.nFileSizeHigh;
455 size.LowPart = attr.nFileSizeLow; 466 size.LowPart = attr.nFileSizeLow;
456 results->size = size.QuadPart; 467 results->size = size.QuadPart;
457 468
458 results->is_directory = 469 results->is_directory =
459 (attr.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) != 0; 470 (attr.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) != 0;
460 return true; 471 return true;
461 } 472 }
462 473
474 FILE* OpenFile(const FilePath& filename, const char* mode) {
475 std::wstring w_mode = ASCIIToWide(std::string(mode));
476 FILE* file;
477 if (_wfopen_s(&file, filename.value().c_str(), w_mode.c_str()) != 0) {
478 return NULL;
479 }
480 return file;
481 }
482
463 FILE* OpenFile(const std::string& filename, const char* mode) { 483 FILE* OpenFile(const std::string& filename, const char* mode) {
464 FILE* file; 484 FILE* file;
465 if (fopen_s(&file, filename.c_str(), mode) != 0) { 485 if (fopen_s(&file, filename.c_str(), mode) != 0) {
466 return NULL; 486 return NULL;
467 } 487 }
468 return file; 488 return file;
469 } 489 }
470 490
471 FILE* OpenFile(const std::wstring& filename, const char* mode) { 491 FILE* OpenFile(const std::wstring& filename, const char* mode) {
472 std::wstring w_mode = ASCIIToWide(std::string(mode)); 492 return OpenFile(FilePath(filename), mode);
473 FILE* file;
474 if (_wfopen_s(&file, filename.c_str(), w_mode.c_str()) != 0) {
475 return NULL;
476 }
477 return file;
478 } 493 }
479 494
480 int ReadFile(const std::wstring& filename, char* data, int size) { 495 int ReadFile(const std::wstring& filename, char* data, int size) {
481 ScopedHandle file(CreateFile(filename.c_str(), 496 ScopedHandle file(CreateFile(filename.c_str(),
482 GENERIC_READ, 497 GENERIC_READ,
483 FILE_SHARE_READ | FILE_SHARE_WRITE, 498 FILE_SHARE_READ | FILE_SHARE_WRITE,
484 NULL, 499 NULL,
485 OPEN_EXISTING, 500 OPEN_EXISTING,
486 FILE_FLAG_SEQUENTIAL_SCAN, 501 FILE_FLAG_SEQUENTIAL_SCAN,
487 NULL)); 502 NULL));
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
549 move_info.fFlags = FOF_SILENT | FOF_NOCONFIRMATION | FOF_NOERRORUI | 564 move_info.fFlags = FOF_SILENT | FOF_NOCONFIRMATION | FOF_NOERRORUI |
550 FOF_NOCONFIRMMKDIR | FOF_NOCOPYSECURITYATTRIBS; 565 FOF_NOCONFIRMMKDIR | FOF_NOCOPYSECURITYATTRIBS;
551 566
552 if (0 != SHFileOperation(&move_info)) 567 if (0 != SHFileOperation(&move_info))
553 return false; 568 return false;
554 569
555 return true; 570 return true;
556 } 571 }
557 572
558 // Gets the current working directory for the process. 573 // Gets the current working directory for the process.
559 bool GetCurrentDirectory(std::wstring* dir) { 574 bool GetCurrentDirectory(FilePath* dir) {
560 wchar_t system_buffer[MAX_PATH]; 575 wchar_t system_buffer[MAX_PATH];
561 system_buffer[0] = 0; 576 system_buffer[0] = 0;
562 DWORD len = ::GetCurrentDirectory(MAX_PATH, system_buffer); 577 DWORD len = ::GetCurrentDirectory(MAX_PATH, system_buffer);
563 if (len == 0 || len > MAX_PATH) 578 if (len == 0 || len > MAX_PATH)
564 return false; 579 return false;
565 *dir = system_buffer; 580 // TODO(evanm): the old behavior of this function was to always strip the
566 file_util::TrimTrailingSeparator(dir); 581 // trailing slash. We duplicate this here, but it shouldn't be necessary
582 // when everyone is using the appropriate FilePath APIs.
583 std::wstring dir_str(system_buffer);
584 file_util::TrimTrailingSeparator(&dir_str);
585 *dir = FilePath(dir_str);
567 return true; 586 return true;
568 } 587 }
569 588
570 // Sets the current working directory for the process. 589 // Sets the current working directory for the process.
571 bool SetCurrentDirectory(const std::wstring& current_directory) { 590 bool SetCurrentDirectory(const std::wstring& current_directory) {
572 BOOL ret = ::SetCurrentDirectory(current_directory.c_str()); 591 BOOL ret = ::SetCurrentDirectory(current_directory.c_str());
573 return (ret ? true : false); 592 return (ret ? true : false);
574 } 593 }
575 594
576 /////////////////////////////////////////////// 595 ///////////////////////////////////////////////
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
660 // it to pending_paths_ so we scan it after we finish scanning this 679 // it to pending_paths_ so we scan it after we finish scanning this
661 // directory. 680 // directory.
662 pending_paths_.push(cur_file); 681 pending_paths_.push(cur_file);
663 } 682 }
664 return (file_type_ & FileEnumerator::DIRECTORIES) ? cur_file : Next(); 683 return (file_type_ & FileEnumerator::DIRECTORIES) ? cur_file : Next();
665 } 684 }
666 return (file_type_ & FileEnumerator::FILES) ? cur_file : Next(); 685 return (file_type_ & FileEnumerator::FILES) ? cur_file : Next();
667 } 686 }
668 687
669 } // namespace file_util 688 } // namespace file_util
OLDNEW
« no previous file with comments | « base/file_util_unittest.cc ('k') | base/icu_util.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698