Chromium Code Reviews| Index: util/test/scoped_temp_dir_win.cc |
| diff --git a/util/test/scoped_temp_dir_win.cc b/util/test/scoped_temp_dir_win.cc |
| index 19a1d667fc7a1d8cb8de7d8a0605419a658b4706..3b07fda6e1feeb2470cf8bbc08befbb9c1bac404 100644 |
| --- a/util/test/scoped_temp_dir_win.cc |
| +++ b/util/test/scoped_temp_dir_win.cc |
| @@ -26,21 +26,42 @@ |
| namespace crashpad { |
| namespace test { |
| -// static |
| -base::FilePath ScopedTempDir::CreateTemporaryDirectory() { |
| +namespace { |
| + |
| +base::FilePath GenerateCandidateName() { |
| wchar_t temp_path[MAX_PATH + 1]; |
| DWORD path_len = GetTempPath(MAX_PATH, temp_path); |
| PCHECK(path_len != 0) << "GetTempPath"; |
| base::FilePath system_temp_dir(temp_path); |
| + base::string16 new_dir_name = base::UTF8ToUTF16(base::StringPrintf( |
| + "crashpad.test.%d.%I64x", GetCurrentProcessId(), base::RandUint64())); |
| + return system_temp_dir.Append(new_dir_name); |
| +} |
| + |
| +} // namespace |
| +void ScopedTempDir::Rename() { |
| for (int count = 0; count < 50; ++count) { |
|
Mark Mentovai
2015/02/11 17:25:50
50 should be a constant local to this file, in the
scottmg
2015/02/11 19:24:55
Done.
|
| - // Try create a new temporary directory with random generated name. If the |
| - // one we generate exists, keep trying another path name until we reach some |
| + // Try to move to a new temporary directory with a randomly generated name. |
| + // If the one we try exists, retry with a new name until we reach some |
| // limit. |
| - base::string16 new_dir_name = base::UTF8ToUTF16(base::StringPrintf( |
| - "crashpad.test.%d.%I64x", GetCurrentProcessId(), base::RandUint64())); |
| + base::FilePath target_path = GenerateCandidateName(); |
| + if (MoveFileEx(path_.value().c_str(), target_path.value().c_str(), 0)) { |
| + path_ = target_path; |
| + return; |
| + } |
| + } |
| + |
| + CHECK(false) << "Couldn't find temp dir name"; |
| +} |
| - base::FilePath path_to_create = system_temp_dir.Append(new_dir_name); |
| +// static |
| +base::FilePath ScopedTempDir::CreateTemporaryDirectory() { |
| + for (int count = 0; count < 50; ++count) { |
|
Mark Mentovai
2015/02/11 17:25:50
because you use it here too.
scottmg
2015/02/11 19:24:55
Done.
|
| + // Try to create a new temporary directory with random generated name. If |
| + // the one we generate exists, keep trying another path name until we reach |
| + // some limit. |
| + base::FilePath path_to_create = GenerateCandidateName(); |
| if (CreateDirectory(path_to_create.value().c_str(), NULL)) |
| return path_to_create; |
| } |