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

Side by Side Diff: util/test/scoped_temp_dir_win.cc

Issue 913273002: win: Implementation of CrashReportDatabase for Windows (for C++ Windows readability review) (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 unified diff | Download patch
OLDNEW
1 // Copyright 2015 The Crashpad Authors. All rights reserved. 1 // Copyright 2015 The Crashpad Authors. All rights reserved.
2 // 2 //
3 // Licensed under the Apache License, Version 2.0 (the "License"); 3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License. 4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at 5 // You may obtain a copy of the License at
6 // 6 //
7 // http://www.apache.org/licenses/LICENSE-2.0 7 // http://www.apache.org/licenses/LICENSE-2.0
8 // 8 //
9 // Unless required by applicable law or agreed to in writing, software 9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS, 10 // distributed under the License is distributed on an "AS IS" BASIS,
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
47 // Try to move to a new temporary directory with a randomly generated name. 47 // Try to move to a new temporary directory with a randomly generated name.
48 // If the one we try exists, retry with a new name until we reach some 48 // If the one we try exists, retry with a new name until we reach some
49 // limit. 49 // limit.
50 base::FilePath target_path = GenerateCandidateName(); 50 base::FilePath target_path = GenerateCandidateName();
51 if (MoveFileEx(path_.value().c_str(), target_path.value().c_str(), 0)) { 51 if (MoveFileEx(path_.value().c_str(), target_path.value().c_str(), 0)) {
52 path_ = target_path; 52 path_ = target_path;
53 return; 53 return;
54 } 54 }
55 } 55 }
56 56
57 CHECK(false) << "Couldn't find temp dir name"; 57 CHECK(false) << "Couldn't find temp dir name";
Peter Kasting 2015/02/13 00:32:41 Nit: "Couldn't create a unique temp dir name" migh
scottmg 2015/02/13 06:34:05 Done.
58 } 58 }
59 59
60 // static 60 // static
61 base::FilePath ScopedTempDir::CreateTemporaryDirectory() { 61 base::FilePath ScopedTempDir::CreateTemporaryDirectory() {
62 for (int count = 0; count < kRetries; ++count) { 62 for (int count = 0; count < kRetries; ++count) {
63 // Try to create a new temporary directory with random generated name. If 63 // Try to create a new temporary directory with random generated name. If
64 // the one we generate exists, keep trying another path name until we reach 64 // the one we generate exists, keep trying another path name until we reach
65 // some limit. 65 // some limit.
66 base::FilePath path_to_create = GenerateCandidateName(); 66 base::FilePath path_to_create = GenerateCandidateName();
67 if (CreateDirectory(path_to_create.value().c_str(), NULL)) 67 if (CreateDirectory(path_to_create.value().c_str(), NULL))
68 return path_to_create; 68 return path_to_create;
69 } 69 }
70 70
71 CHECK(false) << "Couldn't find temp dir name"; 71 CHECK(false) << "Couldn't find temp dir name";
72 return base::FilePath(); 72 return base::FilePath();
73 } 73 }
74 74
75 // static 75 // static
76 void ScopedTempDir::RecursivelyDeleteTemporaryDirectory( 76 void ScopedTempDir::RecursivelyDeleteTemporaryDirectory(
77 const base::FilePath& path) { 77 const base::FilePath& path) {
78 const std::wstring all_files_mask(L"\\*"); 78 const std::wstring all_files_mask(L"\\*");
79 79
80 std::wstring search_mask = path.value() + all_files_mask; 80 std::wstring search_mask = path.value() + all_files_mask;
81 WIN32_FIND_DATA find_data; 81 WIN32_FIND_DATA find_data;
82 HANDLE search_handle = FindFirstFile(search_mask.c_str(), &find_data); 82 HANDLE search_handle = FindFirstFile(search_mask.c_str(), &find_data);
83 if (search_handle == INVALID_HANDLE_VALUE) { 83 if (search_handle == INVALID_HANDLE_VALUE) {
84 ASSERT_EQ(GetLastError(), ERROR_FILE_NOT_FOUND); 84 ASSERT_EQ(GetLastError(), ERROR_FILE_NOT_FOUND);
Peter Kasting 2015/02/13 00:32:41 Nit: (expected, actual) for gtest ASSERT/EXPECT_EQ
scottmg 2015/02/13 06:34:05 Done.
85 return; 85 return;
86 } 86 }
87 for (;;) { 87 for (;;) {
88 if (wcscmp(find_data.cFileName, L".") != 0 && 88 if (wcscmp(find_data.cFileName, L".") != 0 &&
89 wcscmp(find_data.cFileName, L"..") != 0) { 89 wcscmp(find_data.cFileName, L"..") != 0) {
90 bool is_dir = 90 bool is_dir =
91 (find_data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) != 0 || 91 (find_data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) != 0 ||
92 (find_data.dwFileAttributes & FILE_ATTRIBUTE_REPARSE_POINT) != 0; 92 (find_data.dwFileAttributes & FILE_ATTRIBUTE_REPARSE_POINT) != 0;
Peter Kasting 2015/02/13 00:32:40 Nit: Shorter: if (find_data.dwFileAttribute
scottmg 2015/02/13 06:34:06 Done.
93 base::FilePath entry_path = path.Append(find_data.cFileName); 93 base::FilePath entry_path = path.Append(find_data.cFileName);
94 if (is_dir) 94 if (is_dir)
95 RecursivelyDeleteTemporaryDirectory(entry_path); 95 RecursivelyDeleteTemporaryDirectory(entry_path);
96 else 96 else
97 EXPECT_TRUE(DeleteFile(entry_path.value().c_str())); 97 EXPECT_TRUE(DeleteFile(entry_path.value().c_str()));
98 } 98 }
99 99
100 if (!FindNextFile(search_handle, &find_data)) { 100 if (!FindNextFile(search_handle, &find_data)) {
Peter Kasting 2015/02/13 00:32:41 Nit: This can be used as a loop condition, and the
scottmg 2015/02/13 06:34:06 Done.
101 EXPECT_EQ(GetLastError(), ERROR_NO_MORE_FILES); 101 EXPECT_EQ(GetLastError(), ERROR_NO_MORE_FILES);
102 break; 102 break;
103 } 103 }
104 } 104 }
105 105
106 EXPECT_TRUE(FindClose(search_handle)); 106 EXPECT_TRUE(FindClose(search_handle));
107 EXPECT_TRUE(RemoveDirectory(path.value().c_str())); 107 EXPECT_TRUE(RemoveDirectory(path.value().c_str()));
108 } 108 }
109 109
110 } // namespace test 110 } // namespace test
111 } // namespace crashpad 111 } // namespace crashpad
112 // EOF comment added for readability review.
OLDNEW
« util/test/scoped_temp_dir_posix.cc ('K') | « 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