From 26e6cb3eb9a68ded9b0db6bce86afd4523e4c741 Mon Sep 17 00:00:00 2001 From: Ralf Schmelter Date: Wed, 25 Nov 2020 13:16:36 +0000 Subject: [PATCH] 8256489: Make gtest for long path names on Windows more resilient in the presence of virus scanners Reviewed-by: dholmes, clanger --- test/hotspot/gtest/runtime/test_os_windows.cpp | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/test/hotspot/gtest/runtime/test_os_windows.cpp b/test/hotspot/gtest/runtime/test_os_windows.cpp index 930e483d02b..2d678d65dcf 100644 --- a/test/hotspot/gtest/runtime/test_os_windows.cpp +++ b/test/hotspot/gtest/runtime/test_os_windows.cpp @@ -135,8 +135,20 @@ static void create_rel_directory_w(const wchar_t* path) { static void delete_empty_rel_directory_w(const wchar_t* path) { WITH_ABS_PATH(path); EXPECT_TRUE(file_exists_w(abs_path)) << "Can't delete directory: \"" << path << "\" does not exists"; - BOOL result = RemoveDirectoryW(abs_path); - EXPECT_TRUE(result) << "Failed to delete directory \"" << path << "\": " << GetLastError(); + const int retry_count = 20; + + // If the directory cannot be deleted directly, a file in it might be kept + // open by a virus scanner. Try a few times, since this should be temporary. + for (int i = 0; i <= retry_count; ++i) { + BOOL result = RemoveDirectoryW(abs_path); + + if (!result && (i < retry_count)) { + Sleep(1); + } else { + EXPECT_TRUE(result) << "Failed to delete directory \"" << path << "\": " << GetLastError(); + return; + } + } } static void create_rel_file_w(const wchar_t* path) {