Skip to content

Commit 26e6cb3

Browse files
committed
8256489: Make gtest for long path names on Windows more resilient in the presence of virus scanners
Reviewed-by: dholmes, clanger
1 parent 911f16d commit 26e6cb3

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

test/hotspot/gtest/runtime/test_os_windows.cpp

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -135,8 +135,20 @@ static void create_rel_directory_w(const wchar_t* path) {
135135
static void delete_empty_rel_directory_w(const wchar_t* path) {
136136
WITH_ABS_PATH(path);
137137
EXPECT_TRUE(file_exists_w(abs_path)) << "Can't delete directory: \"" << path << "\" does not exists";
138-
BOOL result = RemoveDirectoryW(abs_path);
139-
EXPECT_TRUE(result) << "Failed to delete directory \"" << path << "\": " << GetLastError();
138+
const int retry_count = 20;
139+
140+
// If the directory cannot be deleted directly, a file in it might be kept
141+
// open by a virus scanner. Try a few times, since this should be temporary.
142+
for (int i = 0; i <= retry_count; ++i) {
143+
BOOL result = RemoveDirectoryW(abs_path);
144+
145+
if (!result && (i < retry_count)) {
146+
Sleep(1);
147+
} else {
148+
EXPECT_TRUE(result) << "Failed to delete directory \"" << path << "\": " << GetLastError();
149+
return;
150+
}
151+
}
140152
}
141153

142154
static void create_rel_file_w(const wchar_t* path) {

0 commit comments

Comments
 (0)