| OLD | NEW |
| 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> |
| (...skipping 377 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 388 return false; | 388 return false; |
| 389 // TODO(evanm): the old behavior of this function was to always strip the | 389 // TODO(evanm): the old behavior of this function was to always strip the |
| 390 // trailing slash. We duplicate this here, but it shouldn't be necessary | 390 // trailing slash. We duplicate this here, but it shouldn't be necessary |
| 391 // when everyone is using the appropriate FilePath APIs. | 391 // when everyone is using the appropriate FilePath APIs. |
| 392 std::wstring path_str(temp_path); | 392 std::wstring path_str(temp_path); |
| 393 TrimTrailingSeparator(&path_str); | 393 TrimTrailingSeparator(&path_str); |
| 394 *path = FilePath(path_str); | 394 *path = FilePath(path_str); |
| 395 return true; | 395 return true; |
| 396 } | 396 } |
| 397 | 397 |
| 398 bool GetShmemTempDir(FilePath* path) { |
| 399 return GetTempDir(path); |
| 400 } |
| 401 |
| 398 bool CreateTemporaryFileName(FilePath* path) { | 402 bool CreateTemporaryFileName(FilePath* path) { |
| 399 std::wstring temp_path, temp_file; | 403 std::wstring temp_path, temp_file; |
| 400 | 404 |
| 401 if (!GetTempDir(&temp_path)) | 405 if (!GetTempDir(&temp_path)) |
| 402 return false; | 406 return false; |
| 403 | 407 |
| 404 if (CreateTemporaryFileNameInDir(temp_path, &temp_file)) { | 408 if (CreateTemporaryFileNameInDir(temp_path, &temp_file)) { |
| 405 *path = FilePath(temp_file); | 409 *path = FilePath(temp_file); |
| 406 return true; | 410 return true; |
| 407 } | 411 } |
| 408 | 412 |
| 409 return false; | 413 return false; |
| 410 } | 414 } |
| 411 | 415 |
| 416 // On POSIX we have semantics to create and open a temporary file |
| 417 // atomically. |
| 418 // TODO(jrg): is there equivalent call to use on Windows instead of |
| 419 // going 2-step? |
| 420 FILE* CreateAndOpenTemporaryFile(FilePath* path) { |
| 421 |
| 422 if (!CreateTemporaryFileName(path)) { |
| 423 return NULL; |
| 424 } |
| 425 return OpenFile(*path, "w+"); |
| 426 } |
| 427 |
| 428 FILE* CreateAndOpenTemporaryShmemFile(FilePath* path) { |
| 429 return CreateAndOpenTemporaryFile(path); |
| 430 } |
| 431 |
| 412 bool CreateTemporaryFileNameInDir(const std::wstring& dir, | 432 bool CreateTemporaryFileNameInDir(const std::wstring& dir, |
| 413 std::wstring* temp_file) { | 433 std::wstring* temp_file) { |
| 414 wchar_t temp_name[MAX_PATH + 1]; | 434 wchar_t temp_name[MAX_PATH + 1]; |
| 415 | 435 |
| 416 if (!GetTempFileName(dir.c_str(), L"", 0, temp_name)) | 436 if (!GetTempFileName(dir.c_str(), L"", 0, temp_name)) |
| 417 return false; // fail! | 437 return false; // fail! |
| 418 | 438 |
| 419 DWORD path_len = GetLongPathName(temp_name, temp_name, MAX_PATH); | 439 DWORD path_len = GetLongPathName(temp_name, temp_name, MAX_PATH); |
| 420 if (path_len > MAX_PATH + 1 || path_len == 0) | 440 if (path_len > MAX_PATH + 1 || path_len == 0) |
| 421 return false; // fail! | 441 return false; // fail! |
| (...skipping 329 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 751 void PathComponents(const std::wstring& path, | 771 void PathComponents(const std::wstring& path, |
| 752 std::vector<std::wstring>* components) { | 772 std::vector<std::wstring>* components) { |
| 753 PathComponents(FilePath(path), components); | 773 PathComponents(FilePath(path), components); |
| 754 } | 774 } |
| 755 void ReplaceExtension(std::wstring* file_name, const std::wstring& extension) { | 775 void ReplaceExtension(std::wstring* file_name, const std::wstring& extension) { |
| 756 FilePath path(*file_name); | 776 FilePath path(*file_name); |
| 757 ReplaceExtension(&path, extension); | 777 ReplaceExtension(&path, extension); |
| 758 file_name->assign(path.value()); | 778 file_name->assign(path.value()); |
| 759 } | 779 } |
| 760 } // namespace file_util | 780 } // namespace file_util |
| OLD | NEW |