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

Unified Diff: util/test/scoped_temp_dir_win.cc

Issue 867363003: win: Implementation of CrashReportDatabase for Windows (Closed) Base URL: https://chromium.googlesource.com/crashpad/crashpad@master
Patch Set: . Created 5 years, 10 months 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « util/test/scoped_temp_dir_posix.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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..f641ec2b750d9adb160692e66e4f2ba5edd99bec 100644
--- a/util/test/scoped_temp_dir_win.cc
+++ b/util/test/scoped_temp_dir_win.cc
@@ -26,21 +26,44 @@
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);
+}
+
+const int kRetries = 50;
- for (int count = 0; count < 50; ++count) {
- // 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
+} // namespace
+
+void ScopedTempDir::Rename() {
+ for (int count = 0; count < kRetries; ++count) {
+ // 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;
+ }
+ }
- base::FilePath path_to_create = system_temp_dir.Append(new_dir_name);
+ CHECK(false) << "Couldn't find temp dir name";
+}
+
+// static
+base::FilePath ScopedTempDir::CreateTemporaryDirectory() {
+ for (int count = 0; count < kRetries; ++count) {
+ // 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;
}
« no previous file with comments | « util/test/scoped_temp_dir_posix.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698